From 76e6420002aa045940e998977e22ee9029b9a682 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Sun, 1 Mar 2020 18:42:41 +0100 Subject: [PATCH 01/14] Initial commit of compact pane length handling --- dev/NavigationView/NavigationView.cpp | 54 ++++++++++++++++++- dev/NavigationView/NavigationView.h | 1 + dev/NavigationView/NavigationView.xaml | 18 ++++++- dev/NavigationView/NavigationViewItem.cpp | 1 + .../NavigationViewItemPresenter.cpp | 20 ++++++- .../NavigationViewItemPresenter.h | 4 ++ 6 files changed, 93 insertions(+), 5 deletions(-) diff --git a/dev/NavigationView/NavigationView.cpp b/dev/NavigationView/NavigationView.cpp index 515b6b9765..b2ad59f01c 100644 --- a/dev/NavigationView/NavigationView.cpp +++ b/dev/NavigationView/NavigationView.cpp @@ -24,6 +24,7 @@ #include "NavigationViewAutomationPeer.h" #include "StackLayout.h" +// General items static constexpr auto c_togglePaneButtonName = L"TogglePaneButton"sv; static constexpr auto c_paneTitleHolderFrameworkElement = L"PaneTitleHolder"sv; static constexpr auto c_paneTitleFrameworkElement = L"PaneTitleTextBlock"sv; @@ -36,6 +37,7 @@ static constexpr auto c_paneContentGridName = L"PaneContentGrid"sv; static constexpr auto c_rootGridName = L"RootGrid"sv; static constexpr auto c_contentGridName = L"ContentGrid"sv; static constexpr auto c_searchButtonName = L"PaneAutoSuggestButton"sv; +static constexpr auto c_paneToggleButtonGridName = L"PaneToggleButtonGrid"sv; static constexpr auto c_togglePaneTopPadding = L"TogglePaneTopPadding"sv; static constexpr auto c_contentPaneTopPadding = L"ContentPaneTopPadding"sv; static constexpr auto c_contentLeftPadding = L"ContentLeftPadding"sv; @@ -45,6 +47,7 @@ static constexpr auto c_navViewCloseButton = L"NavigationViewCloseButton"sv; static constexpr auto c_navViewCloseButtonToolTip = L"NavigationViewCloseButtonToolTip"sv; static constexpr auto c_paneShadowReceiverCanvas = L"PaneShadowReceiver"sv; +// DisplayMode Top specific items static constexpr auto c_topNavMenuItemsHost = L"TopNavMenuItemsHost"sv; static constexpr auto c_topNavOverflowButton = L"TopNavOverflowButton"sv; static constexpr auto c_topNavMenuItemsOverflowHost = L"TopNavMenuItemsOverflowHost"sv; @@ -54,6 +57,7 @@ static constexpr auto c_leftNavPaneAutoSuggestBoxPresenter = L"PaneAutoSuggestBo static constexpr auto c_topNavPaneAutoSuggestBoxPresenter = L"TopPaneAutoSuggestBoxPresenter"sv; static constexpr auto c_paneTitlePresenter = L"PaneTitlePresenter"sv; +// DisplayMode Left specific items static constexpr auto c_leftNavFooterContentBorder = L"FooterContentBorder"sv; static constexpr auto c_leftNavPaneHeaderContentBorder = L"PaneHeaderContentBorder"sv; static constexpr auto c_leftNavPaneCustomContentBorder = L"PaneCustomContentBorder"sv; @@ -256,6 +260,7 @@ void NavigationView::OnApplyTemplate() m_paneTitleOnTopPane.set(GetTemplateChildT(c_paneTitleOnTopPane, controlProtected)); m_paneCustomContentOnTopPane.set(GetTemplateChildT(c_paneCustomContentOnTopPane, controlProtected)); m_paneFooterOnTopPane.set(GetTemplateChildT(c_paneFooterOnTopPane, controlProtected)); + m_paneToggleButtonGrid.set(GetTemplateChildT(c_paneToggleButtonGridName, controlProtected)); // Get a pointer to the root SplitView if (auto splitView = GetTemplateChildT(c_rootSplitViewName, controlProtected)) @@ -3026,6 +3031,15 @@ void NavigationView::OnPropertyChanged(const winrt::DependencyPropertyChangedEve { // Need to update receiver margins when CompactPaneLength changes UpdatePaneShadow(); + + // Update pane-button-grid width hwne pane is closed and we are not in minimal + if (!IsPaneOpen() && DisplayMode() != winrt::NavigationViewDisplayMode::Minimal) + { + if (auto paneButtonGrid = m_paneToggleButtonGrid.try_as()) + { + paneButtonGrid.Width(CompactPaneLength()); + } + } } else if (property == s_IsTitleBarAutoPaddingEnabledProperty) { @@ -3105,6 +3119,36 @@ void NavigationView::OnIsPaneOpenChanged() } } } + if (isPaneOpen || DisplayMode() == winrt::NavigationViewDisplayMode::Minimal) + { + // Opening pane, so we need to clear the button grid width to prevent clipping + if (auto paneButtonGrid = m_paneToggleButtonGrid.try_as()) + { + paneButtonGrid.Width(NAN); + } + } + else + { + // Closing pane, so we need to set width of button grid so they are centered + if (DisplayMode() != winrt::NavigationViewDisplayMode::Minimal) + { + // Update pane (toggle) button grid's width for button centering + if (auto paneButtonGrid = m_paneToggleButtonGrid.try_as()) + { + paneButtonGrid.Width(CompactPaneLength()); + } + } + } + + if (isPaneOpen) + { + winrt::VisualStateManager::GoToState(*this, L"PaneOpen", false /* usetransition */); + } + else + { + winrt::VisualStateManager::GoToState(*this, L"PaneClosed", false /* usetransition */); + } + SetPaneToggleButtonAutomationName(); UpdatePaneTabFocusNavigation(); UpdateSettingsItemToolTip(); @@ -3155,7 +3199,15 @@ void NavigationView::UpdatePaneDisplayMode() thisAsUIElement8.KeyTipTarget(paneToggleButton); } } - + + //if (DisplayMode() == winrt::NavigationViewDisplayMode::Compact) + //{ + // // Update pane (toggle) button grid's width for button centering + // if (auto paneButtonGrid = m_paneToggleButtonGrid.try_as()) + // { + // paneButtonGrid.Width(CompactPaneLength()); + // } + //} } else { diff --git a/dev/NavigationView/NavigationView.h b/dev/NavigationView/NavigationView.h index 69ea97ad34..db1fe01374 100644 --- a/dev/NavigationView/NavigationView.h +++ b/dev/NavigationView/NavigationView.h @@ -272,6 +272,7 @@ class NavigationView : tracker_ref m_rootSplitView{ this }; tracker_ref m_settingsItem{ this }; tracker_ref m_paneContentGrid{ this }; + tracker_ref m_paneToggleButtonGrid{ this }; tracker_ref m_paneTitleHolderFrameworkElement{ this }; tracker_ref m_paneTitleFrameworkElement{ this }; tracker_ref m_paneSearchButton{ this }; diff --git a/dev/NavigationView/NavigationView.xaml b/dev/NavigationView/NavigationView.xaml index 1659ca3e09..b8ada10b23 100644 --- a/dev/NavigationView/NavigationView.xaml +++ b/dev/NavigationView/NavigationView.xaml @@ -1,4 +1,4 @@ - + + + + + + + + + + + @@ -140,6 +150,7 @@ + - + + + + UpdateCompactPaneLength(splitView.CompactPaneLength()); } } diff --git a/dev/NavigationView/NavigationViewItemPresenter.cpp b/dev/NavigationView/NavigationViewItemPresenter.cpp index 712d6de01f..1dba95a01e 100644 --- a/dev/NavigationView/NavigationViewItemPresenter.cpp +++ b/dev/NavigationView/NavigationViewItemPresenter.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" @@ -7,6 +7,8 @@ #include "NavigationViewItem.h" #include "SharedHelpers.h" +static constexpr auto c_iconBoxColumnDefinitionName = L"IconColumn"sv; + NavigationViewItemPresenter::NavigationViewItemPresenter() { SetDefaultStyleKey(this); @@ -14,12 +16,16 @@ NavigationViewItemPresenter::NavigationViewItemPresenter() void NavigationViewItemPresenter::OnApplyTemplate() { + winrt::IControlProtected controlProtected = *this; + // Retrieve pointers to stable controls m_helper.Init(*this); if (auto navigationViewItem = GetNavigationViewItem()) { navigationViewItem->UpdateVisualStateNoTransition(); } + + m_iconBoxColumnDefinition.set(GetTemplateChildT(c_iconBoxColumnDefinitionName, controlProtected)); } winrt::UIElement NavigationViewItemPresenter::GetSelectionIndicator() @@ -54,4 +60,14 @@ NavigationViewItem* NavigationViewItemPresenter::GetNavigationViewItem() navigationViewItem = winrt::get_self(item); } return navigationViewItem; -} \ No newline at end of file +} + +void NavigationViewItemPresenter::UpdateCompactPaneLength(double compactPaneLength) +{ + if (auto iconGridColumn = m_iconBoxColumnDefinition.try_as()) + { + auto gridLength = iconGridColumn.Width(); + gridLength.Value = compactPaneLength; + iconGridColumn.Width(gridLength); + } +} diff --git a/dev/NavigationView/NavigationViewItemPresenter.h b/dev/NavigationView/NavigationViewItemPresenter.h index bfe422fd75..0a5a00ae3b 100644 --- a/dev/NavigationView/NavigationViewItemPresenter.h +++ b/dev/NavigationView/NavigationViewItemPresenter.h @@ -23,8 +23,12 @@ class NavigationViewItemPresenter: winrt::UIElement GetSelectionIndicator(); + void UpdateCompactPaneLength(double compactPaneLength); + private: NavigationViewItem * GetNavigationViewItem(); + tracker_ref m_iconBoxColumnDefinition{ this }; + NavigationViewItemHelper m_helper{ this }; }; From 9498adfa7713c2d14d01063b5a768548e14ca71e Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Sun, 1 Mar 2020 23:35:12 +0100 Subject: [PATCH 02/14] Add interaction test --- .../NavigationViewTests.cs | 23 ++++ .../TestUI/NavigationViewCaseBundle.xaml | 1 + .../TestUI/NavigationViewCaseBundle.xaml.cs | 1 + ...vigationViewCompactPaneLengthTestPage.xaml | 113 ++++++++++++++++++ ...ationViewCompactPaneLengthTestPage.xaml.cs | 109 +++++++++++++++++ .../TestUI/NavigationView_TestUI.projitems | 7 ++ 6 files changed, 254 insertions(+) create mode 100644 dev/NavigationView/TestUI/NavigationViewCompactPaneLengthTestPage.xaml create mode 100644 dev/NavigationView/TestUI/NavigationViewCompactPaneLengthTestPage.xaml.cs diff --git a/dev/NavigationView/NavigationView_InteractionTests/NavigationViewTests.cs b/dev/NavigationView/NavigationView_InteractionTests/NavigationViewTests.cs index 8de0fafd3d..bf2a6ea1d2 100644 --- a/dev/NavigationView/NavigationView_InteractionTests/NavigationViewTests.cs +++ b/dev/NavigationView/NavigationView_InteractionTests/NavigationViewTests.cs @@ -4179,6 +4179,29 @@ public void VerifyEventsReturnExpectedDataTypesMenuItemsSource() } } + [TestMethod] + [TestProperty("TestSuide","D")] + public void VerifyIconsRespectCompactPaneLength() + { + using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView compact pane length test" })) + { + var checkMenuItemsButton = FindElement.ByName("CheckMenuItemsOffset"); + var compactpaneCheckbox = new ComboBox(FindElement.ByName("CompactPaneLenghtComboBox")); + var currentStatus = new CheckBox(FindElement.ByName("MenuItemsCorrectOffset")); + + checkMenuItemsButton.Click(); + Wait.ForIdle(); + Verify.IsTrue(currentStatus.ToggleState == ToggleState.On); + + compactpaneCheckbox.SelectItemByName("96"); + Wait.ForIdle(); + + checkMenuItemsButton.Click(); + Wait.ForIdle(); + Verify.IsTrue(currentStatus.ToggleState == ToggleState.On); + } + } + private void EnsurePaneHeaderCanBeModifiedHelper(RegressionTestType navviewMode) { if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2)) diff --git a/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml b/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml index fb4a02045d..1a14e2bd52 100644 --- a/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml +++ b/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml @@ -23,6 +23,7 @@ + diff --git a/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml.cs b/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml.cs index 1ada28eb11..c5a9010f49 100644 --- a/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml.cs +++ b/dev/NavigationView/TestUI/NavigationViewCaseBundle.xaml.cs @@ -19,6 +19,7 @@ public NavigationViewCaseBundle() { this.InitializeComponent(); NavigationViewPage.Click += delegate { Frame.NavigateWithoutAnimation(typeof(NavigationViewPage), 0); }; + NavigationViewCompactPaneLengthTestPage.Click += delegate { Frame.NavigateWithoutAnimation(typeof(NavigationViewCompactPaneLengthTestPage), 0); }; NavigationViewRS4Page.Click += delegate { Frame.NavigateWithoutAnimation(typeof(NavigationViewRS4Page), 0); }; NavigationViewPageDataContext.Click += delegate { Frame.NavigateWithoutAnimation(typeof(NavigationViewPageDataContext), 0); }; NavigationViewTopNavPage.Click += delegate { Frame.NavigateWithoutAnimation(typeof(NavigationViewTopNavPage), 0); }; diff --git a/dev/NavigationView/TestUI/NavigationViewCompactPaneLengthTestPage.xaml b/dev/NavigationView/TestUI/NavigationViewCompactPaneLengthTestPage.xaml new file mode 100644 index 0000000000..bf45f4f355 --- /dev/null +++ b/dev/NavigationView/TestUI/NavigationViewCompactPaneLengthTestPage.xaml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +