diff -r e06714e6fa12 -r 00735562b25b ui/gtk/container.c --- a/ui/gtk/container.c Sun Feb 16 20:57:04 2025 +0100 +++ b/ui/gtk/container.c Sun Feb 16 21:15:17 2025 +0100 @@ -107,7 +107,7 @@ 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->container = ui_grid_container(newobj, sub, FALSE, FALSE, FALSE, FALSE); newobj->widget = sub; break; } @@ -167,11 +167,22 @@ ct->current = widget; } -UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid) { +UiContainer* ui_grid_container( + UiObject *obj, + GtkWidget *grid, + UiBool def_hexpand, + UiBool def_vexpand, + UiBool def_hfill, + UiBool def_vfill) +{ UiGridContainer *ct = cxCalloc( obj->ctx->allocator, 1, sizeof(UiGridContainer)); + ct->def_hexpand = def_hexpand; + ct->def_vexpand = def_vexpand; + ct->def_hfill = def_hfill; + ct->def_vfill = def_vfill; ct->container.widget = grid; ct->container.add = ui_grid_container_add; UI_GTK_V2(ct->width = 0); @@ -193,15 +204,34 @@ int vexpand = FALSE; int hfill = FALSE; int vfill = FALSE; + if(!ct->layout.override_defaults) { + if(grid->def_hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(grid->def_hfill) { + hfill = TRUE; + } + if(grid->def_vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(grid->def_vfill) { + vfill = TRUE; + } + } + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { fill = ui_lb2bool(ct->layout.fill); } - if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { - hexpand = ct->layout.hexpand; + if(ct->layout.hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(ct->layout.hfill) { hfill = TRUE; } - if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { - vexpand = ct->layout.vexpand; + if(ct->layout.vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(ct->layout.vfill) { vfill = TRUE; } if(fill) { @@ -241,14 +271,57 @@ int hexpand = FALSE; int vexpand = FALSE; - if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { - hexpand = ct->layout.hexpand; + int hfill = FALSE; + int vfill = FALSE; + if(!ct->layout.override_defaults) { + if(grid->def_hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(grid->def_hfill) { + hfill = TRUE; + } + if(grid->def_vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(grid->def_vfill) { + vfill = TRUE; + } + } + + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(ct->layout.fill); + } + if(ct->layout.hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(ct->layout.hfill) { + hfill = TRUE; } - if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { - vexpand = ct->layout.vexpand; + if(ct->layout.vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(ct->layout.vfill) { + vfill = TRUE; + } + if(fill) { + hfill = TRUE; + vfill = TRUE; } - GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; - GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; + + GtkAttachOptions xoptions = 0; + GtkAttachOptions yoptions = 0; + if(hexpand) { + xoptions = GTK_EXPAND; + } + if(hfill) { + xoptions |= GTK_FILL; + } + if(vexpand) { + yoptions = GTK_EXPAND; + } + if(vfill) { + yoptions |= GTK_FILL; + } int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1; int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1; @@ -407,7 +480,7 @@ current->container->add(current->container, widget, TRUE); UiObject *newobj = uic_object_new(obj, grid); - newobj->container = ui_grid_container(obj, grid); + newobj->container = ui_grid_container(obj, grid, args.def_hexpand, args.def_vexpand, args.def_hfill, args.def_vfill); uic_obj_add(obj, newobj); return widget; @@ -766,7 +839,7 @@ } case UI_CONTAINER_GRID: { sub = ui_create_grid_widget(data->columnspacing, data->rowspacing); - newobj->container = ui_grid_container(newobj, sub); + newobj->container = ui_grid_container(newobj, sub, FALSE, FALSE, FALSE, FALSE); break; } } @@ -1175,6 +1248,11 @@ ct->layout.vfill = fill; } +UIEXPORT void ui_layout_override_defaults(UiObject *obj, UiBool d) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.override_defaults = d; +} + void ui_layout_colspan(UiObject* obj, int cols) { UiContainer* ct = uic_get_current_container(obj); ct->layout.colspan = cols;