finish navigationview (WinUI3) newapi

Tue, 03 Oct 2023 21:10:15 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 03 Oct 2023 21:10:15 +0200
branch
newapi
changeset 202
9f309d1914a2
parent 201
7f67ebbb0c1c
child 203
0e94be3d9722

finish navigationview (WinUI3)

make/vs/testapp/main.c file | annotate | diff | comparison | revisions
ui/winui/container.cpp file | annotate | diff | comparison | revisions
ui/winui/container.h file | annotate | diff | comparison | revisions
--- a/make/vs/testapp/main.c	Tue Oct 03 16:30:42 2023 +0200
+++ b/make/vs/testapp/main.c	Tue Oct 03 21:10:15 2023 +0200
@@ -136,25 +136,22 @@
             ui_passwordfield(obj, .value = wdata->password);
             ui_newline(obj);
 
-            /*
             ui_frame(obj, .label = "Test", .colspan = 3) {
                 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
             }
             ui_newline(obj);
-            */
-
-            /*
+            
             ui_expander(obj, .label = "Expand", .colspan = 3, .margin = 10, .spacing = 5, .isexpanded = false) {
                 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
                 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
                 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
             }
-            */
+            ui_newline(obj);
 
             ui_combobox(obj, .list = wdata->list, .onselection= action_listselection_changed, .onactivate= action_onactivate);
             ui_newline(obj);
 
-            ui_tabview(obj, .colspan = 3, .vexpand = true, .hexpand = true) {
+            ui_tabview(obj, .colspan = 3, .vexpand = true, .hexpand = true, .tabview = UI_TABVIEW_NAVIGATION_TOP2) {
                 ui_tab(obj, "Tab 1") {
                     ui_button(obj, .label = "Tab 1 Button");
                 }
--- a/ui/winui/container.cpp	Tue Oct 03 16:30:42 2023 +0200
+++ b/ui/winui/container.cpp	Tue Oct 03 21:10:15 2023 +0200
@@ -530,7 +530,7 @@
 	return uitabview;
 }
 
-UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView NavigationView, UiTabViewArgs args, enum UiNavigationViewType type) {
+UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) {
 	this->current = obj;
 	this->navigationview = navigationview;
 	this->type = type;
@@ -538,6 +538,12 @@
 	this->spacing = args.spacing;
 	this->columnspacing = args.columnspacing;
 	this->rowspacing = args.rowspacing;
+
+	if (type == UI_TABVIEW_NAVIGATION_TOP) {
+		navigationview.PaneDisplayMode(NavigationViewPaneDisplayMode::Top);
+	}
+
+	navigationview.SelectionChanged({ this, &UiNavigationTabView::SelectionChanged });
 }
 
 UiObject* UiNavigationTabView::AddTab(const char* label) {
@@ -552,12 +558,14 @@
 
 	// sub container
 	Grid subcontainer = Grid();
-	//item.Content(subcontainer);
-	navigationview.MenuItems().Append(item);
+	if (pages.size() == 0) {
+		navigationview.Content(subcontainer);
+		navigationview.SelectedItem(item);
+	}
 
-	Button b1 = Button();
-	b1.Content(box_value(L"Test"));
-	navigationview.Content(b1);
+	navigationview.MenuItems().Append(item);
+	auto page = std::tuple<NavigationViewItem, FrameworkElement>{ item, subcontainer };
+	pages.push_back(page);
 
 	return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
 }
@@ -566,16 +574,51 @@
 	return navigationview;
 }
 
-static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args) {
+void UiNavigationTabView::SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args) {
+	for (auto page : pages) {
+		NavigationViewItem item = std::get<0>(page);
+		FrameworkElement elm = std::get<1>(page);
+		if (item == navigationview.SelectedItem()) {
+			navigationview.Content(elm);
+			break;
+		}
+	}
+}
+
+static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) {
 	NavigationView navigationview = NavigationView();
-	UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, UI_NAVIGATIONVIEW_SIDE);
+	UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type);
+	navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed);
+	navigationview.IsSettingsVisible(false);
 
 	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_navigationview_create(obj, args);
+	UiTabView* tabview = nullptr;
+	switch (type) {
+		default: {
+			tabview = tabview_pivot_create(obj, args);
+			break;
+		}
+		case UI_TABVIEW_DOC: { 
+			tabview = tabview_main_create(obj, args);
+			break;
+		}
+		case UI_TABVIEW_NAVIGATION_SIDE: { 
+			tabview = tabview_navigationview_create(obj, args, type);
+			break;
+		}
+		case UI_TABVIEW_NAVIGATION_TOP: { 
+			tabview = tabview_navigationview_create(obj, args, type);
+			break;
+		}
+		case UI_TABVIEW_NAVIGATION_TOP2: { 
+			tabview = tabview_pivot_create(obj, args);
+			break;
+		}
+	}
 	UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
 
 	// add frame to the parent container
--- a/ui/winui/container.h	Tue Oct 03 16:30:42 2023 +0200
+++ b/ui/winui/container.h	Tue Oct 03 21:10:15 2023 +0200
@@ -153,10 +153,13 @@
 
 struct UiNavigationTabView : UiTabView {
     NavigationView navigationview;
-    UiNavigationViewType type;
+    UiTabViewType type;
+    std::vector<std::tuple<NavigationViewItem, FrameworkElement> > pages;
 
-    UiNavigationTabView(UiObject* obj, NavigationView NavigationView, UiTabViewArgs args, enum UiNavigationViewType type);
+    UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type);
 
     UiObject* AddTab(const char* label);
     FrameworkElement GetFrameworkElement();
+
+    void SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args);
 };

mercurial