mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 09:42:34 +02:00
refactor page/list movement
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package util
|
||||
|
||||
// CursorMovePage moves cursor forward or backward by one page (perPage items),
|
||||
// clamped to [0, total-1].
|
||||
func CursorMovePage(cursor, total, perPage int, forward bool) int {
|
||||
step := perPage
|
||||
if step < 1 {
|
||||
step = 1
|
||||
}
|
||||
if forward {
|
||||
cursor += step
|
||||
} else {
|
||||
cursor -= step
|
||||
}
|
||||
if cursor < 0 || total <= 0 {
|
||||
return 0
|
||||
}
|
||||
if cursor >= total {
|
||||
return total - 1
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
|
||||
// CursorGotoBottom returns the last valid cursor index for a list of total items.
|
||||
func CursorGotoBottom(total int) int {
|
||||
if total <= 0 {
|
||||
return 0
|
||||
}
|
||||
return total - 1
|
||||
}
|
||||
Reference in New Issue
Block a user