application/main.c

branch
newapi
changeset 268
1b321a0c624f
parent 267
79dd183dd4cb
child 269
3380100e20f5
--- a/application/main.c	Fri Feb 16 19:37:51 2024 +0100
+++ b/application/main.c	Sun Feb 18 19:55:56 2024 +0100
@@ -37,6 +37,7 @@
     UiString *str1;
     UiString *str2;
     UiDouble *progress;
+    UiList *list;
 } MyDocument;
 
 MyDocument *doc1;
@@ -62,9 +63,26 @@
     doc->str1 = ui_string_new(docctx, "str1");
     doc->str1 = ui_string_new(docctx, "str2");
     doc->progress = ui_double_new(docctx, "progress");
+    doc->list = ui_list_new(docctx, "list");
+    ui_list_append(doc->list, "test1");
+    ui_list_append(doc->list, "test2");
+    ui_list_append(doc->list, "test3");
     return doc;
 }
 
+UiIcon *icon = NULL;
+
+static void* list_getvalue(void *elm, int col) {
+    if(col == 0) {
+        if(!icon) {
+            icon = ui_icon("folder", 24);
+        }
+        return icon;
+    }
+    char *str = elm;
+    return col == 1 ? str : "x";
+}
+
 void application_startup(UiEvent *event, void *data) {
     
     UiObject *obj = ui_window("Test", NULL);
@@ -95,6 +113,11 @@
         ui_newline(obj);
         
         ui_textfield(obj, .value = doc->str1);
+        ui_newline(obj);
+        
+        UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1);
+        model->getvalue = list_getvalue;
+        ui_table(obj, .hexpand = true, .vexpand = true, .colspan = 2, .varname = "list", .model = model);
     }
     
     ui_show(obj);

mercurial