Mon, 02 Oct 2023 10:10:09 +0200
add expander (WinUI3)
make/vs/testapp/main.c | file | annotate | diff | comparison | revisions | |
ui/ui/container.h | file | annotate | diff | comparison | revisions | |
ui/winui/container.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/container.h | file | annotate | diff | comparison | revisions | |
ui/winui/window.cpp | file | annotate | diff | comparison | revisions |
--- a/make/vs/testapp/main.c Mon Oct 02 09:22:52 2023 +0200 +++ b/make/vs/testapp/main.c Mon Oct 02 10:10:09 2023 +0200 @@ -109,7 +109,14 @@ ui_passwordfield(obj, .value = wdata->password); ui_newline(obj); - ui_frame(obj, .label = "Test", .colspan = 3, .vexpand = true) { + ui_frame(obj, .label = "Test", .colspan = 3) { + ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); + } + ui_newline(obj); + + ui_expander(obj, .label = "Expand", .colspan = 3, .margin = 10, .spacing = 5, .isexpanded = true) { + ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); + ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); } }
--- a/ui/ui/container.h Mon Oct 02 09:22:52 2023 +0200 +++ b/ui/ui/container.h Mon Oct 02 10:10:09 2023 +0200 @@ -35,6 +35,12 @@ extern "C" { #endif +typedef enum UiSubContainerType { + UI_CONTAINER_VBOX = 0, + UI_CONTAINER_HBOX, + UI_CONTAINER_GRID +} UiSubContainerType; + typedef struct UiContainerArgs { UiTri fill; UiBool hexpand; @@ -55,22 +61,33 @@ int colspan; int rowspan; + UiSubContainerType subcontainer; + + int margin; + int spacing; + int columnspacing; + int rowspacing; + const char* label; + UiBool isexpanded; } UiFrameArgs; + #define UI_CTN(obj, ctn) for(ctn;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)) #define ui_frame(obj, ...) for(ui_frame_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) -#define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_expander(obj, ...) for(ui_expander_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_vbox0(obj) for(ui_vbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hbox0(obj) for(ui_hbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_grid0(obj) for(ui_grid_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_frame0(obj) for(ui_frame_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) -#define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_expander0(obj) for(ui_expande_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) void ui_end(UiObject *obj); @@ -78,7 +95,8 @@ UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args); -UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args); +UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args); +UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args); UIWIDGET ui_scrolledwindow_deprecated(UiObject *obj);
--- a/ui/winui/container.cpp Mon Oct 02 09:22:52 2023 +0200 +++ b/ui/winui/container.cpp Mon Oct 02 10:10:09 2023 +0200 @@ -72,11 +72,11 @@ } UIWIDGET ui_vbox_create(UiObject* obj, UiContainerArgs args) { - return ui_box(obj, args, UI_CONTAINER_VBOX); + return ui_box(obj, args, UI_BOX_CONTAINER_VBOX); } UIWIDGET ui_hbox_create(UiObject* obj, UiContainerArgs args) { - return ui_box(obj, args, UI_CONTAINER_HBOX); + return ui_box(obj, args, UI_BOX_CONTAINER_HBOX); } UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) { @@ -94,7 +94,7 @@ // hbox needs one row def, vbox needs one col def // all other col/row defs are created when elements are added - if (type == UI_CONTAINER_HBOX) { + if (type == UI_BOX_CONTAINER_HBOX) { boxRowDef = RowDefinition(); boxRowDef.Height(gl); grid.RowDefinitions().Append(boxRowDef); @@ -302,8 +302,72 @@ UIElement elm = frame; UiWidget* widget = new UiWidget(elm); + // sub container + UiContainer* ctn = nullptr; + switch (args.subcontainer) { + default: + case UI_CONTAINER_VBOX: { + ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_HBOX: { + ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_GRID: { + ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing); + break; + } + } + UiObject* newobj = uic_object_new(obj, widget); - newobj->container = new UiBoxContainer(workarea, UI_CONTAINER_VBOX, 0, 0); + newobj->container = ctn; + uic_obj_add(obj, newobj); + + return widget; +} + +// --------------------- UI Expander --------------------- + +UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args) { + Expander expander = Expander(); + if (args.label) { + wchar_t* wlabel = str2wstr(args.label, nullptr); + expander.Header(box_value(wlabel)); + free(wlabel); + } + expander.IsExpanded(args.isexpanded); + + // add frame to the parent container + UiObject* current = uic_current_obj(obj); + UI_APPLY_LAYOUT1(current, args); + current->container->Add(expander, true); + + UIElement elm = expander; + UiWidget* widget = new UiWidget(elm); + + Grid content = Grid(); + expander.Content(content); + + UiContainer* ctn = nullptr; + switch (args.subcontainer) { + default: + case UI_CONTAINER_VBOX: { + ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_HBOX: { + ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_GRID: { + ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing); + break; + } + } + + UiObject* newobj = uic_object_new(obj, widget); + newobj->container = ctn; uic_obj_add(obj, newobj); return widget; @@ -311,7 +375,7 @@ // --------------------- UI ScrolledWindow --------------------- -UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args) { +UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { ScrollViewer scrollW = ScrollViewer(); // add frame to the parent container @@ -322,12 +386,29 @@ UIElement elm = scrollW; UiWidget* widget = new UiWidget(elm); - // create a vbox as child container - Grid vbox = Grid(); - scrollW.Content(vbox); + // create child container + Grid content = Grid(); + scrollW.Content(content); + + UiContainer* ctn = nullptr; + switch (args.subcontainer) { + default: + case UI_CONTAINER_VBOX: { + ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_HBOX: { + ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); + break; + } + case UI_CONTAINER_GRID: { + ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing); + break; + } + } UiObject* newobj = uic_object_new(obj, widget); - newobj->container = new UiBoxContainer(vbox, UI_CONTAINER_VBOX, args.margin, args.spacing); + newobj->container = ctn; uic_obj_add(obj, newobj); return widget;
--- a/ui/winui/container.h Mon Oct 02 09:22:52 2023 +0200 +++ b/ui/winui/container.h Mon Oct 02 10:10:09 2023 +0200 @@ -81,8 +81,8 @@ }; enum UiBoxContainerType { - UI_CONTAINER_HBOX = 0, - UI_CONTAINER_VBOX + UI_BOX_CONTAINER_VBOX = 0, + UI_BOX_CONTAINER_HBOX }; struct UiBoxContainer : UiContainer {
--- a/ui/winui/window.cpp Mon Oct 02 09:22:52 2023 +0200 +++ b/ui/winui/window.cpp Mon Oct 02 10:10:09 2023 +0200 @@ -83,7 +83,7 @@ delete obj->wobj; }); - obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX, 0, 0); + obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0); if (uic_get_menu_list()) { // create/add menubar