ui/winui/container.cpp

branch
newapi
changeset 198
f2332d0d3318
parent 195
0f2e69873875
child 199
84e0a24bab4a
--- a/ui/winui/container.cpp	Mon Oct 02 19:56:18 2023 +0200
+++ b/ui/winui/container.cpp	Tue Oct 03 12:36:57 2023 +0200
@@ -305,19 +305,19 @@
 	// 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;
-	}
+		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);
@@ -414,6 +414,106 @@
 	return widget;
 }
 
+// --------------------- UI TabView ---------------------
+
+UiTabViewContainer::UiTabViewContainer(UiTabView* tabview) {
+	this->tabview = tabview;
+}
+
+void UiTabViewContainer::Add(FrameworkElement control, UiBool fill) {
+	// noop
+}
+
+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;
+	}
+	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;
+	}
+	}
+
+	UIElement elm = subcontainer;
+	UiWidget* widget = new UiWidget(elm);
+	UiObject* newobj = uic_object_new(current, widget);
+	newobj->container = ctn;
+	return newobj;
+}
+
+UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) {
+	this->current = obj;
+	this->pivot = pivot;
+	this->margin = args.margin;
+	this->spacing = args.spacing;
+	this->columnspacing = args.columnspacing;
+	this->rowspacing = args.rowspacing;
+}
+
+UiObject* UiPivotTabView::AddTab(const char* label) {
+	TextBlock text = TextBlock();
+	wchar_t* wlabel = str2wstr(label, nullptr);
+	winrt::hstring hstr(wlabel);
+	text.Text(hstr);
+	free(wlabel);
+
+	PivotItem item = PivotItem();
+	item.Header(text);
+
+	// sub container
+	Grid subcontainer = Grid();
+	item.Content(subcontainer);
+	pivot.Items().Append(item);
+
+	return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
+}
+
+FrameworkElement UiPivotTabView::GetFrameworkElement() {
+	return pivot;
+}
+
+static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) {
+	Pivot pivot = Pivot();
+	UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args);
+
+	return tabview;
+}
+
+UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
+	UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview;
+	UiTabView *tabview = tabview_pivot_create(obj, args);
+	UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
+
+	// add frame to the parent container
+	UiObject* current = uic_current_obj(obj);
+	UI_APPLY_LAYOUT1(current, args);
+	current->container->Add(tabview->GetFrameworkElement(), true);
+
+	UIElement elm = tabview->GetFrameworkElement();
+	UiWidget* widget = new UiWidget(elm);
+	widget->data1 = tabview;
+
+	UiObject* newobj = uic_object_new(obj, widget);
+	newobj->container = ctn;
+	uic_obj_add(obj, newobj);
+
+	return widget;
+}
+
+void ui_tab_create(UiObject* obj, const char* title) {
+	UiObject* current = uic_current_obj(obj);
+	UiTabView* tabview = (UiTabView*)current->widget->data1;
+	UiObject* newobj = tabview->AddTab(title);
+	uic_obj_add(current, newobj);
+}
 
 /*
  * -------------------- Layout Functions --------------------

mercurial