--- 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 <winrt/Windows.UI.Xaml.Media.h> +#include <winrt/Microsoft.UI.Xaml.Media.h> + 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 -------------------- *