more arg refactoring (winui3)

Tue, 10 Jun 2025 12:34:21 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 10 Jun 2025 12:34:21 +0200
changeset 614
a6e70dead6bd
parent 613
dac25dd922a2
child 615
55850ad7702c

more arg refactoring (winui3)

make/vs/testapp/main.c 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/image.cpp file | annotate | diff | comparison | revisions
--- a/make/vs/testapp/main.c	Tue Jun 10 12:28:30 2025 +0200
+++ b/make/vs/testapp/main.c	Tue Jun 10 12:34:21 2025 +0200
@@ -311,7 +311,7 @@
         }
         ui_tab(obj, "Tab 3") {
             UiTabViewArgs args = {0};
-            UI_CTN(obj, tabview=ui_tabview_create(obj, args)) {
+            UI_CTN(obj, tabview=ui_tabview_create(obj, &args)) {
                 UiObject *tab1 = ui_tabview_add(tabview, "Sub 1", -1);
                 ui_button(tab1, .label = "Button 1");
 
--- a/ui/winui/container.cpp	Tue Jun 10 12:28:30 2025 +0200
+++ b/ui/winui/container.cpp	Tue Jun 10 12:34:21 2025 +0200
@@ -162,9 +162,9 @@
 
 // --------------------- UiGridContainer ---------------------
 
-UIWIDGET ui_grid_create(UiObject* obj, UiContainerArgs args) {
+UIWIDGET ui_grid_create(UiObject* obj, UiContainerArgs *args) {
 	UiObject* current = uic_current_obj(obj);
-	UI_APPLY_LAYOUT1(current, args);
+	UI_APPLY_LAYOUT2(current, args);
 
 	Grid grid = Grid();
 	current->container->Add(grid, true);
@@ -174,7 +174,7 @@
 	ui_context_add_widget_destructor(current->ctx, widget);
 
 	UiObject* newobj = uic_object_new(obj, widget);
-	newobj->container = new UiGridContainer(grid, args.margin, args.columnspacing, args.rowspacing);
+	newobj->container = new UiGridContainer(grid, args->margin, args->columnspacing, args->rowspacing);
 	ui_context_add_container_destructor(current->ctx, newobj->container);
 	uic_obj_add(obj, newobj);
 
@@ -304,7 +304,7 @@
 
 // --------------------- UI Frame ---------------------
 
-UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args) {
+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();
 
@@ -321,7 +321,7 @@
 
 	// label
 	int row = 0;
-	if (args.label) {
+	if (args->label) {
 		RowDefinition rowdefLabel = RowDefinition();
 		gl.GridUnitType = GridUnitType::Auto;
 		gl.Value = 0;
@@ -329,7 +329,7 @@
 		frame.RowDefinitions().Append(rowdefLabel);
 
 		TextBlock label = TextBlock();
-		wchar_t* wlabel = str2wstr(args.label, nullptr);
+		wchar_t* wlabel = str2wstr(args->label, nullptr);
 		winrt::hstring hstr(wlabel);
 		label.Text(hstr);
 		free(wlabel);
@@ -360,7 +360,7 @@
 
 	// add frame to the parent container
 	UiObject* current = uic_current_obj(obj);
-	UI_APPLY_LAYOUT1(current, args);
+	UI_APPLY_LAYOUT2(current, args);
 	current->container->Add(frame, true);
 
 	UIElement elm = frame;
@@ -369,18 +369,18 @@
 
 	// sub container
 	UiContainer* ctn = nullptr;
-	switch (args.subcontainer) {
+	switch (args->subcontainer) {
 		default:
 		case UI_CONTAINER_VBOX: {
-			ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
+			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);
+			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);
+			ctn = new UiGridContainer(workarea, args->margin, args->columnspacing, args->rowspacing);
 			break;
 		}
 	}
@@ -395,18 +395,18 @@
 
 // --------------------- UI Expander ---------------------
 
-UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args) {
+UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs *args) {
 	Expander expander = Expander();
-	if (args.label) {
-		wchar_t* wlabel = str2wstr(args.label, nullptr);
+	if (args->label) {
+		wchar_t* wlabel = str2wstr(args->label, nullptr);
 		expander.Header(box_value(wlabel));
 		free(wlabel);
 	}
-	expander.IsExpanded(args.isexpanded);
+	expander.IsExpanded(args->isexpanded);
 
 	// add frame to the parent container
 	UiObject* current = uic_current_obj(obj);
-	UI_APPLY_LAYOUT1(current, args);
+	UI_APPLY_LAYOUT2(current, args);
 	current->container->Add(expander, true);
 
 	UIElement elm = expander;
@@ -417,18 +417,18 @@
 	expander.Content(content);
 
 	UiContainer* ctn = nullptr;
-	switch (args.subcontainer) {
+	switch (args->subcontainer) {
 		default: 
 		case UI_CONTAINER_VBOX: {
-			ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
+			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);
+			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);
+			ctn = new UiGridContainer(content, args->margin, args->columnspacing, args->rowspacing);
 			break;
 		}
 	}
@@ -443,12 +443,12 @@
 
 // --------------------- UI ScrolledWindow ---------------------
 
-UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
+UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs *args) {
 	ScrollViewer scrollW = ScrollViewer();
 
 	// add frame to the parent container
 	UiObject* current = uic_current_obj(obj);
-	UI_APPLY_LAYOUT1(current, args);
+	UI_APPLY_LAYOUT2(current, args);
 	current->container->Add(scrollW, true);
 
 	UIElement elm = scrollW;
@@ -460,18 +460,18 @@
 	scrollW.Content(content);
 
 	UiContainer* ctn = nullptr;
-	switch (args.subcontainer) {
+	switch (args->subcontainer) {
 		default:
 		case UI_CONTAINER_VBOX: {
-			ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
+			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);
+			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);
+			ctn = new UiGridContainer(content, args->margin, args->columnspacing, args->rowspacing);
 			break;
 		}
 	}
@@ -521,21 +521,21 @@
 	return newobj;
 }
 
-static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) {
+static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs *args) {
 	Pivot pivot = Pivot();
 	UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args);
 
 	return tabview;
 }
 
-UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) {
+UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs *args) {
 	this->current = obj;
 	this->pivot = pivot;
-	this->subcontainer = args.subcontainer;
-	this->margin = args.margin;
-	this->spacing = args.spacing;
-	this->columnspacing = args.columnspacing;
-	this->rowspacing = args.rowspacing;
+	this->subcontainer = args->subcontainer;
+	this->margin = args->margin;
+	this->spacing = args->spacing;
+	this->columnspacing = args->columnspacing;
+	this->rowspacing = args->rowspacing;
 }
 
 UiObject* UiPivotTabView::AddTab(const char* label, int index) {
@@ -569,7 +569,7 @@
 }
 
 
-static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) {
+static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs *args) {
 	Grid container = Grid();
 	container.HorizontalAlignment(HorizontalAlignment::Stretch);
 	container.VerticalAlignment(VerticalAlignment::Stretch);
@@ -577,14 +577,14 @@
 	return tabview;
 }
 
-UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) {
+UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs *args) {
 	this->current = obj;
 	this->container = container;
-	this->subcontainer = args.subcontainer;
-	this->margin = args.margin;
-	this->spacing = args.spacing;
-	this->columnspacing = args.columnspacing;
-	this->rowspacing = args.rowspacing;
+	this->subcontainer = args->subcontainer;
+	this->margin = args->margin;
+	this->spacing = args->spacing;
+	this->columnspacing = args->columnspacing;
+	this->rowspacing = args->rowspacing;
 	this->currentIndex = -1;
 
 	GridLength gl;
@@ -639,7 +639,7 @@
 }
 
 
-static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) {
+static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs *args) {
 	TabView tabview = TabView();
 	tabview.IsAddTabButtonVisible(false);
 	//tabview.CanDragTabs(false);
@@ -649,14 +649,14 @@
 	return uitabview;
 }
 
-UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) {
+UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs *args) {
 	this->current = obj;
 	this->tabview = tabview;
-	this->subcontainer = args.subcontainer;
-	this->margin = args.margin;
-	this->spacing = args.spacing;
-	this->columnspacing = args.columnspacing;
-	this->rowspacing = args.rowspacing;
+	this->subcontainer = args->subcontainer;
+	this->margin = args->margin;
+	this->spacing = args->spacing;
+	this->columnspacing = args->columnspacing;
+	this->rowspacing = args->rowspacing;
 }
 
 UiObject* UiMainTabView::AddTab(const char* label, int index) {
@@ -692,7 +692,7 @@
 }
 
 
