ui/gtk/container.c

changeset 60
ee4e4742391e
parent 56
294d5515583a
--- a/ui/gtk/container.c	Wed Oct 23 21:46:43 2024 +0200
+++ b/ui/gtk/container.c	Sun Oct 27 18:24:37 2024 +0100
@@ -68,6 +68,44 @@
 #endif
 }
 
+GtkWidget* ui_subcontainer_create(
+        UiSubContainerType type,
+        UiObject *newobj,
+        int spacing,
+        int columnspacing,
+        int rowspacing,
+        int margin)
+{
+    GtkWidget *sub = NULL;
+    GtkWidget *add = NULL;
+    switch(type) {
+        default: {
+            sub = ui_gtk_vbox_new(spacing);
+            add = ui_box_set_margin(sub, margin);
+            newobj->container = ui_box_container(newobj, sub, type);
+            newobj->widget = sub;
+            break;
+        }
+        case UI_CONTAINER_HBOX: {
+            sub = ui_gtk_hbox_new(spacing);
+            add = ui_box_set_margin(sub, margin);
+            newobj->container = ui_box_container(newobj, sub, type);
+            newobj->widget = sub;
+            break;
+        }
+        case UI_CONTAINER_GRID: {
+            sub = ui_create_grid_widget(columnspacing, rowspacing);
+            add = ui_box_set_margin(sub, margin);
+            newobj->container = ui_grid_container(newobj, sub);
+            newobj->widget = sub;
+            break;
+        }
+        case UI_CONTAINER_NO_SUB: {
+            break;
+        }
+    }
+    return add;
+}
 
 
 /* -------------------- Box Container -------------------- */
@@ -201,6 +239,41 @@
 }
 #endif
 
+UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) {
+    UiContainer *ct = cxCalloc(
+            obj->ctx->allocator,
+            1,
+            sizeof(UiContainer));
+    ct->widget = frame;
+    ct->add = ui_frame_container_add;
+    return ct;
+}
+
+void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    FRAME_SET_CHILD(ct->widget, widget);
+}
+
+UiContainer* ui_expander_container(UiObject *obj, GtkWidget *expander) {
+    UiContainer *ct = cxCalloc(
+            obj->ctx->allocator,
+            1,
+            sizeof(UiContainer));
+    ct->widget = expander;
+    ct->add = ui_expander_container_add;
+    return ct;
+}
+
+void ui_expander_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    EXPANDER_SET_CHILD(ct->widget, widget);
+}
+
+void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    // TODO: check if the widget implements GtkScrollable
+    SCROLLEDWINDOW_SET_CHILD(ct->widget, widget);
+    ui_reset_layout(ct->layout);
+    ct->current = widget;
+}
+
 UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow) {
     UiContainer *ct = cxCalloc(
             obj->ctx->allocator,
@@ -211,13 +284,6 @@
     return ct;
 }
 
-void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
-    // TODO: check if the widget implements GtkScrollable
-    SCROLLEDWINDOW_SET_CHILD(ct->widget, widget);
-    ui_reset_layout(ct->layout);
-    ct->current = widget;
-}
-
 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
     UiTabViewContainer *ct = cxCalloc(
             obj->ctx->allocator,
@@ -318,6 +384,45 @@
     return widget;
 }
 
+UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    UI_APPLY_LAYOUT1(current, args);
+    
+    GtkWidget *frame = gtk_frame_new(args.label);
+    UiObject *newobj = uic_object_new(obj, frame);
+    GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin);
+    if(sub) {
+        FRAME_SET_CHILD(frame, sub);
+    } else {
+        newobj->widget = frame;
+        newobj->container = ui_frame_container(obj, frame);
+    }
+    current->container->add(current->container, frame, FALSE);
+    uic_obj_add(obj, newobj);
+    
+    return frame;
+}
+
+UIEXPORT UIWIDGET ui_expander_create(UiObject *obj, UiFrameArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    UI_APPLY_LAYOUT1(current, args);
+    
+    GtkWidget *expander = gtk_expander_new(args.label);
+    gtk_expander_set_expanded(GTK_EXPANDER(expander), args.isexpanded);
+    UiObject *newobj = uic_object_new(obj, expander);
+    GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin);
+    if(sub) {
+        EXPANDER_SET_CHILD(expander, sub);
+    } else {
+        newobj->widget = expander;
+        newobj->container = ui_expander_container(obj, expander);
+    }
+    current->container->add(current->container, expander, FALSE);
+    uic_obj_add(obj, newobj);
+    
+    return expander;
+}
+
 
 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
     UiObject* current = uic_current_obj(obj);
@@ -325,8 +430,18 @@
     
     GtkWidget *sw = SCROLLEDWINDOW_NEW();
     ui_set_name_and_style(sw, args.name, args.style_class);
+    GtkWidget *widget = ui_box_set_margin(sw, args.margin);
+    current->container->add(current->container, widget, TRUE);
+    
     UiObject *newobj = uic_object_new(obj, sw);
-    newobj->container = ui_scrolledwindow_container(obj, sw);
+    GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin);
+    if(sub) {
+        SCROLLEDWINDOW_SET_CHILD(sw, sub);
+    } else {
+        newobj->widget = sw;
+        newobj->container = ui_scrolledwindow_container(obj, sw);
+    }
+    
     uic_obj_add(obj, newobj);
     
     return sw;

mercurial