ui/gtk/container.c

changeset 32
e5f4d8af567e
parent 29
3fc287f06305
--- a/ui/gtk/container.c	Mon Feb 12 21:13:23 2024 +0100
+++ b/ui/gtk/container.c	Sun Jun 09 15:43:08 2024 +0200
@@ -141,10 +141,11 @@
         gtk_widget_set_vexpand(widget, TRUE);
     }
     
-    int gwidth = ct->layout.gridwidth > 0 ? ct->layout.gridwidth : 1;
+    int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1;
+    int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1;
     
-    gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, gwidth, 1);
-    grid->x += gwidth;
+    gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, colspan, rowspan);
+    grid->x += colspan;
     
     ui_reset_layout(ct->layout);
     ct->current = widget;
@@ -171,6 +172,10 @@
     GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL;
     GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL;
     
+    int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1;
+    int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1;
+    // TODO: use colspan/rowspan
+    
     gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, xoptions, yoptions, 0, 0);
     grid->x++;
     int nw = grid->x > grid->width ? grid->x : grid->width;
@@ -254,12 +259,12 @@
     UiContainer *ct = current->container;
     UI_APPLY_LAYOUT1(current, args);
     
-    GtkWidget *vbox = ui_gtk_vbox_new(args.spacing);   
-    GtkWidget *widget = args.margin > 0 ? box_set_margin(vbox, args.margin) : vbox;
+    GtkWidget *box = type == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args.spacing) : ui_gtk_hbox_new(args.spacing);
+    GtkWidget *widget = args.margin > 0 ? box_set_margin(box, args.margin) : box;
     ct->add(ct, widget, TRUE);
     
-    UiObject *newobj = uic_object_new(obj, vbox);
-    newobj->container = ui_box_container(obj, vbox);
+    UiObject *newobj = uic_object_new(obj, box);
+    newobj->container = ui_box_container(obj, box);
     uic_obj_add(obj, newobj);
     
     return widget;
@@ -276,7 +281,8 @@
 
 
 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
-    UiContainer *ct = uic_get_current_container(obj);
+    UiObject* current = uic_current_obj(obj);
+    UI_APPLY_LAYOUT1(current, args);
     GtkWidget *widget;
     
 #ifdef UI_GTK3
@@ -287,8 +293,8 @@
     gtk_widget_set_margin_start(grid, args.margin);
     gtk_widget_set_margin_end(grid, args.margin);
 #else
-    gtk_widget_set_margin_left(grid, margin);
-    gtk_widget_set_margin_right(grid, margin);
+    gtk_widget_set_margin_left(grid, args.margin);
+    gtk_widget_set_margin_right(grid, args.margin);
 #endif
     gtk_widget_set_margin_top(grid, args.margin);
     gtk_widget_set_margin_bottom(grid, args.margin);
@@ -309,7 +315,7 @@
         widget = grid;
     }
 #endif
-    ct->add(ct, widget, TRUE);
+    current->container->add(current->container, widget, TRUE);
     
     UiObject *newobj = uic_object_new(obj, grid);
     newobj->container = ui_grid_container(obj, grid);
@@ -319,6 +325,19 @@
 }
 
 
+UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    UI_APPLY_LAYOUT1(current, args);
+    
+    GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL);
+    UiObject *newobj = uic_object_new(obj, sw);
+    newobj->container = ui_scrolledwindow_container(obj, sw);
+    uic_obj_add(obj, newobj);
+    
+    return sw;
+}
+
+
 void ui_select_tab(UIWIDGET tabview, int tab) {
     gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
 }
@@ -367,11 +386,6 @@
     ct->layout.vexpand = expand;
 }
 
-void ui_layout_gridwidth(UiObject *obj, int width) {
-    UiContainer *ct = uic_get_current_container(obj);
-    ct->layout.gridwidth = width;
-}
-
 void ui_layout_colspan(UiObject* obj, int cols) {
     UiContainer* ct = uic_get_current_container(obj);
     ct->layout.colspan = cols;

mercurial