ui/gtk/container.c

changeset 103
6606616eca9f
parent 102
64ded9f6a6c6
child 108
77254bd6dccb
--- a/ui/gtk/container.c	Tue Feb 25 21:11:00 2025 +0100
+++ b/ui/gtk/container.c	Sat Apr 05 16:46:11 2025 +0200
@@ -52,17 +52,6 @@
     return 1;
 }
 
-UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) {
-    UiObject* current = uic_current_obj(obj);
-    
-    UIWIDGET widget = create_widget(obj, args, userdata);
-    
-    UI_APPLY_LAYOUT1(current, args);
-    current->container->add(current->container, widget, FALSE);
-    
-    return widget;
-}
-
 GtkWidget* ui_gtk_vbox_new(int spacing) {
 #if GTK_MAJOR_VERSION >= 3
     return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing);
@@ -1041,9 +1030,11 @@
     int max = args.max_panes == 0 ? 2 : args.max_panes;
     
     UiObject *newobj = uic_object_new(obj, pane0);
-    newobj->container = ui_splitpane_container(obj, pane0, orientation, max);
+    newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args.initial_position);
     uic_obj_add(obj, newobj);
     
+    g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container);
+    
     return pane0;
 }
 
@@ -1055,13 +1046,15 @@
     return splitpane_create(obj, UI_VERTICAL, args);
 }
 
-UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientation orientation, int max) {
+UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientation orientation, int max, int init) {
     UiSplitPaneContainer *ct = ui_calloc(obj->ctx, 1, sizeof(UiSplitPaneContainer));
     ct->container.widget = pane;
     ct->container.add = ui_splitpane_container_add;
     ct->current_pane = pane;
     ct->orientation = orientation;
     ct->max = max;
+    ct->initial_position = init;
+    ct->children = cxArrayListCreateSimple(CX_STORE_POINTERS, 4);
     return (UiContainer*)ct;
 }
 
@@ -1073,17 +1066,22 @@
         return;
     }
     
+    cxListAdd(s->children, widget);
+    
     if(s->pos == 0) {
-        gtk_paned_set_start_child(GTK_PANED(s->current_pane), widget);
+        PANED_SET_CHILD1(s->current_pane, widget);
+        if(s->initial_position > 0) {
+            gtk_paned_set_position(GTK_PANED(s->current_pane), s->initial_position);
+        }
         s->pos++;
         s->nchildren++;
     } else {
         if(s->nchildren+1 == s->max) {
-            gtk_paned_set_end_child(GTK_PANED(s->current_pane), widget);
+            PANED_SET_CHILD2(s->current_pane, widget);
         } else {
             GtkWidget *pane = create_paned(s->orientation);
-            gtk_paned_set_start_child(GTK_PANED(pane), widget);
-            gtk_paned_set_end_child(GTK_PANED(s->current_pane), pane);
+            PANED_SET_CHILD1(pane, widget);
+            PANED_SET_CHILD2(s->current_pane, pane);
             s->current_pane = pane;
         }
         
@@ -1092,6 +1090,19 @@
     }
 }
 
+UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) {
+    UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane");
+    if(!ct) {
+        fprintf(stderr, "UI Error: not a splitpane\n");
+        return;
+    }
+    
+    GtkWidget *w = cxListAt(ct->children, child_index);
+    if(w) {
+        gtk_widget_set_visible(w, visible);
+    }
+}
+
 /* -------------------- ItemList Container -------------------- */
 
 static void remove_item(void *data, void *item) {

mercurial