application/main.c

changeset 1244
a29b53f97d1a
parent 1236
34cc825ee117
--- a/application/main.c	Tue Sep 08 16:08:59 2026 +0200
+++ b/application/main.c	Wed Sep 09 18:57:52 2026 +0200
@@ -203,6 +203,7 @@
     UiString *link_label;
     UiString *link_uri;
     UiList *submenulist;
+    UiList *tree;
     
     UiModel *model;
 } MyDocument;
@@ -218,6 +219,11 @@
 
 static UiThreadpool *threadpool;
 
+typedef struct TreeNode {
+    char *name;
+    int depth;
+} TreeNode;
+
 int threadfunc(void *data) {
     printf("thr wait for data...\n");
     ui_condvar_wait(cond);
@@ -389,6 +395,33 @@
     
     ui_int_new(docctx, "menu_radio");
     
+    doc->tree = ui_list_new(docctx, "tree");
+    TreeNode *root = malloc(sizeof(TreeNode));
+    root->name = "Root";
+    root->depth = 0;
+    ui_list_append(doc->tree, root);
+    
+    TreeNode *node_a = malloc(sizeof(TreeNode));
+    node_a->name = "Folder";
+    node_a->depth = 1;
+    ui_list_append(doc->tree, node_a);
+    
+    TreeNode *node_a0 = malloc(sizeof(TreeNode));
+    node_a0->name = "Leaf 1";
+    node_a0->depth = 2;
+    ui_list_append(doc->tree, node_a0);
+    
+    TreeNode *node_a1 = malloc(sizeof(TreeNode));
+    node_a1->name = "Leaf 2";
+    node_a1->depth = 2;
+    ui_list_append(doc->tree, node_a1);
+    
+    TreeNode *node_1 = malloc(sizeof(TreeNode));
+    node_1->name = "Leaf 3";
+    node_1->depth = 1;
+    ui_list_append(doc->tree, node_1);
+    
+    
     //doc->text = ui_text_new(docctx, "text");
     return doc;
 }
@@ -537,6 +570,16 @@
     return FALSE;
 }
 
+void* tree_getvalue(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) {
+    TreeNode *node = elm;
+    return node->name;
+}
+
+int tree_getdepth(UiList *list, void *elm, int row, void *userdata) {
+    TreeNode *node = elm;
+    return node->depth;
+}
+
 void sourcelist_getvalue(UiList *list, void *sublistdata, void *rowdata, int index, UiSubListItem *item, void *userdata) {
     ui_menubuilder_ref(sourcelist_menu);
     item->label = strdup(rowdata);
@@ -906,6 +949,10 @@
         ui_tab(obj, "Tab 12") {
             ui_drawingarea(obj, .fill = TRUE, .draw = draw);
         }
+        ui_tab(obj, "Tab 13") {
+            UiModel *model = ui_model(obj->ctx, UI_STRING, "test", -1);
+            ui_treeview(obj, .fill = TRUE, .model = model, .show_header = TRUE, .getvalue = tree_getvalue, .getdepth = tree_getdepth, .varname = "tree");
+        }
     }
     
     /*

mercurial