add unfinished navigationview (WinUI3) newapi

Tue, 03 Oct 2023 15:32:46 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 03 Oct 2023 15:32:46 +0200
branch
newapi
changeset 200
f40dadf3498f
parent 199
84e0a24bab4a
child 201
7f67ebbb0c1c

add unfinished navigationview (WinUI3)

ui/winui/container.cpp file | annotate | diff | comparison | revisions
ui/winui/container.h file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- a/ui/winui/container.cpp	Tue Oct 03 14:18:25 2023 +0200
+++ b/ui/winui/container.cpp	Tue Oct 03 15:32:46 2023 +0200
@@ -520,7 +520,7 @@
 	return tabview;
 }
 
-static UiTabView* tabview_doc_create(UiObject* obj, UiTabViewArgs args) {
+static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) {
 	TabView tabview = TabView();
 	tabview.IsAddTabButtonVisible(false);
 	tabview.CanDragTabs(false);
@@ -530,9 +530,52 @@
 	return uitabview;
 }
 
+UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView NavigationView, UiTabViewArgs args, enum UiNavigationViewType 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;
+}
+
+UiObject* UiNavigationTabView::AddTab(const char* label) {
+	TextBlock text = TextBlock();
+	wchar_t* wlabel = str2wstr(label, nullptr);
+	winrt::hstring hstr(wlabel);
+	text.Text(hstr);
+	free(wlabel);
+
+	NavigationViewItem item = NavigationViewItem();
+	item.Content(text);
+
+	// sub container
+	Grid subcontainer = Grid();
+	//item.Content(subcontainer);
+	navigationview.MenuItems().Append(item);
+
+	Button b1 = Button();
+	b1.Content(box_value(L"Test"));
+	navigationview.Content(b1);
+
+	return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
+}
+
+FrameworkElement UiNavigationTabView::GetFrameworkElement() {
+	return navigationview;
+}
+
+static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args) {
+	NavigationView navigationview = NavigationView();
+	UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, UI_NAVIGATIONVIEW_SIDE);
+
+	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_doc_create(obj, args);
+	UiTabView *tabview = tabview_navigationview_create(obj, args);
 	UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
 
 	// add frame to the parent container
--- a/ui/winui/container.h	Tue Oct 03 14:18:25 2023 +0200
+++ b/ui/winui/container.h	Tue Oct 03 15:32:46 2023 +0200
@@ -85,6 +85,11 @@
     UI_BOX_CONTAINER_HBOX
 };
 
+enum UiNavigationViewType {
+    UI_NAVIGATIONVIEW_TOP = 0,
+    UI_NAVIGATIONVIEW_SIDE
+};
+
 struct UiBoxContainer : UiContainer {
     Grid grid;
     enum UiBoxContainerType type;
@@ -145,3 +150,13 @@
     UiObject* AddTab(const char* label);
     FrameworkElement GetFrameworkElement();
 };
+
+struct UiNavigationTabView : UiTabView {
+    NavigationView navigationview;
+    UiNavigationViewType type;
+
+    UiNavigationTabView(UiObject* obj, NavigationView NavigationView, UiTabViewArgs args, enum UiNavigationViewType type);
+
+    UiObject* AddTab(const char* label);
+    FrameworkElement GetFrameworkElement();
+};
--- a/ui/winui/window.cpp	Tue Oct 03 14:18:25 2023 +0200
+++ b/ui/winui/window.cpp	Tue Oct 03 15:32:46 2023 +0200
@@ -36,6 +36,7 @@
 #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
 #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
 #include <winrt/Microsoft.UI.Xaml.Markup.h>
+#include <winrt/Microsoft.UI.Xaml.Media.h>
 
 #include "appmenu.h"
 #include "container.h"
@@ -72,6 +73,10 @@
 		free(wtitle);
 	}
 
+	auto backdrop = winrt::Microsoft::UI::Xaml::Media::MicaBackdrop();
+	backdrop.Kind(winrt::Microsoft::UI::Composition::SystemBackdrops::MicaKind::Base); // alternative: BaseAlt
+	// TODO: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/system-backdrop-controller#example-use-mica-in-a-windows-appsdkwinui-3-app
+
 	Grid grid = Grid();
 	window.Content(grid);
 

mercurial