--- a/ui/qt/container.cpp Sun Oct 05 18:13:15 2025 +0200 +++ b/ui/qt/container.cpp Sun Oct 05 19:06:34 2025 +0200 @@ -29,6 +29,7 @@ #include <stdio.h> #include "container.h" #include "../common/object.h" +#include "../common/container.h" #include <cx/mempool.h> @@ -47,6 +48,7 @@ container->container = ct; container->prev = NULL; container->next = NULL; + ct->container = container; cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container); uic_object_push_container(obj, container); } @@ -57,11 +59,9 @@ this->box = box; box->setContentsMargins(QMargins(0,0,0,0)); box->setSpacing(0); - - ui_reset_layout(layout); } -void UiBoxContainer::add(QWidget* widget) { +void UiBoxContainer::add(QWidget* widget, UiLayout& layout) { bool fill = layout.fill; if(hasStretchedWidget && fill) { fill = false; @@ -80,18 +80,17 @@ if(fill) { hasStretchedWidget = true; } - ui_reset_layout(layout); current = widget; } UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) { UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); QWidget *widget = new QWidget(); QBoxLayout *box = new QBoxLayout(dir); widget->setLayout(box); - ctn->add(widget); + ctn->add(widget, layout); ui_container_add(obj, new UiBoxContainer(box)); @@ -128,71 +127,36 @@ grid->setContentsMargins(QMargins(margin, margin, margin, margin)); grid->setHorizontalSpacing(columnspacing); grid->setVerticalSpacing(rowspacing); - ui_reset_layout(layout); } -void UiGridContainer::add(QWidget* widget) { - if(layout.newline) { +void UiGridContainer::add(QWidget* widget, UiLayout& layout) { + if(container->newline) { x = 0; y++; + container->newline = false; } - bool fill = layout.fill; - bool hexpand = false; - bool vexpand = false; - bool hfill = false; - bool vfill = false; - if(!layout.override_defaults) { - if(def_hexpand) { - hexpand = true; - hfill = true; - } else if(def_hfill) { - hfill = true; - } - if(def_vexpand) { - vexpand = true; - vfill = true; - } else if(def_vfill) { - vfill = true; - } + uic_layout_setup_expand_fill(&layout, def_hexpand, def_vexpand, def_hfill, def_vfill); + + if(layout.hexpand) { + col_expanding = true; + } + if(layout.vexpand) { + row_expanding = true; } if(layout.hexpand) { - hexpand = true; - //hfill = true; - } else if(layout.hfill) { - hfill = true; + grid->setColumnStretch(x, 1); } if(layout.vexpand) { - vexpand = true; - //vfill = true; - } else if(layout.vfill) { - vfill = true; - } - if(fill) { - hfill = true; - vfill = true; - } - - if(hexpand) { - col_expanding = true; - } - if(vexpand) { - row_expanding = true; - } - - if(hexpand) { - grid->setColumnStretch(x, 1); - } - if(vexpand) { grid->setRowStretch(y, 1); } Qt::Alignment alignment = 0; - if(!hfill) { + if(!layout.hfill) { alignment = Qt::AlignLeft; } - if(!vfill) { + if(!layout.vfill) { alignment = Qt::AlignTop; } @@ -210,7 +174,6 @@ x += colspan; - ui_reset_layout(layout); current = widget; } @@ -231,12 +194,12 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); QWidget *widget = new QWidget(); QGridLayout *grid = new QGridLayout(); widget->setLayout(grid); - ctn->add(widget); + ctn->add(widget, layout); ui_container_add(obj, new UiGridContainer( grid, @@ -288,15 +251,3 @@ return 1; } - -/* - * -------------------- Layout Functions -------------------- - * - * functions for setting layout attributes for the current container - * - */ - -void ui_newline(UiObject *obj) { - UiContainerPrivate *ct = ui_obj_container(obj); - ct->layout.newline = TRUE; -}