summaryrefslogtreecommitdiff
path: root/tui
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst@digdash.com>2025-03-20 12:33:13 +0100
committerJulian Hurst <julian.hurst@digdash.com>2025-03-20 12:33:13 +0100
commitddac62a2a43ee62da4f5302e9cb2958f6ff82cea (patch)
tree1a0e7d0dd485d5a4a1879f05bdefd79b3e4bbf0b /tui
parent6e8a2af6bd47fd05e6b22937c5da7397549e7cbb (diff)
downloadhare-tui-ddac62a2a43ee62da4f5302e9cb2958f6ff82cea.tar.gz
Add setcursor and reframe to scrolllist and flesh out il
Diffstat (limited to 'tui')
-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;