diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2025-03-20 12:33:37 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2025-03-20 12:33:37 +0100 |
| commit | 39b580c33ce568bb3b055df6bc4b16fa5969e77b (patch) | |
| tree | 7970422d1fd128ee6a7025c9eae480d5893d7d72 /tui/widget/list/scrolllist.ha | |
| parent | 8d4bc50570fcb9654ba6fe931dc937ea476b659e (diff) | |
| parent | ddac62a2a43ee62da4f5302e9cb2958f6ff82cea (diff) | |
| download | hare-tui-39b580c33ce568bb3b055df6bc4b16fa5969e77b.tar.gz | |
Merge branch 'master' into nomem
Diffstat (limited to 'tui/widget/list/scrolllist.ha')
| -rw-r--r-- | tui/widget/list/scrolllist.ha | 18 |
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; |
