--- a/application/main.c Mon Dec 30 12:50:52 2024 +0100 +++ b/application/main.c Mon Dec 30 19:48:05 2024 +0100 @@ -50,6 +50,7 @@ UiGeneric *image; UiList *srclist1; UiList *srclist2; + UiList *items; } MyDocument; MyDocument *doc1; @@ -179,7 +180,10 @@ ui_list_append(doc->srclist2, "x1"); ui_list_append(doc->srclist2, "x2"); - + doc->items = ui_list_new(docctx, "items"); + ui_list_append(doc->items, "Item 1"); + ui_list_append(doc->items, "Item 2"); + ui_list_append(doc->items, "Item 3"); //doc->text = ui_text_new(docctx, "text"); return doc; @@ -280,6 +284,44 @@ item->eventdata = sublistdata; } +typedef struct Item { + UiObject *obj; + MyDocument *doc; + void *elm; +} Item; + +void item_remove(UiEvent *event, void *userdata) { + Item *item = userdata; + int index = 0; + void *elm = ui_list_first(item->doc->items); + while(elm) { + if(elm == item->elm) { + break; + } + elm = ui_list_next(item->doc->items); + index++; + } + + ui_list_remove(item->doc->items, index); + ui_list_update(item->doc->items); +} + +void create_item(UiObject *obj, int index, void *elm, void *userdata) { + Item *i = ui_malloc(obj->ctx, sizeof(Item)); + i->obj = obj; + i->elm = elm; + i->doc = userdata; + + char *item = elm; + ui_button(obj, .label = item); + ui_checkbox(obj, .label = "Check"); + ui_label(obj, .fill = UI_ON); + ui_button(obj, .label = "X", .onclick = item_remove, .onclickdata = i); + + + +} + void application_startup(UiEvent *event, void *data) { // global list UiContext *global = ui_global_context(); @@ -404,6 +446,10 @@ } } } + + ui_tab(obj, "Tab 7") { + ui_itemlist(obj, .create_ui = create_item, .varname = "items", .subcontainer = UI_CONTAINER_HBOX, .sub_spacing = 10, .margin = 10, .spacing = 4, .userdata = doc); + } } /*