-static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) {
+static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs *args, UiTabViewType type) {
 	NavigationView navigationview = NavigationView();
 	UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type);
 	navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed);
@@ -701,14 +701,14 @@
 	return tabview;
 }
 
-UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) {
+UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs *args, UiTabViewType type) {
 	this->current = obj;
 	this->navigationview = navigationview;
 	this->type = type;
-	this->margin = args.margin;
-	this->spacing = args.spacing;
-	this->columnspacing = args.columnspacing;
-	this->rowspacing = args.rowspacing;
+	this->margin = args->margin;
+	this->spacing = args->spacing;
+	this->columnspacing = args->columnspacing;
+	this->rowspacing = args->rowspacing;
 
 	if (type == UI_TABVIEW_NAVIGATION_TOP) {
 		navigationview.PaneDisplayMode(NavigationViewPaneDisplayMode::Top);
@@ -774,8 +774,8 @@
 	tabview->Select(value);
 }
 
-UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
-	UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview;
+UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs *args) {
+	UiTabViewType type = args->tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args->tabview;
 	UiTabView* tabview = nullptr;
 	switch (type) {
 		default: {
@@ -807,7 +807,7 @@
 
 	// add frame to the parent container
 	UiObject* current = uic_current_obj(obj);
-	UI_APPLY_LAYOUT1(current, args);
+	UI_APPLY_LAYOUT2(current, args);
 	current->container->Add(tabview->GetFrameworkElement(), true);
 
 	UIElement elm = tabview->GetFrameworkElement();
@@ -818,7 +818,7 @@
 	// TODO: add tabview destructor
 
 	// bind variable
-	UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER);
+	UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
 	if (var) {
 		UiInteger *i = (UiInteger*)var->value;
 		i->obj = tabview;
--- a/ui/winui/container.h	Tue Jun 10 12:28:30 2025 +0200
+++ b/ui/winui/container.h	Tue Jun 10 12:34:21 2025 +0200
@@ -140,7 +140,7 @@
 struct UiPivotTabView : UiTabView {
     Pivot pivot;
 
-    UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args);
+    UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs *args);
 
     UiObject* AddTab(const char* label, int index = -1);
     void Remove(int index);
@@ -151,7 +151,7 @@
 struct UiMainTabView : UiTabView {
     TabView tabview;
 
-    UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args);
+    UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs *args);
 
     UiObject* AddTab(const char* label, int index = -1);
     void Remove(int index);
@@ -164,7 +164,7 @@
     UiTabViewType type;
     std::vector<std::tuple<NavigationViewItem, FrameworkElement> > pages;
 
-    UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type);
+    UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs *args, UiTabViewType type);
 
     UiObject* AddTab(const char* label, int index = -1);
     void Remove(int index);
@@ -179,7 +179,7 @@
     std::vector<FrameworkElement> pages;
     int currentIndex;
 
-    UiInvisibleTabView(UiObject *obj, Grid container, UiTabViewArgs args);
+    UiInvisibleTabView(UiObject *obj, Grid container, UiTabViewArgs *args);
 
     UiObject* AddTab(const char* label, int index = -1);
     void Remove(int index);
--- a/ui/winui/image.cpp	Tue Jun 10 12:28:30 2025 +0200
+++ b/ui/winui/image.cpp	Tue Jun 10 12:34:21 2025 +0200
@@ -122,7 +122,7 @@
     std::wstring uriPath = L"file:///" + wPath;
     Uri uri{ uriPath };
     
-    BitmapImage bitmapImage = BitmapImage();UiImageSource
+    BitmapImage bitmapImage = BitmapImage();
     bitmapImage.UriSource(uri);
     ImageSource src = bitmapImage;
 

mercurial