Added page up/down features

This commit is contained in:
yashpatel5400
2017-03-23 22:31:08 -04:00
parent 5db90f31dc
commit 6560768e08
3 changed files with 59 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"math"
ui "github.com/gizak/termui"
)
@@ -130,3 +131,48 @@ func (gc *GridCursor) Down() {
gc.ScrollPage()
ui.Render(cGrid)
}
func (gc *GridCursor) PgUp() {
idx := gc.Idx()
if idx <= 0 { // already at top
return
}
var nextidx int
nextidx = int(math.Max(0.0, float64(idx - cGrid.MaxRows())))
cGrid.Offset = int(math.Max(float64(cGrid.Offset - cGrid.MaxRows()),
float64(0)))
active := gc.filtered[idx]
next := gc.filtered[nextidx]
active.Widgets.Name.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
cGrid.Align()
ui.Render(cGrid)
}
func (gc *GridCursor) PgDown() {
idx := gc.Idx()
if idx >= gc.Len()-1 { // already at bottom
return
}
var nextidx int
nextidx = int(math.Min(float64(gc.Len() - 1),
float64(idx + cGrid.MaxRows())))
cGrid.Offset = int(math.Min(float64(cGrid.Offset + cGrid.MaxRows()),
float64(gc.Len() - cGrid.MaxRows())))
active := gc.filtered[idx]
next := gc.filtered[nextidx]
active.Widgets.Name.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
cGrid.Align()
ui.Render(cGrid)
}