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] ## [Unreleased]
## 2019/03/01
### Changed
- Change scroll method names in List widget
### Fixed
- Fix List widget scrolling
## 2019/02/28 ## 2019/02/28
### Added ### Added

View File

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

View File

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