Skip to content

Commit bdb68e1

Browse files
committed
some progress in adding hamburger menu
1 parent 339fee9 commit bdb68e1

17 files changed

+923
-11
lines changed

App.xaml.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "pch.h"
77
#include "DirectXPage.xaml.h"
8-
#include "AppShell.xaml.h"
98

109
using namespace VBA10;
1110

BasicPage.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Page
2+
x:Class="VBA10.Views.BasicPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:NavigationMenuSample.Views"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
11+
EntranceNavigationTransitionInfo.IsTargetElement="True">
12+
13+
<TextBlock Style="{ThemeResource TitleTextBlockStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Text="Your App Content"/>
14+
15+
</Grid>
16+
</Page>

BasicPage.xaml.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// BasicPage.xaml.cpp
3+
// Implementation of the BasicPage class
4+
//
5+
6+
#include "pch.h"
7+
#include "BasicPage.xaml.h"
8+
9+
using namespace VBA10::Views;
10+
11+
using namespace Platform;
12+
using namespace Windows::Foundation;
13+
using namespace Windows::Foundation::Collections;
14+
using namespace Windows::UI::Xaml;
15+
using namespace Windows::UI::Xaml::Controls;
16+
using namespace Windows::UI::Xaml::Controls::Primitives;
17+
using namespace Windows::UI::Xaml::Data;
18+
using namespace Windows::UI::Xaml::Input;
19+
using namespace Windows::UI::Xaml::Media;
20+
using namespace Windows::UI::Xaml::Navigation;
21+
22+
BasicPage::BasicPage()
23+
{
24+
InitializeComponent();
25+
}

BasicPage.xaml.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// BasicPage.xaml.h
3+
// Declaration of the BasicPage class
4+
//
5+
6+
#pragma once
7+
8+
#include "BasicPage.g.h"
9+
10+
namespace VBA10
11+
{
12+
namespace Views
13+
{
14+
/// <summary>
15+
/// An empty page that can be used on its own or navigated to within a Frame.
16+
/// </summary>
17+
[Windows::Foundation::Metadata::WebHostHidden]
18+
public ref class BasicPage sealed
19+
{
20+
public:
21+
BasicPage();
22+
};
23+
}
24+
}

DirectXPage.xaml

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,118 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:VBA10"
6+
xmlns:controls="using:VBA10.Controls"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
89
mc:Ignorable="d">
910

10-
11+
<Page.Resources>
12+
<DataTemplate x:Key="NavMenuItemTemplate" x:DataType="local:NavMenuItem">
13+
<Grid>
14+
<Grid.ColumnDefinitions>
15+
<ColumnDefinition Width="48" />
16+
<ColumnDefinition />
17+
</Grid.ColumnDefinitions>
18+
<!-- Showing a ToolTip and the Label is redundant. We put the ToolTip on the icon.
19+
It appears when the user hovers over the icon, but not the label which provides
20+
value when the SplitView is 'Compact' while reducing the likelihood of showing
21+
redundant information when the label is shown.-->
22+
<FontIcon x:Name="Glyph" FontSize="16" Glyph="{x:Bind SymbolAsChar}"
23+
VerticalAlignment="Center" HorizontalAlignment="Center"
24+
ToolTipService.ToolTip="{x:Bind Label}"
25+
Foreground="White"/>
26+
<TextBlock x:Name="Text" Grid.Column="1" Text="{x:Bind Label}"
27+
Foreground="White"/>
28+
</Grid>
29+
</DataTemplate>
30+
</Page.Resources>
31+
32+
1133
<SwapChainPanel x:Name="swapChainPanel">
34+
35+
<!-- Adaptive triggers -->
36+
<VisualStateManager.VisualStateGroups>
37+
<VisualStateGroup>
38+
<VisualState>
39+
<VisualState.StateTriggers>
40+
<AdaptiveTrigger MinWindowWidth="720" />
41+
</VisualState.StateTriggers>
42+
<VisualState.Setters>
43+
<!--<Setter Target="RootSplitView.DisplayMode" Value="CompactInline"/>
44+
<Setter Target="RootSplitView.IsPaneOpen" Value="True"/>-->
45+
<Setter Target="RootSplitView.OpenPaneLength" Value="256"/>
46+
</VisualState.Setters>
47+
</VisualState>
48+
<VisualState>
49+
<VisualState.StateTriggers>
50+
<AdaptiveTrigger MinWindowWidth="0" />
51+
</VisualState.StateTriggers>
52+
<VisualState.Setters>
53+
<!--<Setter Target="RootSplitView.DisplayMode" Value="Overlay"/>-->
54+
<Setter Target="RootSplitView.OpenPaneLength" Value="150"/>
55+
</VisualState.Setters>
56+
</VisualState>
57+
</VisualStateGroup>
58+
</VisualStateManager.VisualStateGroups>
59+
60+
<!-- Top-level navigation menu + app content -->
61+
<SplitView x:Name="RootSplitView"
62+
DisplayMode="Inline"
63+
OpenPaneLength="100"
64+
IsTabStop="False"
65+
>
66+
<SplitView.Pane>
67+
<RelativePanel Background="#FF4D3A89">
68+
<!-- A custom ListView to display the items in the pane. The automation Name is set in the ContainerContentChanging event. -->
69+
<controls:NavMenuListView x:Name="NavMenuList"
70+
TabIndex="3"
71+
Margin="0,48,0,0"
72+
ContainerContentChanging="NavMenuItemContainerContentChanging"
73+
ItemContainerStyle="{StaticResource NavMenuItemContainerStyle}"
74+
ItemTemplate="{StaticResource NavMenuItemTemplate}"
75+
ItemInvoked="NavMenuList_ItemInvoked">
76+
<!--<controls:NavMenuListView.Header>
77+
--><!-- Using this custom back navigation button until the system-provided back button is enabled. --><!--
78+
<Button x:Name="BackButton"
79+
TabIndex="2"
80+
Style="{StaticResource NavigationBackButtonStyle}"
81+
IsEnabled="{x:Bind AppFrame.CanGoBack, Mode=OneWay}"
82+
HorizontalAlignment="{Binding ItemsPanelRoot.HorizontalAlignment, ElementName=NavMenuList}"
83+
Click="BackButton_Click"/>
84+
</controls:NavMenuListView.Header>-->
85+
</controls:NavMenuListView>
86+
</RelativePanel>
87+
88+
</SplitView.Pane>
89+
90+
<!-- OnNavigatingToPage we synchronize the selected item in the nav menu with the current page.
91+
OnNavigatedToPage we move keyboard focus to the first item on the page after it's loaded. -->
92+
<Frame x:Name="frame">
93+
<!--Navigating="OnNavigatingToPage"
94+
Navigated="OnNavigatedToPage"-->
95+
96+
<Frame.ContentTransitions>
97+
<TransitionCollection>
98+
<NavigationThemeTransition>
99+
<NavigationThemeTransition.DefaultNavigationTransitionInfo>
100+
<EntranceNavigationTransitionInfo/>
101+
</NavigationThemeTransition.DefaultNavigationTransitionInfo>
102+
</NavigationThemeTransition>
103+
</TransitionCollection>
104+
</Frame.ContentTransitions>
105+
</Frame>
106+
</SplitView>
107+
108+
<!-- Declared last to have it rendered above everything else, but it needs to be the first item in the tab sequence. -->
109+
<ToggleButton x:Name="TogglePaneButton"
110+
TabIndex="1"
111+
Style="{StaticResource SplitViewTogglePaneButtonStyle}"
112+
IsChecked="{Binding IsPaneOpen, ElementName=RootSplitView, Mode=TwoWay}"
113+
Unchecked="TogglePaneButton_Checked"
114+
AutomationProperties.Name="Menu"
115+
ToolTipService.ToolTip="Menu"
116+
/>
117+
12118
</SwapChainPanel>
13119

