summaryrefslogtreecommitdiff
path: root/tui/scroll_state.go
diff options
context:
space:
mode:
Diffstat (limited to 'tui/scroll_state.go')
-rw-r--r--tui/scroll_state.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/tui/scroll_state.go b/tui/scroll_state.go
new file mode 100644
index 0000000..75797b1
--- /dev/null
+++ b/tui/scroll_state.go
@@ -0,0 +1,43 @@
+package tui
+
+type ScrollState struct {
+ at string
+ offset int
+ absolute int
+ atFirst bool
+ atLast bool
+}
+
+func (s *ScrollState) ToStart() {
+ *s = ScrollState {}
+}
+
+func (s *ScrollState) AtFirst() bool {
+ return s.atFirst
+}
+
+func (s *ScrollState) AtLast() bool {
+ return s.atLast
+}
+
+func (s *ScrollState) Scroll(amnt int) {
+ s.offset += amnt
+ s.absolute += amnt
+}
+
+func (s *ScrollState) ByMouse(ev MouseEvent, reverse bool) {
+ scroll := ev.Scroll * 5
+ if reverse {
+ scroll *= -1
+ }
+ s.Scroll(scroll)
+}
+
+func (s *ScrollState) Get() int {
+ return s.absolute
+}
+
+func (s *ScrollState) Set(amnt int) {
+ s.at = ""
+ s.absolute = amnt
+}