Wed, 24 Sep 2025 21:33:33 +0200
fix ui_listbox_list_update
| application/main.c | file | annotate | diff | comparison | revisions | |
| ui/gtk/list.c | file | annotate | diff | comparison | revisions | |
| ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Wed Sep 24 21:00:42 2025 +0200 +++ b/application/main.c Wed Sep 24 21:33:33 2025 +0200 @@ -435,7 +435,8 @@ void action_sourcelist_activate(UiEvent *event, void *userdata) { UiSubListEventData *eventdata = event->eventdata; - printf("sourcelist %s index %d\n", eventdata->row_data, event->intval); + printf("sourcelist %s index %d\n", eventdata->row_data, eventdata->row_index); + ui_list_update_row(eventdata->list, eventdata->row_index); } void action_table_activate(UiEvent *event, void *userdata) {
--- a/ui/gtk/list.c Wed Sep 24 21:00:42 2025 +0200 +++ b/ui/gtk/list.c Wed Sep 24 21:33:33 2025 +0200 @@ -2178,7 +2178,7 @@ } } -static GtkWidget* create_listbox_row(UiListBox *listbox, UiListBoxSubList *sublist, UiSubListItem *item, int index) { +static void listbox_fill_row(UiListBox *listbox, GtkWidget *row, UiListBoxSubList *sublist, UiSubListItem *item, int index) { GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); if(item->icon) { GtkWidget *icon = ICON_IMAGE(item->icon); @@ -2190,7 +2190,6 @@ if(item->badge) { } - GtkWidget *row = gtk_list_box_row_new(); LISTBOX_ROW_SET_CHILD(row, hbox); // signals @@ -2241,8 +2240,36 @@ event ); } +} + +static void update_sublist_item(UiListBox *listbox, UiListBoxSubList *sublist, int index) { + GtkListBoxRow *row = gtk_list_box_get_row_at_index(listbox->listbox, sublist->startpos + index); + if(!row) { + return; + } + UiList *list = sublist->var->value; + if(!list) { + return; + } - return row; + void *elm = list->get(list, index); + UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL }; + if(listbox->getvalue) { + listbox->getvalue(list, sublist->userdata, elm, index, &item, listbox->getvaluedata); + } else { + item.label = strdup(elm); + } + + LISTBOX_ROW_REMOVE_CHILD(row); + + listbox_fill_row(listbox, GTK_WIDGET(row), sublist, &item, index); + + // cleanup + free(item.label); + free(item.icon); + free(item.button_label); + free(item.button_icon); + free(item.badge); } void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) { @@ -2289,7 +2316,8 @@ } // create listbox item - GtkWidget *row = create_listbox_row(listbox, sublist, &item, (int)index); + GtkWidget *row = gtk_list_box_row_new(); + listbox_fill_row(listbox, row, sublist, &item, (int)index); if(index == 0) { // first row in the sublist, set ui_listbox data to the row // which is then used by the headerfunc @@ -2323,14 +2351,17 @@ 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; + if(i < 0) { + 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 += ls->numitems; + } + } else { + update_sublist_item(sublist->listbox, sublist, i); } - } void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) {
--- a/ui/gtk/toolkit.h Wed Sep 24 21:00:42 2025 +0200 +++ b/ui/gtk/toolkit.h Wed Sep 24 21:33:33 2025 +0200 @@ -74,6 +74,7 @@ #define ICON_IMAGE(icon) gtk_image_new_from_icon_name(icon) #define LISTBOX_REMOVE(listbox, row) gtk_list_box_remove(GTK_LIST_BOX(listbox), row) #define LISTBOX_ROW_SET_CHILD(row, child) gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), child) +#define LISTBOX_ROW_REMOVE_CHILD(row) gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), NULL) #define PANED_SET_CHILD1(paned, child) gtk_paned_set_start_child(GTK_PANED(paned), child) #define PANED_SET_CHILD2(paned, child) gtk_paned_set_end_child(GTK_PANED(paned), child) #else @@ -96,6 +97,7 @@ #define ICON_IMAGE(icon) gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON) #define LISTBOX_REMOVE(listbox, row) gtk_container_remove(GTK_CONTAINER(listbox), row) #define LISTBOX_ROW_SET_CHILD(row, child) gtk_container_add(GTK_CONTAINER(row), child) +#define LISTBOX_ROW_REMOVE_CHILD(row) gtk_container_remove(GTK_CONTAINER(row), gtk_bin_get_child(GTK_BIN(row))) #define PANED_SET_CHILD1(paned, child) gtk_paned_pack1(GTK_PANED(paned), child, TRUE, TRUE) #define PANED_SET_CHILD2(paned, child) gtk_paned_pack2(GTK_PANED(paned), child, TRUE, TRUE) #endif