Change list widget scroll method names

This commit is contained in:
Caleb Bassi 2019-03-01 14:00:31 -08:00
parent a8109c55df
commit a9772ca753
3 changed files with 22 additions and 10 deletions

View File

@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## 2019/03/01
### Changed
- Change scroll method names in List widget
### Fixed
- Fix List widget scrolling
## 2019/02/28
### Added

View File

@ -51,13 +51,13 @@ func main() {
case "k", "<Up>":
l.ScrollUp()
case "<C-d>":
l.HalfPageDown()
l.ScrollHalfPageDown()
case "<C-u>":
l.HalfPageUp()
l.ScrollHalfPageUp()
case "<C-f>":
l.PageDown()
l.ScrollPageDown()
case "<C-b>":
l.PageUp()
l.ScrollPageUp()
case "g":
if previousKey == "g" {
l.ScrollTop()

View File

@ -42,6 +42,7 @@ func (self *List) Draw(buf *Buffer) {
self.topRow = self.SelectedRow
}
// draw rows
for row := self.topRow; row < len(self.Rows) && point.Y < self.Inner.Max.Y; row++ {
cells := ParseStyles(self.Rows[row], self.TextStyle)
if self.WrapText {
@ -67,12 +68,15 @@ func (self *List) Draw(buf *Buffer) {
point = image.Pt(self.Inner.Min.X, point.Y+1)
}
// draw UP_ARROW if needed
if self.topRow > 0 {
buf.SetCell(
NewCell(UP_ARROW, NewStyle(ColorWhite)),
image.Pt(self.Inner.Max.X-1, self.Inner.Min.Y),
)
}
// draw DOWN_ARROW if needed
if len(self.Rows) > int(self.topRow)+self.Inner.Dy() {
buf.SetCell(
NewCell(DOWN_ARROW, NewStyle(ColorWhite)),
@ -102,8 +106,7 @@ func (self *List) ScrollDown() {
self.ScrollAmount(1)
}
// PageUp scrolls up one whole page.
func (self *List) PageUp() {
func (self *List) ScrollPageUp() {
// If an item is selected below top row, then go to the top row.
if self.SelectedRow > self.topRow {
self.SelectedRow = self.topRow
@ -112,16 +115,15 @@ func (self *List) PageUp() {
}
}
// PageDown scolls down one whole page.
func (self *List) PageDown() {
func (self *List) ScrollPageDown() {
self.ScrollAmount(self.Inner.Dy())
}
func (self *List) HalfPageUp() {
func (self *List) ScrollHalfPageUp() {
self.ScrollAmount(-int(FloorFloat64(float64(self.Inner.Dy()) / 2)))
}
func (self *List) HalfPageDown() {
func (self *List) ScrollHalfPageDown() {
self.ScrollAmount(int(FloorFloat64(float64(self.Inner.Dy()) / 2)))
}