workaround for empty sublists with headers (GTK)

Tue, 19 Aug 2025 12:59:00 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 19 Aug 2025 12:59:00 +0200
changeset 697
d254b3ec7736
parent 696
68f513430e5a
child 698
3496032f0dd0

workaround for empty sublists with headers (GTK)

ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/list.c	Tue Aug 19 12:38:16 2025 +0200
+++ b/ui/gtk/list.c	Tue Aug 19 12:59:00 2025 +0200
@@ -2027,6 +2027,20 @@
     
     size_t index = 0;
     void *elm = list->first(list);
+    
+    if(!elm && sublist->header) {
+        // empty row for header
+        GtkWidget *row = gtk_list_box_row_new();
+        cxListAdd(sublist->widgets, row);
+        g_object_set_data(G_OBJECT(row), "ui_listbox", listbox);
+        g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist);
+        intptr_t rowindex = listbox_insert_index + index;
+        g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex);
+        gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index);
+        sublist->numitems = 1;
+        return;
+    }
+    
     while(elm) {
         UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL };
         if(listbox->getvalue) {
@@ -2071,6 +2085,13 @@
 void ui_listbox_list_update(UiList *list, int i) {
     UiListBoxSubList *sublist = list->obj;
     ui_listbox_update_sublist(sublist->listbox, sublist, sublist->startpos);
+    size_t pos = 0;
+    CxIterator it = cxListIterator(sublist->listbox->sublists);
+    cx_foreach(UiListBoxSubList *, ls, it) {
+        ls->startpos = pos;
+        pos += sublist->numitems;
+    }
+    
 }
 
 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) {

mercurial