# HG changeset patch # User Olaf Wintermann # Date 1696171982 -7200 # Node ID 70fd1b24e3951603acd154c4dd7d86afcf7c1d36 # Parent 4daddc326877fbcf2486082a3315ffd3a6b4a075 implement new api style for box and grid containers (WinUI3) diff -r 4daddc326877 -r 70fd1b24e395 make/vs/testapp/main.c --- a/make/vs/testapp/main.c Sun Oct 01 16:39:03 2023 +0200 +++ b/make/vs/testapp/main.c Sun Oct 01 16:53:02 2023 +0200 @@ -69,7 +69,7 @@ wdata->toggle = ui_int_new(obj->ctx, "toggle"); wdata->radio = ui_int_new(obj->ctx, "radio"); - UI_GRID_SP(obj, 10, 5, 20) { + ui_grid(obj, .margin=10, .columnspacing=5, .rowspacing=20) { ui_button(obj, .label="Button1", .onclick=action1, .onclickdata="action1"); ui_button(obj, .label="Button2", .onclick=action1, .onclickdata="action2"); ui_button(obj, .label="Button3", .onclick=action1, .onclickdata="action3", .hexpand=true); @@ -86,8 +86,7 @@ ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle); ui_newline(obj); - ui_layout_colspan(obj, 3); - UI_HBOX(obj) { + ui_hbox(obj, .colspan=3) { ui_radiobutton(obj, .label = "Radio 1", .value = wdata->radio); ui_radiobutton(obj, .label = "Radio 2", .value = wdata->radio); ui_radiobutton(obj, .label = "Radio 3", .value = wdata->radio); diff -r 4daddc326877 -r 70fd1b24e395 ui/ui/container.h --- a/ui/ui/container.h Sun Oct 01 16:39:03 2023 +0200 +++ b/ui/ui/container.h Sun Oct 01 16:53:02 2023 +0200 @@ -35,25 +35,32 @@ extern "C" { #endif +typedef struct UiContainerArgs { + UiTri fill; + UiBool hexpand; + UiBool vexpand; + int colspan; + int rowspan; + + int margin; + int spacing; + int columnspacing; + int rowspacing; +} UiContainerArgs; #define UI_CTN(obj, ctn) for(ctn;ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_VBOX(obj) for(ui_vbox(obj);ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_HBOX(obj) for(ui_hbox(obj);ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_VBOX_SP(obj, margin, spacing) for(ui_vbox_sp(obj,margin,spacing);ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_HBOX_SP(obj, margin, spacing) for(ui_hbox_sp(obj,margin,spacing);ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_GRID(obj) for(ui_grid(obj);ui_container_finish(obj);ui_container_begin_close(obj)) -#define UI_GRID_SP(obj, margin, columnspacing, rowspacing) for(ui_grid_sp(obj,margin,columnspacing,rowspacing);ui_container_finish(obj);ui_container_begin_close(obj)) - + +#define ui_vbox(obj, ...) for(ui_vbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_hbox(obj, ...) for(ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_grid(obj, ...) for(ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) + void ui_end(UiObject *obj); -UIWIDGET ui_vbox(UiObject *obj); -UIWIDGET ui_hbox(UiObject *obj); -UIWIDGET ui_vbox_sp(UiObject *obj, int margin, int spacing); -UIWIDGET ui_hbox_sp(UiObject *obj, int margin, int spacing); +UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args); +UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args); -UIWIDGET ui_grid(UiObject *obj); -UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing); +UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_scrolledwindow(UiObject *obj); diff -r 4daddc326877 -r 70fd1b24e395 ui/winui/container.cpp --- a/ui/winui/container.cpp Sun Oct 01 16:39:03 2023 +0200 +++ b/ui/winui/container.cpp Sun Oct 01 16:53:02 2023 +0200 @@ -49,31 +49,32 @@ // --------------------- UiBoxContainer --------------------- -static UIWIDGET ui_box(UiObject* obj, UiBoxContainerType type) { - UiContainer* ct = uic_get_current_container(obj); +static UIWIDGET ui_box(UiObject* obj, UiContainerArgs args, UiBoxContainerType type) { + UiObject* current = uic_current_obj(obj); + UI_APPLY_LAYOUT1(current, args); Grid grid = Grid(); - ct->Add(grid, true); + current->container->Add(grid, true); UIElement elm = grid; UiWidget* widget = new UiWidget(elm); UiObject* newobj = uic_object_new(obj, widget); - newobj->container = new UiBoxContainer(grid, type); + newobj->container = new UiBoxContainer(grid, type, args.margin, args.spacing); uic_obj_add(obj, newobj); return widget; } -UIWIDGET ui_vbox(UiObject* obj) { - return ui_box(obj, UI_CONTAINER_VBOX); +UIWIDGET ui_vbox_create(UiObject* obj, UiContainerArgs args) { + return ui_box(obj, args, UI_CONTAINER_VBOX); } -UIWIDGET ui_hbox(UiObject* obj) { - return ui_box(obj, UI_CONTAINER_HBOX); +UIWIDGET ui_hbox_create(UiObject* obj, UiContainerArgs args) { + return ui_box(obj, args, UI_CONTAINER_HBOX); } -UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type) { +UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) { this->grid = grid; this->type = type; @@ -136,21 +137,18 @@ // --------------------- UiGridContainer --------------------- -UIWIDGET ui_grid(UiObject* obj) { - return ui_grid_sp(obj, 0, 0, 0); -} - -UIWIDGET ui_grid_sp(UiObject* obj, int margin, int columnspacing, int rowspacing) { - UiContainer* ct = uic_get_current_container(obj); +UIWIDGET ui_grid_create(UiObject* obj, UiContainerArgs args) { + UiObject* current = uic_current_obj(obj); + UI_APPLY_LAYOUT1(current, args); Grid grid = Grid(); - ct->Add(grid, true); + current->container->Add(grid, true); UIElement elm = grid; UiWidget* widget = new UiWidget(elm); UiObject* newobj = uic_object_new(obj, widget); - newobj->container = new UiGridContainer(grid, margin, columnspacing, rowspacing); + newobj->container = new UiGridContainer(grid, args.margin, args.columnspacing, args.rowspacing); uic_obj_add(obj, newobj); return widget; diff -r 4daddc326877 -r 70fd1b24e395 ui/winui/container.h --- a/ui/winui/container.h Sun Oct 01 16:39:03 2023 +0200 +++ b/ui/winui/container.h Sun Oct 01 16:53:02 2023 +0200 @@ -91,7 +91,7 @@ RowDefinition boxRowDef; ColumnDefinition boxColDef; - UiBoxContainer(Grid grid, enum UiBoxContainerType type); + UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing); void Add(FrameworkElement control, UiBool fill); }; diff -r 4daddc326877 -r 70fd1b24e395 ui/winui/window.cpp --- a/ui/winui/window.cpp Sun Oct 01 16:39:03 2023 +0200 +++ b/ui/winui/window.cpp Sun Oct 01 16:53:02 2023 +0200 @@ -83,7 +83,7 @@ delete obj->wobj; }); - obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX); + obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX, 0, 0); if (uic_get_menu_list()) { // create/add menubar