diff options
Diffstat (limited to 'widgets/scrollable.go')
-rw-r--r-- | widgets/scrollable.go | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/widgets/scrollable.go b/widgets/scrollable.go deleted file mode 100644 index f478f858..00000000 --- a/widgets/scrollable.go +++ /dev/null @@ -1,67 +0,0 @@ -package widgets - -// Scrollable implements vertical scrolling -type Scrollable struct { - scroll int - height int - elems int -} - -func (s *Scrollable) Scroll() int { - return s.scroll -} - -func (s *Scrollable) PercentVisible() float64 { - if s.elems <= 0 { - return 1.0 - } - return float64(s.height) / float64(s.elems) -} - -func (s *Scrollable) PercentScrolled() float64 { - if s.elems <= 0 { - return 1.0 - } - return float64(s.scroll) / float64(s.elems) -} - -func (s *Scrollable) NeedScrollbar() bool { - needScrollbar := true - if s.PercentVisible() >= 1.0 { - needScrollbar = false - } - return needScrollbar -} - -func (s *Scrollable) UpdateScroller(height, elems int) { - s.height = height - s.elems = elems -} - -func (s *Scrollable) EnsureScroll(selectingIdx int) { - if selectingIdx < 0 { - return - } - - maxScroll := s.elems - s.height - if maxScroll < 0 { - maxScroll = 0 - } - - if selectingIdx >= s.scroll && selectingIdx < s.scroll+s.height { - if s.scroll > maxScroll { - s.scroll = maxScroll - } - return - } - - if selectingIdx >= s.scroll+s.height { - s.scroll = selectingIdx - s.height + 1 - } else if selectingIdx < s.scroll { - s.scroll = selectingIdx - } - - if s.scroll > maxScroll { - s.scroll = maxScroll - } -} |