ui/winui/container.cpp

branch
newapi
changeset 212
ad5c74af14c4
parent 205
b1ac0dd1d38b
child 221
a82d9beaa94a
--- a/ui/winui/container.cpp	Thu Oct 12 13:52:18 2023 +0200
+++ b/ui/winui/container.cpp	Thu Oct 12 14:09:04 2023 +0200
@@ -62,9 +62,11 @@
 
 	UIElement elm = grid;
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 
 	UiObject* newobj = uic_object_new(obj, widget);
 	newobj->container = new UiBoxContainer(grid, type, args.margin, args.spacing);
+	ui_context_add_container_destructor(current->ctx, newobj->container);
 	uic_obj_add(obj, newobj);
 
 	return widget;
@@ -155,9 +157,11 @@
 
 	UIElement elm = grid;
 	UiWidget* widget = new UiWidget(elm);
+	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);
+	ui_context_add_container_destructor(current->ctx, newobj->container);
 	uic_obj_add(obj, newobj);
 
 	return widget;
@@ -300,6 +304,7 @@
 
 	UIElement elm = frame;
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 
 	// sub container
 	UiContainer* ctn = nullptr;
@@ -318,6 +323,7 @@
 			break;
 		}
 	}
+	ui_context_add_container_destructor(current->ctx, ctn);
 
 	UiObject* newobj = uic_object_new(obj, widget);
 	newobj->container = ctn;
@@ -344,6 +350,7 @@
 
 	UIElement elm = expander;
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 
 	Grid content = Grid();
 	expander.Content(content);
@@ -364,6 +371,7 @@
 			break;
 		}
 	}
+	ui_context_add_container_destructor(current->ctx, ctn);
 
 	UiObject* newobj = uic_object_new(obj, widget);
 	newobj->container = ctn;
@@ -384,6 +392,7 @@
 
 	UIElement elm = scrollW;
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 
 	// create child container
 	Grid content = Grid();
@@ -391,20 +400,21 @@
 
 	UiContainer* ctn = nullptr;
 	switch (args.subcontainer) {
-	default:
-	case UI_CONTAINER_VBOX: {
-		ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
-		break;
+		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;
+		}
 	}
-	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;
-	}
-	}
+	ui_context_add_container_destructor(current->ctx, ctn);
 
 	UiObject* newobj = uic_object_new(obj, widget);
 	newobj->container = ctn;
@@ -426,23 +436,25 @@
 static UiObject* create_subcontainer_obj(UiObject* current, Grid subcontainer, UiSubContainerType type, int margin, int spacing, int columnspacing, int rowspacing) {
 	UiContainer* ctn = nullptr;
 	switch (type) {
-	default:
-	case UI_CONTAINER_VBOX: {
-		ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_VBOX, margin, spacing);
-		break;
+		default:
+		case UI_CONTAINER_VBOX: {
+			ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_VBOX, margin, spacing);
+			break;
+		}
+		case UI_CONTAINER_HBOX: {
+			ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_HBOX, margin, spacing);
+			break;
+		}
+		case UI_CONTAINER_GRID: {
+			ctn = new UiGridContainer(subcontainer, margin, columnspacing, rowspacing);
+			break;
+		}
 	}
-	case UI_CONTAINER_HBOX: {
-		ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_HBOX, margin, spacing);
-		break;
-	}
-	case UI_CONTAINER_GRID: {
-		ctn = new UiGridContainer(subcontainer, margin, columnspacing, rowspacing);
-		break;
-	}
-	}
+	ui_context_add_container_destructor(current->ctx, ctn);
 
 	UIElement elm = subcontainer;
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 	UiObject* newobj = uic_object_new(current, widget);
 	newobj->container = ctn;
 	return newobj;
@@ -627,6 +639,7 @@
 
 	UIElement elm = tabview->GetFrameworkElement();
 	UiWidget* widget = new UiWidget(elm);
+	ui_context_add_widget_destructor(current->ctx, widget);
 	widget->data1 = tabview;
 
 	UiObject* newobj = uic_object_new(obj, widget);

mercurial