aboutsummaryrefslogtreecommitdiff
path: root/ui/widget
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-25 12:35:50 +0300
committerTulir Asokan <tulir@maunium.net>2018-03-25 12:35:50 +0300
commitc1286661090731729e76e48d5e47988ad0175a20 (patch)
treee43ce30f3d3020ec1e2bec13ea7fc954b89e78d4 /ui/widget
parente414e20215db3a80bb1cf511390406324e742ebf (diff)
Refactor things and add proper wheel scroll support
Diffstat (limited to 'ui/widget')
-rw-r--r--ui/widget/message-view.go39
1 files changed, 17 insertions, 22 deletions
diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go
index a3a7942..50de405 100644
--- a/ui/widget/message-view.go
+++ b/ui/widget/message-view.go
@@ -211,46 +211,41 @@ func (view *MessageView) recalculateBuffers() {
const PaddingAtTop = 5
-func (view *MessageView) MoveUp(page bool) {
+func (view *MessageView) AddScrollOffset(diff int) {
_, _, _, height := view.GetInnerRect()
totalHeight := len(view.textBuffer)
- if view.ScrollOffset >= totalHeight-height {
+ if diff >= 0 && view.ScrollOffset >= totalHeight-height {
// If the user is at the top and presses page up again, add a bit of blank space.
- if page {
+ if view.ScrollOffset+diff >= totalHeight-height+PaddingAtTop {
view.ScrollOffset = totalHeight - height + PaddingAtTop
- } else if view.ScrollOffset < totalHeight-height+PaddingAtTop {
- view.ScrollOffset++
+ } else {
+ view.ScrollOffset += diff
}
return
}
- if page {
- view.ScrollOffset += height / 2
- } else {
- view.ScrollOffset++
- }
+ view.ScrollOffset += diff
if view.ScrollOffset > totalHeight-height {
view.ScrollOffset = totalHeight - height
+ } else if view.ScrollOffset < 0 {
+ view.ScrollOffset = 0
}
}
-func (view *MessageView) IsAtTop() bool {
+func (view *MessageView) Height() int {
_, _, _, height := view.GetInnerRect()
- totalHeight := len(view.textBuffer)
- return view.ScrollOffset >= totalHeight-height+PaddingAtTop
+ return height
+}
+
+func (view *MessageView) TotalHeight() int {
+ return len(view.textBuffer)
}
-func (view *MessageView) MoveDown(page bool) {
+func (view *MessageView) IsAtTop() bool {
_, _, _, height := view.GetInnerRect()
- if page {
- view.ScrollOffset -= height / 2
- } else {
- view.ScrollOffset--
- }
- if view.ScrollOffset < 0 {
- view.ScrollOffset = 0
- }
+ totalHeight := len(view.textBuffer)
+ return view.ScrollOffset >= totalHeight-height+PaddingAtTop
}
func (view *MessageView) writeLine(screen tcell.Screen, line string, x, y int, color tcell.Color) {