diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/msglist.go | 17 | ||||
-rw-r--r-- | app/scrollable.go | 24 |
2 files changed, 41 insertions, 0 deletions
diff --git a/app/msglist.go b/app/msglist.go index a5e5fbb6..38970123 100644 --- a/app/msglist.go +++ b/app/msglist.go @@ -51,6 +51,23 @@ type messageRowParams struct { headers *mail.Header } +// AlignMessage aligns the selected message to position pos. +func (ml *MessageList) AlignMessage(pos AlignPosition) { + store := ml.Store() + if store == nil { + return + } + idx := 0 + iter := store.UidsIterator() + for i := 0; iter.Next(); i++ { + if store.SelectedUid() == iter.Value().(uint32) { + idx = i + break + } + } + ml.Align(idx, pos) +} + func (ml *MessageList) Draw(ctx *ui.Context) { ml.height = ctx.Height() ml.width = ctx.Width() diff --git a/app/scrollable.go b/app/scrollable.go index 3a0555fe..04436375 100644 --- a/app/scrollable.go +++ b/app/scrollable.go @@ -62,6 +62,10 @@ func (s *Scrollable) EnsureScroll(idx int) { s.scroll = idx + s.offset - s.height + 1 } + s.checkBounds() +} + +func (s *Scrollable) checkBounds() { maxScroll := s.elems - s.height if maxScroll < 0 { maxScroll = 0 @@ -75,3 +79,23 @@ func (s *Scrollable) EnsureScroll(idx int) { s.scroll = 0 } } + +type AlignPosition uint + +const ( + AlignTop AlignPosition = iota + AlignCenter + AlignBottom +) + +func (s *Scrollable) Align(idx int, pos AlignPosition) { + switch pos { + case AlignTop: + s.scroll = idx + case AlignCenter: + s.scroll = idx - s.height/2 + case AlignBottom: + s.scroll = idx - s.height + 1 + } + s.checkBounds() +} |