From a421424dda24a25f5e8c0387fff54296d821e8bb Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Tue, 17 May 2022 00:13:56 +0200 Subject: Add list::setitems, sorting and decouple handlers from main.ha --- libui/widget/list/list.ha | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libui') diff --git a/libui/widget/list/list.ha b/libui/widget/list/list.ha index 8500482..efed759 100644 --- a/libui/widget/list/list.ha +++ b/libui/widget/list/list.ha @@ -79,6 +79,18 @@ export fn finish(list: *widget::widget) void = { widget::finishcommon(list); }; +// Set the list's items. If the length of the given items is smaller than the +// list's current items, the cursor will be set to 0z and [[reframe]] will be +// called to reset the frame. +export fn setitems(list: *listwidget, items: str...) void = { + const reset = len(items) < len(list.items); + list.items = strings::dupall(items); + if (reset) { + list.cursor = 0z; + reframe(list); + }; +}; + // Add a listener to the given list. //export fn addlistener(list: *listwidget, l: listener) void = { //append(list.listeners, l); -- cgit v1.2.3