14120
<Page.BottomAppBar>

DirectXPage.xaml.cpp

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
#include "EmulatorFileHandler.h"
1010
#include "SelectROMPane.xaml.h"
1111

12+
#include "NavMenuItem.h"
13+
#include "NavMenuListView.h"
14+
#include "BasicPage.xaml.h"
15+
16+
1217
using namespace std;
1318
using namespace VBA10;
19+
using namespace VBA10::Controls;
1420

1521
using namespace Platform;
1622
using namespace Windows::Foundation;
@@ -37,6 +43,13 @@ using namespace Windows::UI::ViewManagement;
3743

3844
extern bool enableTurboMode;
3945

46+
DirectXPage^ DirectXPage::_current;
47+
48+
Frame^ DirectXPage::AppFrame::get()
49+
{
50+
return frame;
51+
}
52+
4053
DirectXPage::DirectXPage():
4154
m_windowVisible(true),
4255
m_coreInput(nullptr)
@@ -107,6 +120,14 @@ DirectXPage::DirectXPage():
107120
//// Run task on a dedicated high priority background thread.
108121
//m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced);
109122

123+
// Declare the top level nav items
124+
navlist = ref new Vector<NavMenuItem^>();
125+
navlist->Append(
126+
ref new NavMenuItem(
127+
"Basic Page",
128+
Symbol::Contact,
129+
TypeName(Views::BasicPage::typeid)));
130+
NavMenuList->ItemsSource = navlist;
110131
//load settings
111132
auto settings = ApplicationData::Current->LocalSettings->Values;
112133

