change return type of ui_list_getselection from UiListSelection to int, add ui_list_get_selection for returning UiListSelection

Sun, 25 Jan 2026 10:28:37 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 25 Jan 2026 10:28:37 +0100
changeset 1055
02af1d4a88df
parent 1054
c08c2c9f11b3
child 1056
541cec5e913c

change return type of ui_list_getselection from UiListSelection to int, add ui_list_get_selection for returning UiListSelection

application/main.c file | annotate | diff | comparison | revisions
ui/common/types.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Fri Jan 23 16:25:39 2026 +0100
+++ b/application/main.c	Sun Jan 25 10:28:37 2026 +0100
@@ -453,7 +453,7 @@
     if(eventdata->row_index >= 0) {
         ui_list_update_row(eventdata->list, eventdata->row_index);
     }
-    UiListSelection sel = ui_list_getselection(eventdata->list);
+    UiListSelection sel = ui_list_get_selection(eventdata->list);
     printf("sel: %d: %d\n", sel.count, sel.count > 0 ? sel.rows[0] : -1);
     
     if(eventdata->sublist_index == 1 && eventdata->row_index == 2) {
--- a/ui/common/types.c	Fri Jan 23 16:25:39 2026 +0100
+++ b/ui/common/types.c	Sun Jan 25 10:28:37 2026 +0100
@@ -196,6 +196,12 @@
     }
 }
 
+UIEXPORT void ui_list_set_selection(UiList *list, UiListSelection sel) {
+    if(list->setselection) {
+        list->setselection(list, sel);
+    }
+}
+
 void ui_list_addobsv(UiList *list, ui_callback f, void *data) {
     list->observers = ui_add_observer(list->observers, f, data);
 }
@@ -789,11 +795,16 @@
 }
 
 
-UIEXPORT UiListSelection ui_list_getselection(UiList *list) {
+UIEXPORT int ui_list_getselection(UiList *list) {
+    int selection = -1;
     if (list->getselection) {
-        return list->getselection(list);
+        UiListSelection sel = list->getselection(list);
+        if(sel.count > 0) {
+            selection = sel.rows[0];
+        }
+        ui_listselection_free(sel);
     }
-    return (UiListSelection){ 0, NULL };
+    return selection;
 }
 
 UIEXPORT void ui_list_setselection(UiList *list, int index) {
--- a/ui/ui/toolkit.h	Fri Jan 23 16:25:39 2026 +0100
+++ b/ui/ui/toolkit.h	Sun Jan 25 10:28:37 2026 +0100
@@ -683,12 +683,15 @@
 UIEXPORT void ui_list_update(UiList *list);
 UIEXPORT void ui_list_update_row(UiList *list, int row);
 UIEXPORT UiListSelection ui_list_get_selection(UiList *list);
+UIEXPORT void ui_list_set_selection(UiList *list, UiListSelection sel);
 UIEXPORT void ui_list_addobsv(UiList *list, ui_callback f, void *data);
 UIEXPORT void ui_list_notify(UiList *list);
 
-UIEXPORT UiListSelection ui_list_getselection(UiList *list);
+UIEXPORT int ui_list_getselection(UiList *list);
 UIEXPORT void ui_list_setselection(UiList *list, int index);
 
+UIEXPORT void ui_listselection_free(UiListSelection selection);
+
 UIEXPORT UiFileList ui_filelist_copy(UiFileList list);
 UIEXPORT void ui_filelist_free(UiFileList list);
 
@@ -699,9 +702,6 @@
 
 
 
-UIEXPORT void ui_listselection_free(UiListSelection selection);
-
-
 UIEXPORT UiStr ui_str(char *cstr);
 UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));
 

mercurial