From ddac62a2a43ee62da4f5302e9cb2958f6ff82cea Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 20 Mar 2025 12:33:13 +0100 Subject: Add setcursor and reframe to scrolllist and flesh out il --- tui/widget/list/scrolllist.ha | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tui/widget') 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; -- cgit v1.2.3