implement listview (GTK) newapi

Thu, 22 Feb 2024 22:25:53 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 22 Feb 2024 22:25:53 +0100
branch
newapi
changeset 269
3380100e20f5
parent 268
1b321a0c624f
child 270
9389313ac00f

implement listview (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/tree.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Sun Feb 18 19:55:56 2024 +0100
+++ b/application/main.c	Thu Feb 22 22:25:53 2024 +0100
@@ -73,12 +73,15 @@
 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";
 }
@@ -115,9 +118,9 @@
         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);
+        //UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1);
+        //model->getvalue = list_getvalue;
+        ui_listview(obj, .hexpand = true, .vexpand = true, .colspan = 2, .varname = "list", .getvalue = list_getvalue);
     }
     
     ui_show(obj);
--- a/ui/gtk/tree.c	Sun Feb 18 19:55:56 2024 +0100
+++ b/ui/gtk/tree.c	Thu Feb 22 22:25:53 2024 +0100
@@ -144,7 +144,9 @@
 }
 
 
-UIWIDGET ui_listview_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
+UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    
     // create treeview
     GtkWidget *view = gtk_tree_view_new();
     GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
@@ -163,8 +165,11 @@
 #endif
     
     UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
-    model->getvalue = getvalue;
-    UiList *list = var->value;
+    model->getvalue = args.getvalue;
+    
+    UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
+    
+    UiList *list = var ? var->value : NULL;
     GtkListStore *listmodel = create_list_store(list, model);
     gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
     
@@ -184,11 +189,11 @@
     list->obj = listview;
     
     // add callback
-    if(f) {
+    if(args.onactivate) {
         UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
         event->obj = obj;
-        event->activatedata = udata;
-        event->activate = f;
+        event->activatedata = args.onactivatedata;
+        event->activate = args.onactivate;
         event->selection = NULL;
 
         g_signal_connect(
@@ -206,33 +211,16 @@
             GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS  
     gtk_container_add(GTK_CONTAINER(scroll_area), view);
     
-    UiContainer *ct = uic_get_current_container(obj);
-    ct->add(ct, scroll_area, TRUE);
+    UI_APPLY_LAYOUT1(current, args);
+    current->container->add(current->container, scroll_area, FALSE);
     
     // ct->current should point to view, not scroll_area, to make it possible
     // to add a context menu
-    ct->current = view;
+    current->container->current = view;
     
     return scroll_area;
 }
 
-UIWIDGET ui_listview_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
-    UiVar *var = malloc(sizeof(UiVar));
-    var->value = list;
-    var->type = UI_VAR_SPECIAL;
-    return ui_listview_var(obj, var, getvalue, f, udata);
-}
-
-UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
-    UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
-    if(var) {
-        return ui_listview_var(obj, var, getvalue, f, udata);
-    } else {
-        // TODO: error
-    }
-    return NULL;
-}
-
 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) {
     printf("drag begin\n");
     

mercurial