ui/winui/container.cpp

branch
newapi
changeset 195
0f2e69873875
parent 194
e2281ace0769
child 198
f2332d0d3318
--- a/ui/winui/container.cpp	Mon Oct 02 09:22:52 2023 +0200
+++ b/ui/winui/container.cpp	Mon Oct 02 10:10:09 2023 +0200
@@ -72,11 +72,11 @@
 }
 
 UIWIDGET ui_vbox_create(UiObject* obj, UiContainerArgs args) {
-	return ui_box(obj, args, UI_CONTAINER_VBOX);
+	return ui_box(obj, args, UI_BOX_CONTAINER_VBOX);
 }
 
 UIWIDGET ui_hbox_create(UiObject* obj, UiContainerArgs args) {
-	return ui_box(obj, args, UI_CONTAINER_HBOX);
+	return ui_box(obj, args, UI_BOX_CONTAINER_HBOX);
 }
 
 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) {
@@ -94,7 +94,7 @@
 
 	// hbox needs one row def, vbox needs one col def
 	// all other col/row defs are created when elements are added
-	if (type == UI_CONTAINER_HBOX) {
+	if (type == UI_BOX_CONTAINER_HBOX) {
 		boxRowDef = RowDefinition();
 		boxRowDef.Height(gl);
 		grid.RowDefinitions().Append(boxRowDef);
@@ -302,8 +302,72 @@
 	UIElement elm = frame;
 	UiWidget* widget = new UiWidget(elm);
 
+	// sub container
+	UiContainer* ctn = nullptr;
+	switch (args.subcontainer) {
+	default:
+	case UI_CONTAINER_VBOX: {
+		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);
+		break;
+	}
+	case UI_CONTAINER_GRID: {
+		ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing);
+		break;
+	}
+	}
+
 	UiObject* newobj = uic_object_new(obj, widget);
-	newobj->container = new UiBoxContainer(workarea, UI_CONTAINER_VBOX, 0, 0);
+	newobj->container = ctn;
+	uic_obj_add(obj, newobj);
+
+	return widget;
+}
+
+// --------------------- UI Expander ---------------------
+
+UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args) {
+	Expander expander = Expander();
+	if (args.label) {
+		wchar_t* wlabel = str2wstr(args.label, nullptr);
+		expander.Header(box_value(wlabel));
+		free(wlabel);
+	}
+	expander.IsExpanded(args.isexpanded);
+
+	// add frame to the parent container
+	UiObject* current = uic_current_obj(obj);
+	UI_APPLY_LAYOUT1(current, args);
+	current->container->Add(expander, true);
+
+	UIElement elm = expander;
+	UiWidget* widget = new UiWidget(elm);
+
+	Grid content = Grid();
+	expander.Content(content);
+
+	UiContainer* ctn = nullptr;
+	switch (args.subcontainer) {
+		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;
+		}
+	}
+
+	UiObject* newobj = uic_object_new(obj, widget);
+	newobj->container = ctn;
 	uic_obj_add(obj, newobj);
 
 	return widget;
@@ -311,7 +375,7 @@
 
 // --------------------- UI ScrolledWindow ---------------------
 
-UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args) {
+UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
 	ScrollViewer scrollW = ScrollViewer();
 
 	// add frame to the parent container
@@ -322,12 +386,29 @@
 	UIElement elm = scrollW;
 	UiWidget* widget = new UiWidget(elm);
 
-	// create a vbox as child container
-	Grid vbox = Grid();
-	scrollW.Content(vbox);
+	// create child container
+	Grid content = Grid();
+	scrollW.Content(content);
+
+	UiContainer* ctn = nullptr;
+	switch (args.subcontainer) {
+	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;
+	}
+	}
 
 	UiObject* newobj = uic_object_new(obj, widget);
-	newobj->container = new UiBoxContainer(vbox, UI_CONTAINER_VBOX, args.margin, args.spacing);
+	newobj->container = ctn;
 	uic_obj_add(obj, newobj);
 
 	return widget;

mercurial