application/main.c

branch
newapi
changeset 427
7ead63398a50
parent 426
3eb26df703bf
child 429
0921f8a5d535
--- a/application/main.c	Tue Dec 31 17:57:43 2024 +0100
+++ b/application/main.c	Wed Jan 01 11:39:42 2025 +0100
@@ -546,9 +546,33 @@
 
 typedef struct WData {
     UiString *path;
+    UiList *list;
 } WData;
 
 
+int lsitems = 4;
+
+void action_button2(UiEvent *event, void *data) {
+    WData *wdata = event->window;
+    char *newitem = malloc(32);
+    snprintf(newitem, 32, "List Item %d", ++lsitems);
+    ui_list_append(wdata->list, newitem);
+    ui_list_update(wdata->list);
+    UiListSelection sel;
+    int index = lsitems-1;
+    sel.count = 1;
+    sel.rows = &index;
+    wdata->list->setselection(wdata->list, sel);
+}
+
+void action_listevent(UiEvent *event, void *data) {
+    printf("%s: %d\n", data, event->intval);
+    UiListSelection *sel = event->eventdata;
+    for(int i=0;i<sel->count;i++) {
+        printf("sel: %d\n", sel->rows[i]);
+    }
+    printf("\n");
+}
 
 void application_startup(UiEvent *event, void *data) {
     
@@ -562,41 +586,20 @@
     
     WData *wdata = ui_malloc(obj->ctx, sizeof(WData));
     wdata->path = ui_string_new(obj->ctx, NULL);
+    wdata->list = ui_list_new(obj->ctx, NULL);
     obj->window = wdata;
     
-    /*
-    ui_button(obj, .label = "Add Item", .onclick = action_button, .name = "mybutton1");
-    ui_button(obj, .label = "Test2", .name = "mybutton2");
-    ui_button(obj, .label = "Test3", .name = "mybutton3");
-    ui_hbox0(obj) {
-        ui_button(obj, .label = "hbutton1");
-        ui_button(obj, .label = "hbutton2");
-        ui_button(obj, .label = "hbutton3", .fill = UI_ON);
-        ui_button(obj, .label = "hbutton4");
-        ui_button(obj, .label = "hbutton5");
-        
-    }
-    ui_button(obj, .label = "Test4", .name = "mybutton4", .fill = UI_ON);
-    ui_button(obj, .label = "end");
-    */
+    ui_list_append(wdata->list, "List Item 1");
+    ui_list_append(wdata->list, "List Item 2");
+    ui_list_append(wdata->list, "List Item 3");
+    ui_list_append(wdata->list, "List Item 4");
     
-    ui_grid(obj, .columnspacing = 10, .rowspacing = 20, .fill = UI_ON) {
-        ui_button(obj, .label = "Add Item", .onclick = action_button, .name = "mybutton1");
-        ui_newline(obj);
-        ui_button(obj, .label = "Line 2 B1");
-        ui_button(obj, .label = "Line 2 B2");
-        ui_button(obj, .label = "Line 2 B3");
-        ui_newline(obj);
-        ui_button(obj, .label = "Line 3", .colspan = 3, .hfill = TRUE, .vexpand = TRUE, .vfill = TRUE);
-        ui_newline(obj);
-        ui_button(obj, .label = "Line 4 B1");
-        ui_button(obj, .label = "Line 4 B2");
-        ui_button(obj, .label = "Line 4 B3");
-        ui_button(obj, .label = "Line 4 B4", .hexpand = TRUE, .hfill = TRUE);
-        ui_button(obj, .label = "Line EOL");
-        ui_newline(obj);
-        ui_button(obj, .colspan = 5, .hfill = TRUE, .label = "EOL");
-    }
+    ui_button(obj, .label = "Add Menu Item", .onclick = action_button, .name = "mybutton1");
+    ui_button(obj, .label = "Add List Item", .onclick = action_button2);
+    ui_listview(obj, .list = wdata->list, .fill = UI_ON, .multiselection = TRUE,
+            .onactivate = action_listevent, .onactivatedata = "activate",
+            .onselection = action_listevent, .onselectiondata = "selection");
+    
     
     ui_show(obj);
 }

mercurial