add frame container (WinUI3) newapi

Sun, 01 Oct 2023 22:34:48 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 Oct 2023 22:34:48 +0200
branch
newapi
changeset 193
74c688cc1839
parent 192
bcacd00ea955
child 194
e2281ace0769

add frame container (WinUI3)

make/vs/testapp/main.c file | annotate | diff | comparison | revisions
make/vs/testapp/packages.config file | annotate | diff | comparison | revisions
make/vs/testapp/testapp.vcxproj 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/packages.config file | annotate | diff | comparison | revisions
ui/winui/winui.vcxproj file | annotate | diff | comparison | revisions
--- 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);
--- 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 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="Microsoft.Windows.CppWinRT" version="2.0.230225.1" targetFramework="native" />
+  <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.230824.2" targetFramework="native" />
   <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.1" targetFramework="native" />
   <package id="Microsoft.WindowsAppSDK" version="1.3.230331000" targetFramework="native" />
 </packages>
\ No newline at end of file
--- 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 @@
     <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
     <Import Project="..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets')" />
     <Import Project="..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" />
+    <Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
   </ImportGroup>
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
     <PropertyGroup>
@@ -167,5 +168,6 @@
     <Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
     <Error Condition="!Exists('..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props'))" />
     <Error Condition="!Exists('..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets'))" />
+    <Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
   </Target>
 </Project>
\ No newline at end of file
--- 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);
--- 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 --------------------
  *
--- 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 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="Microsoft.Windows.CppWinRT" version="2.0.230225.1" targetFramework="native" />
+  <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.230824.2" targetFramework="native" />
   <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.1" targetFramework="native" />
   <package id="Microsoft.WindowsAppSDK" version="1.3.230331000" targetFramework="native" />
 </packages>
\ No newline at end of file
--- 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 @@
     <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
     <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets')" />
     <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" />
+    <Import Project="..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
   </ImportGroup>
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
     <PropertyGroup>
@@ -215,5 +216,6 @@
     <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
     <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props'))" />
     <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets'))" />
+    <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
   </Target>
 </Project>
\ No newline at end of file

mercurial