add pgCount() method to GridCursor

This commit is contained in:
Bradley Cicenas 2017-07-07 12:28:26 +00:00
parent 79a3f361a7
commit c47ba3f804
1 changed files with 11 additions and 4 deletions

View File

@ -142,8 +142,7 @@ func (gc *GridCursor) PgUp() {
return
}
var nextidx int
nextidx = int(math.Max(0.0, float64(idx-cGrid.MaxRows())))
nextidx := int(math.Max(0.0, float64(idx-cGrid.MaxRows())))
cGrid.Offset = int(math.Max(float64(cGrid.Offset-cGrid.MaxRows()),
float64(0)))
@ -164,8 +163,7 @@ func (gc *GridCursor) PgDown() {
return
}
var nextidx int
nextidx = int(math.Min(float64(gc.Len()-1),
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())))
@ -180,3 +178,12 @@ func (gc *GridCursor) PgDown() {
cGrid.Align()
ui.Render(cGrid)
}
// number of pages at current row count and term height
func (gc *GridCursor) pgCount() int {
pages := gc.Len() / cGrid.MaxRows()
if gc.Len()%cGrid.MaxRows() > 0 {
pages++
}
return pages
}