summaryrefslogtreecommitdiff
path: root/tui/widget/list/scrolllist.ha
diff options
context:
space:
mode:
Diffstat (limited to 'tui/widget/list/scrolllist.ha')
-rw-r--r--tui/widget/list/scrolllist.ha18
1 files changed, 18 insertions, 0 deletions
diff --git a/tui/widget/list/scrolllist.ha b/tui/widget/list/scrolllist.ha
index 3aaad87..d08c7d7 100644
--- a/tui/widget/list/scrolllist.ha
+++ b/tui/widget/list/scrolllist.ha
@@ -115,6 +115,24 @@ export fn bottom(li: *scrolllist) void = {
li.frame.start = len(li.items): u16 - sz;
};
+export fn setcursor(li: *scrolllist, newpos: u16) void = {
+ li.cursor = newpos;
+ reframe(li);
+};
+
+fn reframe(li: *scrolllist) void = {
+ if (li.cursor > li.frame.end) {
+ const diff = li.frame.end - li.frame.start;
+ li.frame.start = li.cursor;
+ li.frame.end = li.frame.start + diff;
+ };
+ if (li.cursor < li.frame.start) {
+ const diff = li.frame.end - li.frame.start;
+ li.frame.end = li.cursor;
+ li.frame.start = li.frame.end - diff;
+ };
+};
+
fn stylesscrolllist(widget: *widget::widget, txt: str, idx: size) str = {
const list = widget: *scrolllist;
const idx = idx + list.frame.start;