From ff4168311339f659c73f6bf1b0f48ea4744e5638 Mon Sep 17 00:00:00 2001 From: hmmmmmmmm Date: Thu, 31 Jan 2019 17:06:46 +0000 Subject: [PATCH 1/2] Added page up and page down functions to list. --- widgets/list.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/widgets/list.go b/widgets/list.go index 53d88b9..e1f9ede 100644 --- a/widgets/list.go +++ b/widgets/list.go @@ -95,3 +95,21 @@ func (self *List) ScrollDown() { } } } + +func (self *List) PageUp() { // Goes up one whole page. + if int(self.SelectedRow)-self.Inner.Dy() >= 0 { + self.topRow -= uint(self.Inner.Dy()) + } else { // If at the first 'page', then go to the top and select the first item. + self.topRow = 0 + } + self.SelectedRow = self.topRow +} + +func (self *List) PageDown() { // Down one whole page + if len(self.Rows)-int(self.topRow) > self.Inner.Dy() { + self.topRow += uint(self.Inner.Dy()) + self.SelectedRow = self.topRow + } else { // If at last 'page', then select last item. + self.SelectedRow = uint(len(self.Rows)-1) + } +} From 91de22dab351c5ccf19b4c6f2df9528e0cd7f1ad Mon Sep 17 00:00:00 2001 From: hmmmmmmmm Date: Thu, 31 Jan 2019 17:27:53 +0000 Subject: [PATCH 2/2] Ran go fmt to clean it up a bit. --- widgets/list.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/widgets/list.go b/widgets/list.go index e1f9ede..66274f4 100644 --- a/widgets/list.go +++ b/widgets/list.go @@ -34,7 +34,7 @@ func (self *List) Draw(buf *Buffer) { point := self.Inner.Min if self.SelectedRow >= uint(self.Inner.Max.Y)+self.topRow-2 { - self.topRow = self.SelectedRow-uint(self.Inner.Max.Y)+2 + self.topRow = self.SelectedRow - uint(self.Inner.Max.Y) + 2 } else if self.SelectedRow < self.topRow { self.topRow = self.SelectedRow } @@ -96,20 +96,20 @@ func (self *List) ScrollDown() { } } -func (self *List) PageUp() { // Goes up one whole page. +func (self *List) PageUp() { // Goes up one whole page. if int(self.SelectedRow)-self.Inner.Dy() >= 0 { self.topRow -= uint(self.Inner.Dy()) - } else { // If at the first 'page', then go to the top and select the first item. + } else { // If at the first 'page', then go to the top and select the first item. self.topRow = 0 } self.SelectedRow = self.topRow } -func (self *List) PageDown() { // Down one whole page +func (self *List) PageDown() { // Down one whole page if len(self.Rows)-int(self.topRow) > self.Inner.Dy() { self.topRow += uint(self.Inner.Dy()) self.SelectedRow = self.topRow - } else { // If at last 'page', then select last item. - self.SelectedRow = uint(len(self.Rows)-1) + } else { // If at last 'page', then select last item. + self.SelectedRow = uint(len(self.Rows) - 1) } }