diff options
Diffstat (limited to 'tui/widget/list/scrolllist.ha')
| -rw-r--r-- | tui/widget/list/scrolllist.ha | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/tui/widget/list/scrolllist.ha b/tui/widget/list/scrolllist.ha index 2f18ef0..0079363 100644 --- a/tui/widget/list/scrolllist.ha +++ b/tui/widget/list/scrolllist.ha @@ -120,27 +120,25 @@ export fn bottom(li: *scrolllist) void = { }; export fn setcursor(li: *scrolllist, newpos: int) void = { - li.cursor = newpos; + if (newpos < 0) { + li.cursor = 0; + } else if (newpos > len(li.items): int) { + li.cursor = len(li.items): int - 1; + } else { + li.cursor = newpos; + }; reframe(li); }; fn reframe(li: *scrolllist) void = { - if (li.cursor > li.frame.end) { + if (li.cursor >= li.frame.end) { const diff = li.frame.end - li.frame.start; - li.frame.start = if (li.cursor <= len(li.items): int - diff) li.cursor else len(li.items): int - diff; - li.frame.end = if (li.frame.start + diff > len(li.items): int) { - yield len(li.items): int; - } else { - yield li.frame.start + diff; - }; + li.frame.end = li.cursor + 1; + li.frame.start = li.frame.end - diff; } else if (li.cursor < li.frame.start) { const diff = li.frame.end - li.frame.start; - li.frame.end = if (li.cursor > diff) li.cursor else diff; - li.frame.start = if (li.frame.end - diff < 0) { - yield 0; - } else { - yield li.frame.end - diff; - }; + li.frame.start = li.cursor; + li.frame.end = li.frame.start + diff; }; assert(li.frame.start >= 0); assert(li.frame.end <= len(li.items): int); |
