application/main.c

branch
newapi
changeset 411
3e91b7aff6a1
parent 409
86fbc80f0be7
child 414
ef60d527c066
--- a/application/main.c	Thu Dec 05 20:02:30 2024 +0100
+++ b/application/main.c	Fri Dec 06 13:11:09 2024 +0100
@@ -48,6 +48,8 @@
     UiInteger *radio;
     UiInteger *tabview;
     UiGeneric *image;
+    UiList *srclist1;
+    UiList *srclist2;
 } MyDocument;
 
 MyDocument *doc1;
@@ -168,6 +170,17 @@
     doc->radio = ui_int_new(docctx, "radio");
     doc->tabview = ui_int_new(docctx, "tabview");
     doc->image = ui_generic_new(docctx, "image");
+    
+    doc->srclist1 = ui_list_new(docctx, "srclist1");
+    doc->srclist2 = ui_list_new(docctx, "srclist2");
+    ui_list_append(doc->srclist1, "test1");
+    ui_list_append(doc->srclist1, "test2");
+    ui_list_append(doc->srclist1, "test3");
+    ui_list_append(doc->srclist2, "x1");
+    ui_list_append(doc->srclist2, "x2");
+    
+    
+    
     //doc->text = ui_text_new(docctx, "text");
     return doc;
 }
@@ -252,12 +265,21 @@
     ui_show(obj);
 }
 
+void action_sourcelist_activate(UiEvent *event, void *userdata) {
+    printf("sourcelist %s index %d\n", event->eventdata, event->intval);
+}
+
 UiMenuBuilder *menubuilder;
 
 void* table_getvalue(void *row, int col) {
     return row;
 }
 
+void sourcelist_getvalue(void *sublistdata, void *rowdata, int index, UiSubListItem *item) {
+    item->label = strdup(rowdata);
+    item->eventdata = sublistdata;
+}
+
 void application_startup(UiEvent *event, void *data) {
     // global list
     UiContext *global = ui_global_context();
@@ -270,17 +292,16 @@
     
     UiObject *obj = ui_sidebar_window("Test", NULL);
     
-    ui_sidebar(obj, .margin = 8, .spacing = 8) {
-        ui_button(obj, .label = "Button 1", .style_class = "flat");
-        ui_button(obj, .label = "Button 2", .style_class = "flat");
-        ui_button(obj, .label = "Button 3", .style_class = "flat");
-        ui_button(obj, .label = "Button 4", .style_class = "flat");
-        ui_button(obj, .label = "Button 5", .style_class = "flat");
-    }
-    
     MyDocument *doc = create_doc();
     ui_attach_document(obj->ctx, doc);
     
+    ui_sidebar(obj, .margin = 0, .spacing = 0) {
+        ui_sourcelist(obj, .fill = UI_ON,
+                .getvalue = sourcelist_getvalue,
+                .sublists = UI_SUBLISTS(UI_SUBLIST(.varname = "srclist1", .header = "Header 1", .userdata = "Sublist1"), UI_SUBLIST(.varname = "srclist2", .header = "Header 2", .userdata = "Sublist2")),
+                .onactivate = action_sourcelist_activate);
+    }
+    
     ui_tabview(obj, .spacing=10, .margin=10, .tabview = UI_TABVIEW_NAVIGATION_SIDE, .varname="tabview") {
         ui_tab(obj, "Tab 1") {
             ui_vbox(obj, .fill = UI_OFF, .margin = 15, .spacing = 15) {
@@ -314,7 +335,7 @@
                 ui_newline(obj);
 
                 //ui_button(obj, .label="Test");
-                ui_path_textfield(obj, .varname = "path");
+                ui_path_textfield(obj, .varname = "path", .hfill = TRUE, .hexpand = TRUE);
                 ui_set(doc->path, "/test/path/longdirectoryname/123");
                 ui_newline(obj);
 

mercurial