add main tabview based on WinUI TabView newapi

Tue, 03 Oct 2023 14:18:25 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 03 Oct 2023 14:18:25 +0200
branch
newapi
changeset 199
84e0a24bab4a
parent 198
f2332d0d3318
child 200
f40dadf3498f

add main tabview based on WinUI TabView

ui/winui/container.cpp file | annotate | diff | comparison | revisions
ui/winui/container.h file | annotate | diff | comparison | revisions
--- a/ui/winui/container.cpp	Tue Oct 03 12:36:57 2023 +0200
+++ b/ui/winui/container.cpp	Tue Oct 03 14:18:25 2023 +0200
@@ -487,9 +487,52 @@
 	return tabview;
 }
 
+UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) {
+	this->current = obj;
+	this->tabview = tabview;
+	this->margin = args.margin;
+	this->spacing = args.spacing;
+	this->columnspacing = args.columnspacing;
+	this->rowspacing = args.rowspacing;
+}
+
+UiObject* UiMainTabView::AddTab(const char* label) {
+	TextBlock text = TextBlock();
+	wchar_t* wlabel = str2wstr(label, nullptr);
+	winrt::hstring hstr(wlabel);
+	text.Text(hstr);
+	free(wlabel);
+
+	TabViewItem item = TabViewItem();
+	item.Header(text);
+	item.CanDrag(false);
+	item.IsClosable(false);
+
+	// sub container
+	Grid subcontainer = Grid();
+	item.Content(subcontainer);
+	tabview.TabItems().Append(item);
+
+	return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
+}
+
+FrameworkElement UiMainTabView::GetFrameworkElement() {
+	return tabview;
+}
+
+static UiTabView* tabview_doc_create(UiObject* obj, UiTabViewArgs args) {
+	TabView tabview = TabView();
+	tabview.IsAddTabButtonVisible(false);
+	tabview.CanDragTabs(false);
+	tabview.CanReorderTabs(false);
+	UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args);
+
+	return uitabview;
+}
+
 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);
+	UiTabView *tabview = tabview_doc_create(obj, args);
 	UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
 
 	// add frame to the parent container
--- a/ui/winui/container.h	Tue Oct 03 12:36:57 2023 +0200
+++ b/ui/winui/container.h	Tue Oct 03 14:18:25 2023 +0200
@@ -109,7 +109,11 @@
 
 struct UiTabView {
     UiObject* current;
-    int close = 0;
+    UiSubContainerType subcontainer;
+    int margin;
+    int spacing;
+    int columnspacing;
+    int rowspacing;
 
     virtual UiObject* AddTab(const char* label) = 0;
 
@@ -126,14 +130,18 @@
 
 struct UiPivotTabView : UiTabView {
     Pivot pivot;
-    UiSubContainerType subcontainer;
-    int margin;
-    int spacing;
-    int columnspacing;
-    int rowspacing;
 
     UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args);
 
     UiObject* AddTab(const char* label);
     FrameworkElement GetFrameworkElement();
 };
+
+struct UiMainTabView : UiTabView {
+    TabView tabview;
+
+    UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args);
+
+    UiObject* AddTab(const char* label);
+    FrameworkElement GetFrameworkElement();
+};

mercurial