diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-15 21:49:40 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-15 21:49:40 -0400 |
commit | 52a97c02aeec3c994d2c10e53b024abeb4e7b337 (patch) | |
tree | 080c46e4792d00c2c2c95d9ea9b089ac033694a6 /widgets/msglist.go | |
parent | 01ae0cef601007bb7ad2da72621a440d35df30ec (diff) | |
download | aerc-52a97c02aeec3c994d2c10e53b024abeb4e7b337.tar.gz |
Implement scrolling in message list
Diffstat (limited to 'widgets/msglist.go')
-rw-r--r-- | widgets/msglist.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go index cf9a772..28eec0c 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -15,6 +15,7 @@ type MessageList struct { logger *log.Logger height int onInvalidate func(d ui.Drawable) + scroll int selected int spinner *Spinner store *lib.MessageStore @@ -59,7 +60,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { row int = 0 ) - for i := len(ml.store.Uids) - 1; i >= 0; i-- { + for i := len(ml.store.Uids) - 1 - ml.scroll; i >= 0; i-- { uid := ml.store.Uids[i] msg := ml.store.Messages[uid] @@ -75,7 +76,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { } style := tcell.StyleDefault - if row == ml.selected { + if row == ml.selected-ml.scroll { style = style.Background(tcell.ColorWhite). Foreground(tcell.ColorBlack) } @@ -98,6 +99,10 @@ func (ml *MessageList) Height() int { } func (ml *MessageList) SetStore(store *lib.MessageStore) { + if ml.store == store { + ml.scroll = 0 + ml.selected = 0 + } ml.store = store if store != nil { ml.spinner.Stop() @@ -115,7 +120,13 @@ func (ml *MessageList) nextPrev(delta int) { if ml.selected >= len(ml.store.Uids) { ml.selected = len(ml.store.Uids) - 1 } - // TODO: scrolling + if ml.Height() != 0 { + if ml.selected-ml.scroll >= ml.Height() { + ml.scroll += 1 + } else if ml.selected-ml.scroll < 0 { + ml.scroll -= 1 + } + } ml.Invalidate() } |