# HG changeset patch # User Olaf Wintermann # Date 1696192488 -7200 # Node ID 74c688cc1839574125cc632f67ba483692a01774 # Parent bcacd00ea95510ff8fb3ef80bcbf395d88fc9401 add frame container (WinUI3) diff -r bcacd00ea955 -r 74c688cc1839 make/vs/testapp/main.c --- a/make/vs/testapp/main.c Sun Oct 01 18:54:23 2023 +0200 +++ b/make/vs/testapp/main.c Sun Oct 01 22:34:48 2023 +0200 @@ -106,6 +106,11 @@ ui_textfield(obj, .value = wdata->text); ui_passwordfield(obj, .value = wdata->password); + ui_newline(obj); + + ui_frame(obj, .label = "Test", .colspan = 3, .vexpand = true) { + ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); + } } ui_show(obj); diff -r bcacd00ea955 -r 74c688cc1839 make/vs/testapp/packages.config --- a/make/vs/testapp/packages.config Sun Oct 01 18:54:23 2023 +0200 +++ b/make/vs/testapp/packages.config Sun Oct 01 22:34:48 2023 +0200 @@ -1,6 +1,7 @@  + \ No newline at end of file diff -r bcacd00ea955 -r 74c688cc1839 make/vs/testapp/testapp.vcxproj --- a/make/vs/testapp/testapp.vcxproj Sun Oct 01 18:54:23 2023 +0200 +++ b/make/vs/testapp/testapp.vcxproj Sun Oct 01 22:34:48 2023 +0200 @@ -156,6 +156,7 @@ + @@ -167,5 +168,6 @@ + \ No newline at end of file diff -r bcacd00ea955 -r 74c688cc1839 ui/ui/container.h --- a/ui/ui/container.h Sun Oct 01 18:54:23 2023 +0200 +++ b/ui/ui/container.h Sun Oct 01 22:34:48 2023 +0200 @@ -48,11 +48,22 @@ int rowspacing; } UiContainerArgs; +typedef struct UiFrameArgs { + UiTri fill; + UiBool hexpand; + UiBool vexpand; + int colspan; + int rowspan; + + const char* label; +} 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)) void ui_end(UiObject *obj); @@ -62,6 +73,12 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); +UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args); + + + + + UIWIDGET ui_scrolledwindow(UiObject *obj); UIWIDGET ui_sidebar(UiObject *obj); diff -r bcacd00ea955 -r 74c688cc1839 ui/winui/container.cpp --- a/ui/winui/container.cpp Sun Oct 01 18:54:23 2023 +0200 +++ b/ui/winui/container.cpp Sun Oct 01 22:34:48 2023 +0200 @@ -31,6 +31,11 @@ #include "../common/context.h" #include "../common/object.h" +#include "util.h" + +#include +#include + void ui_container_begin_close(UiObject* obj) { UiContainer* ct = uic_get_current_container(obj); @@ -78,6 +83,11 @@ this->grid = grid; this->type = type; + Thickness t = { (double)margin, (double)margin, (double)margin, (double)margin }; + grid.Margin(t); + grid.ColumnSpacing((double)spacing); + grid.RowSpacing((double)spacing); + GridLength gl; gl.Value = 1; gl.GridUnitType = GridUnitType::Star; @@ -228,6 +238,78 @@ ui_reset_layout(layout); } +// --------------------- UiFrameContainer --------------------- + +UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args) { + // create a grid for the frame, that contains the label and a sub-frame + Grid frame = Grid(); + + GridLength gl; + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + + ColumnDefinition coldef = ColumnDefinition(); + coldef.Width(gl); + frame.ColumnDefinitions().Append(coldef); + + RowDefinition rowdefFrame = RowDefinition(); + rowdefFrame.Height(gl); + + // label + int row = 0; + if (args.label) { + RowDefinition rowdefLabel = RowDefinition(); + gl.GridUnitType = GridUnitType::Auto; + gl.Value = 0; + rowdefLabel.Height(gl); + frame.RowDefinitions().Append(rowdefLabel); + + TextBlock label = TextBlock(); + wchar_t* wlabel = str2wstr(args.label, nullptr); + winrt::hstring hstr(wlabel); + label.Text(hstr); + free(wlabel); + + frame.SetRow(label, row++); + frame.SetColumn(label, 0); + frame.Children().Append(label); + } + + // workarea frame + frame.RowDefinitions().Append(rowdefFrame); + + Grid workarea = Grid(); + frame.SetRow(workarea, row); + frame.SetColumn(workarea, 0); + frame.Children().Append(workarea); + + // some styling for the workarea + winrt::Microsoft::UI::Xaml::Media::SolidColorBrush brush{ winrt::Microsoft::UI::ColorHelper::FromArgb(150, 150, 150, 150) }; + workarea.BorderBrush(brush); + CornerRadius radius{ 8, 8, 8, 8 }; + Thickness t = { 1, 1, 1, 1 }; + workarea.CornerRadius(radius); + workarea.BorderThickness(t); + + Thickness padding = { 10, 10, 10, 10 }; + workarea.Padding(padding); + + // add frame to the parent container + UiObject* current = uic_current_obj(obj); + UI_APPLY_LAYOUT1(current, args); + current->container->Add(frame, true); + + UIElement elm = frame; + UiWidget* widget = new UiWidget(elm); + + UiObject* newobj = uic_object_new(obj, widget); + newobj->container = new UiBoxContainer(workarea, UI_CONTAINER_VBOX, 0, 0); + uic_obj_add(obj, newobj); + + return widget; +} + + /* * -------------------- Layout Functions -------------------- * diff -r bcacd00ea955 -r 74c688cc1839 ui/winui/packages.config --- a/ui/winui/packages.config Sun Oct 01 18:54:23 2023 +0200 +++ b/ui/winui/packages.config Sun Oct 01 22:34:48 2023 +0200 @@ -1,6 +1,7 @@  + \ No newline at end of file diff -r bcacd00ea955 -r 74c688cc1839 ui/winui/winui.vcxproj --- a/ui/winui/winui.vcxproj Sun Oct 01 18:54:23 2023 +0200 +++ b/ui/winui/winui.vcxproj Sun Oct 01 22:34:48 2023 +0200 @@ -204,6 +204,7 @@ + @@ -215,5 +216,6 @@ + \ No newline at end of file