Added more list scrolling functionality.
You can now go up and down by half a page, and to top and bottom. I also added a function called 'scrollAmount' that allows you to scroll by the number of rows you would like to scroll by.
This commit is contained in:
parent
ed41775aa5
commit
8e972f7541
@ -96,26 +96,46 @@ func (self *List) ScrollDown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scrolls by amount given. If amount is < 0, then scroll up.
|
||||||
|
// There is no need to set self.topRow, as this will be set automatically when drawn,
|
||||||
|
// since if the selected item is off screen then the topRow variable will change accordingly.
|
||||||
|
func (self *List) scrollAmount(amount int) {
|
||||||
|
if len(self.Rows)-int(self.SelectedRow) <= amount {
|
||||||
|
self.SelectedRow = uint(len(self.Rows)-1)
|
||||||
|
} else if int(self.SelectedRow)+amount < 0 {
|
||||||
|
self.SelectedRow = 0
|
||||||
|
} else {
|
||||||
|
self.SelectedRow += uint(amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PageUp scrolls up one whole page.
|
// PageUp scrolls up one whole page.
|
||||||
func (self *List) PageUp() {
|
func (self *List) PageUp() {
|
||||||
// if on the first 'page'
|
// If an item is selected below top row, then go to the top row.
|
||||||
if int(self.SelectedRow)-self.Inner.Dy() < 0 {
|
if self.SelectedRow > self.topRow {
|
||||||
// go to the top
|
|
||||||
self.topRow = 0
|
|
||||||
} else {
|
|
||||||
self.topRow = uint(MaxInt(int(self.topRow)-self.Inner.Dy(), 0))
|
|
||||||
}
|
|
||||||
self.SelectedRow = self.topRow
|
self.SelectedRow = self.topRow
|
||||||
|
} else {
|
||||||
|
self.scrollAmount(-self.Inner.Dy())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PageDown scolls down one whole page.
|
// PageDown scolls down one whole page.
|
||||||
func (self *List) PageDown() {
|
func (self *List) PageDown() {
|
||||||
// if on last 'page'
|
self.scrollAmount(self.Inner.Dy())
|
||||||
if len(self.Rows)-int(self.topRow) <= self.Inner.Dy() {
|
}
|
||||||
// select last item
|
|
||||||
|
func (self *List) HalfPageUp() {
|
||||||
|
self.scrollAmount(-int(FloorFloat64(float64(self.Inner.Dy())/2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *List) HalfPageDown() {
|
||||||
|
self.scrollAmount(int(FloorFloat64(float64(self.Inner.Dy())/2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *List) ScrollTop() {
|
||||||
|
self.SelectedRow = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *List) ScrollBottom() {
|
||||||
self.SelectedRow = uint(len(self.Rows)-1)
|
self.SelectedRow = uint(len(self.Rows)-1)
|
||||||
} else {
|
|
||||||
self.topRow += uint(self.Inner.Dy())
|
|
||||||
self.SelectedRow = self.topRow
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user