@@ -276,6 +297,8 @@ void DirectXPage::OnSwapChainPanelSizeChanged(Object^ sender, SizeChangedEventAr
276297

277298

278299

300+
301+
279302
void DirectXPage::StartROM_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
280303
{
281304
////pause emulator
@@ -326,7 +349,76 @@ void DirectXPage::StartROM_Click(Platform::Object^ sender, Windows::UI::Xaml::Ro
326349
selectRomPopup->SetValue(Canvas::TopProperty, 100);
327350
selectRomPopup->IsOpen = true;
328351
this->loadingDialogOpen = true;
352+
}
353+
354+
355+
356+
357+
/// <summary>
358+
/// Navigate to the Page for the selected <paramref name="listViewItem"/>.
359+
/// </summary>
360+
/// <param name="sender"></param>
361+
/// <param name="listViewItem"></param>
362+
void DirectXPage::NavMenuList_ItemInvoked(Object^ sender, ListViewItem^ listViewItem)
363+
{
364+
auto item = (NavMenuItem^)((NavMenuListView^)(sender))->ItemFromContainer(listViewItem);
365+
366+
if (item != nullptr)
367+
{
368+
if (item->DestPage.Name != AppFrame->CurrentSourcePageType.Name)
369+
{
370+
AppFrame->Navigate(item->DestPage, item->Arguments);
371+
}
372+
}
373+
}
329374

375+
/// <summary>
376+
/// Callback when the SplitView's Pane is toggled open or close. When the Pane is not visible
377+
/// then the floating hamburger may be occluding other content in the app unless it is aware.
378+
/// </summary>
379+
/// <param name="sender"></param>
380+
/// <param name="e"></param>
381+
void DirectXPage::TogglePaneButton_Checked(Object^ sender, RoutedEventArgs^ e)
382+
{
383+
CheckTogglePaneButtonSizeChanged();
384+
}
385+
386+
/// <summary>
387+
/// Check for the conditions where the navigation pane does not occupy the space under the floating
388+
/// hamburger button and trigger the event.
389+
/// </summary>
390+
void DirectXPage::CheckTogglePaneButtonSizeChanged()
391+
{
392+
if (RootSplitView->DisplayMode == SplitViewDisplayMode::Inline ||
393+
RootSplitView->DisplayMode == SplitViewDisplayMode::Overlay)
394+
{
395+
auto transform = TogglePaneButton->TransformToVisual(this);
396+
auto rect = transform->TransformBounds(Rect(0, 0, (float)TogglePaneButton->ActualWidth, (float)TogglePaneButton->ActualHeight));
397+
_togglePaneButtonRect = rect;
398+
}
399+
else
400+
{
401+
_togglePaneButtonRect = Rect();
402+
}
330403

331-
404+
TogglePaneButtonRectChanged(this, TogglePaneButtonRect);
332405
}
406+
407+
/// <summary>
408+
/// Enable accessibility on each nav menu item by setting the AutomationProperties.Name on each container
409+
/// using the associated Label of each item.
410+
/// </summary>
411+
/// <param name="sender"></param>
412+
/// <param name="args"></param>
413+
void DirectXPage::NavMenuItemContainerContentChanging(ListViewBase^ sender, ContainerContentChangingEventArgs^ args)
414+
{
415+
if (!args->InRecycleQueue && args->Item != nullptr && dynamic_cast<NavMenuItem^>(args->Item) != nullptr)
416+
{
417+
args->ItemContainer->SetValue(Windows::UI::Xaml::Automation::AutomationProperties::NameProperty, ((NavMenuItem^)args->Item)->Label);
418+
}
419+
else
420+
{
421+
args->ItemContainer->ClearValue(Windows::UI::Xaml::Automation::AutomationProperties::NameProperty);
422+
}
423+
}
424+

DirectXPage.xaml.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "Common\DeviceResources.h"
1111
#include "VBA10Main.h"
1212

13+
#include "NavMenuItem.h"
14+
#include "NavMenuListView.h"
15+
1316

1417
using namespace Platform;
1518
using namespace Platform::Collections;
@@ -34,6 +37,33 @@ namespace VBA10
3437
void SaveInternalState(Windows::Foundation::Collections::IPropertySet^ state);
3538
void LoadInternalState(Windows::Foundation::Collections::IPropertySet^ state);
3639

40+
//from AppShell
41+
property Windows::UI::Xaml::Controls::Frame^ AppFrame
42+
{
43+
Windows::UI::Xaml::Controls::Frame^ get();
44+
}
45+
46+
//from AppShell
47+
internal:
48+
/// <summary>
49+
/// An event to notify listeners when the hamburger button may occlude other content in the app.
50+
/// The custom "PageHeader" user control is using this.
51+
/// </summary>
52+
event TypedEventHandler<DirectXPage^, Rect>^ TogglePaneButtonRectChanged;
53+
property Rect TogglePaneButtonRect
54+
{
55+
Rect get() { return _togglePaneButtonRect; }
56+
private:
57+
void set(Rect value) { _togglePaneButtonRect = value; }
58+
}
59+
60+
static property DirectXPage^ Current
61+
{
62+
DirectXPage^ get()
63+
{
64+
return _current;
65+
}
66+
}
3767

3868

3969
private:
@@ -78,6 +108,17 @@ namespace VBA10
78108
bool m_windowVisible;
79109
void AppBarButton_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
80110
void StartROM_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
111+
112+
//from AppShell
113+
void NavMenuList_ItemInvoked(Object^ sender, ListViewItem^ e);
114+
void TogglePaneButton_Checked(Object^ sender, RoutedEventArgs^ e);
115+
void CheckTogglePaneButtonSizeChanged();
116+
void NavMenuItemContainerContentChanging(ListViewBase^ sender, ContainerContentChangingEventArgs^ args);
117+
118+
Vector<NavMenuItem^>^ navlist;
119+
Rect _togglePaneButtonRect;
120+
121+
static DirectXPage^ _current;
81122
};
82123
}
83124

0 commit comments

Comments
 (0)