mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
Add back button
This commit is contained in:
parent
b34756d794
commit
5ce06fb0da
10 changed files with 100 additions and 67 deletions
|
@ -42,7 +42,6 @@ static constexpr int PRESSURE_ID = 14;
|
|||
static constexpr int ANGLE_ID = 15;
|
||||
static constexpr int CURRENCY_ID = 16;
|
||||
static constexpr int GRAPHING_ID = 17;
|
||||
static constexpr int SETTINGS_ID = 18;
|
||||
// ^^^ THESE CONSTANTS SHOULD NEVER CHANGE ^^^
|
||||
|
||||
wchar_t* towchar_t(int number)
|
||||
|
@ -299,16 +298,6 @@ static const list<NavCategoryInitializer> s_categoryManifest = [] {
|
|||
MyVirtualKey::None,
|
||||
nullptr,
|
||||
SUPPORTS_NEGATIVE,
|
||||
true },
|
||||
NavCategoryInitializer{ ViewMode::Settings,
|
||||
SETTINGS_ID,
|
||||
L"Settings",
|
||||
L"CategoryName_Settings",
|
||||
L"\uE713",
|
||||
CategoryGroupType::None,
|
||||
MyVirtualKey::None,
|
||||
nullptr,
|
||||
false,
|
||||
true } });
|
||||
return res;
|
||||
}();
|
||||
|
@ -390,11 +379,6 @@ bool NavCategory::IsConverterViewMode(ViewMode mode)
|
|||
return IsModeInCategoryGroup(mode, CategoryGroupType::Converter);
|
||||
}
|
||||
|
||||
bool NavCategory::IsSettingsViewMode(ViewMode mode)
|
||||
{
|
||||
return mode == ViewMode::Settings;
|
||||
}
|
||||
|
||||
bool NavCategory::IsModeInCategoryGroup(ViewMode mode, CategoryGroupType type)
|
||||
{
|
||||
auto iter = find_if(begin(s_categoryManifest), end(s_categoryManifest), [mode, type](const NavCategoryInitializer& initializer) {
|
||||
|
|
|
@ -45,8 +45,7 @@ namespace CalculatorApp
|
|||
Pressure = 14,
|
||||
Angle = 15,
|
||||
Currency = 16,
|
||||
Graphing = 17,
|
||||
Settings = 18
|
||||
Graphing = 17
|
||||
};
|
||||
|
||||
public
|
||||
|
@ -140,7 +139,6 @@ namespace CalculatorApp
|
|||
static bool IsGraphingCalculatorViewMode(ViewMode mode);
|
||||
static bool IsDateCalculatorViewMode(ViewMode mode);
|
||||
static bool IsConverterViewMode(ViewMode mode);
|
||||
static bool IsSettingsViewMode(ViewMode mode);
|
||||
|
||||
static Platform::String ^ GetFriendlyName(ViewMode mode);
|
||||
static Platform::String ^ GetNameResourceKey(ViewMode mode);
|
||||
|
|
|
@ -4726,4 +4726,12 @@
|
|||
<value>You'll see your changes the next time you start the app.</value>
|
||||
<comment>Notice when the user change the theme.</comment>
|
||||
</data>
|
||||
<data name="BackButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Back</value>
|
||||
<comment>This is the tool tip for the back button </comment>
|
||||
</data>
|
||||
<data name="SettingsHeader.Text" xml:space="preserve">
|
||||
<value>Settings</value>
|
||||
<comment>Text for the "Settings" header</comment>
|
||||
</data>
|
||||
</root>
|
|
@ -1,17 +1,24 @@
|
|||
<UserControl x:Class="CalculatorApp.SettingsPage"
|
||||
<Page x:Class="CalculatorApp.SettingsPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="using:CalculatorApp.Converters"
|
||||
xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:CalculatorApp"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="455"
|
||||
d:DesignWidth="445"
|
||||
Background="{ThemeResource AppChromeAcrylicHostBackdropMediumLowBrush}"
|
||||
d:Height="455"
|
||||
d:Width="445"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="PageGrid"
|
||||
Margin="12,0,12,0"
|
||||
AutomationProperties.LandmarkType="Main">
|
||||
<Page.Resources>
|
||||
<Style x:Key="CategoryNameTextBlockStyle" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="20"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
<Setter Property="OpticalMarginAlignment" Value="TrimSideBearings"/>
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
|
||||
<Grid x:Name="PageGrid" AutomationProperties.LandmarkType="Main">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*"
|
||||
MinHeight="{StaticResource HamburgerHeight}"
|
||||
|
@ -19,7 +26,34 @@
|
|||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<Grid Height="{StaticResource HamburgerHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{StaticResource HamburgerHeightGridLength}"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button x:Name="BackButton"
|
||||
x:Uid="BackButton"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{ThemeResource AppChromeAcrylicHostBackdropMediumLowBrush}"
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="15"
|
||||
Windows10version1809:CornerRadius="0"
|
||||
Click="BackButtonClick"
|
||||
Content=""/>
|
||||
|
||||
<TextBlock x:Uid="SettingsHeader"
|
||||
Grid.Column="1"
|
||||
Margin="8,-3,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Style="{StaticResource CategoryNameTextBlockStyle}"/>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1" Margin="12,0,12,0">
|
||||
<StackPanel x:Name="SettingsStack"
|
||||
AutomationProperties.LabeledBy="{Binding ElementName=SettingsAppTheme}"
|
||||
Orientation="Vertical">
|
||||
|
@ -108,4 +142,4 @@
|
|||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</Page>
|
||||
|
|
|
@ -62,6 +62,20 @@ SettingsPage::SettingsPage()
|
|||
}
|
||||
}
|
||||
|
||||
void SettingsPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e)
|
||||
{
|
||||
MainPage ^ mainPage = (MainPage ^) e->Parameter;
|
||||
if (mainPage != nullptr)
|
||||
{
|
||||
MainPageProperty = mainPage;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsPage::BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
{
|
||||
MainPageProperty->CollapseSettings();
|
||||
}
|
||||
|
||||
void SettingsPage::SetVersionString()
|
||||
{
|
||||
PackageVersion version = Package::Current->Id->Version;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "SettingsPage.g.h"
|
||||
#include "Views/MainPage.xaml.h"
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
|
@ -12,8 +13,13 @@ namespace CalculatorApp
|
|||
{
|
||||
public:
|
||||
SettingsPage();
|
||||
property MainPage ^ MainPageProperty;
|
||||
|
||||
protected:
|
||||
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e) override;
|
||||
|
||||
private:
|
||||
void BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void ColorSettingsButtonClicked(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SettingsFeedbackButtonClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SetVersionString();
|
||||
|
|
|
@ -109,9 +109,6 @@
|
|||
<Border x:Name="ConverterHolder">
|
||||
<!-- PLACEHOLDER!!!! This is where the converter goes when it is delay loaded -->
|
||||
</Border>
|
||||
<Border x:Name="SettingsHolder">
|
||||
<!-- PLACEHOLDER!!!! This is where the settings goes when it is delay loaded -->
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1"
|
||||
|
@ -153,6 +150,10 @@
|
|||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Canvas.ZIndex="0">
|
||||
<Frame x:Name="SettingsHolder" Visibility="Collapsed"/>
|
||||
</Grid>
|
||||
|
||||
<muxc:NavigationView x:Name="NavView"
|
||||
x:Uid="NavView"
|
||||
Grid.Row="1"
|
||||
|
|
|
@ -178,10 +178,6 @@ void MainPage::OnAppPropertyChanged(_In_ Platform::Object ^ sender, _In_ Windows
|
|||
m_converter->AnimateConverter();
|
||||
}
|
||||
}
|
||||
else if (newValue == ViewMode::Settings)
|
||||
{
|
||||
EnsureSettings();
|
||||
}
|
||||
|
||||
ShowHideControls(newValue);
|
||||
|
||||
|
@ -201,7 +197,6 @@ void MainPage::ShowHideControls(ViewMode mode)
|
|||
auto isDateCalcViewMode = NavCategory::IsDateCalculatorViewMode(mode);
|
||||
auto isGraphingCalcViewMode = NavCategory::IsGraphingCalculatorViewMode(mode);
|
||||
auto isConverterViewMode = NavCategory::IsConverterViewMode(mode);
|
||||
auto isSettingsViewMode = NavCategory::IsSettingsViewMode(mode);
|
||||
|
||||
if (m_calculator)
|
||||
{
|
||||
|
@ -227,11 +222,6 @@ void MainPage::ShowHideControls(ViewMode mode)
|
|||
m_converter->IsEnabled = isConverterViewMode;
|
||||
}
|
||||
|
||||
if (m_settings)
|
||||
{
|
||||
m_settings->Visibility = BooleanToVisibilityConverter::Convert(isSettingsViewMode);
|
||||
m_settings->IsEnabled = isSettingsViewMode;
|
||||
}
|
||||
}
|
||||
|
||||
void MainPage::UpdateViewState()
|
||||
|
@ -393,13 +383,10 @@ void MainPage::EnsureConverter()
|
|||
|
||||
void MainPage::EnsureSettings()
|
||||
{
|
||||
if (!m_settings)
|
||||
{
|
||||
m_settings = ref new CalculatorApp::SettingsPage();
|
||||
m_settings->Name = L"SettingsPage";
|
||||
|
||||
SettingsHolder->Child = m_settings;
|
||||
}
|
||||
SettingsHolder->Navigate((SettingsPage::typeid), this);
|
||||
SettingsHolder->Visibility = ::Visibility::Visible;
|
||||
NavView->IsPaneOpen = false;
|
||||
NavView->Visibility = ::Visibility::Collapsed;
|
||||
}
|
||||
|
||||
void MainPage::OnNavLoaded(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
|
||||
|
@ -451,7 +438,13 @@ void MainPage::OnNavPaneClosed(_In_ MUXC::NavigationView ^ sender, _In_ Object ^
|
|||
|
||||
void MainPage::OnSettingsButtonClick(Object ^ sender, ItemClickEventArgs ^ e, ViewMode /*model*/)
|
||||
{
|
||||
Model->Mode = ViewMode::Settings;
|
||||
EnsureSettings();
|
||||
}
|
||||
|
||||
void MainPage::CollapseSettings()
|
||||
{
|
||||
SettingsHolder->Visibility = ::Visibility::Collapsed;
|
||||
NavView->Visibility = ::Visibility::Visible;
|
||||
}
|
||||
|
||||
void MainPage::OnNavSelectionChanged(_In_ Object ^ sender, _In_ MUXC::NavigationViewSelectionChangedEventArgs ^ e)
|
||||
|
|
|
@ -39,6 +39,8 @@ public
|
|||
Platform::Object
|
||||
^> ^ CreateUIElementsForCategories(_In_ Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup ^> ^ categories);
|
||||
|
||||
void CollapseSettings();
|
||||
|
||||
protected:
|
||||
void OnNavigatedTo(_In_ Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e) override;
|
||||
|
||||
|
|
|
@ -123,7 +123,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Data));
|
||||
VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Pressure));
|
||||
VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Angle));
|
||||
VERIFY_IS_TRUE(NavCategory::IsValidViewMode(ViewMode::Settings));
|
||||
}
|
||||
|
||||
void NavCategoryUnitTests::IsValidViewMode_AllInvalid()
|
||||
|
@ -173,7 +172,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Data));
|
||||
VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Pressure));
|
||||
VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Angle));
|
||||
VERIFY_IS_FALSE(NavCategory::IsCalculatorViewMode(ViewMode::Settings));
|
||||
}
|
||||
|
||||
void NavCategoryUnitTests::IsDateCalculatorViewMode()
|
||||
|
@ -201,7 +199,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Data));
|
||||
VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Pressure));
|
||||
VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Angle));
|
||||
VERIFY_IS_FALSE(NavCategory::IsDateCalculatorViewMode(ViewMode::Settings));
|
||||
}
|
||||
|
||||
void NavCategoryUnitTests::IsConverterViewMode()
|
||||
|
@ -228,7 +225,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Data));
|
||||
VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Pressure));
|
||||
VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Angle));
|
||||
VERIFY_IS_TRUE(NavCategory::IsConverterViewMode(ViewMode::Settings));
|
||||
}
|
||||
|
||||
void NavCategoryUnitTests::GetFriendlyName()
|
||||
|
@ -254,7 +250,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_ARE_EQUAL(StringReference(L"Data"), NavCategory::GetFriendlyName(ViewMode::Data));
|
||||
VERIFY_ARE_EQUAL(StringReference(L"Pressure"), NavCategory::GetFriendlyName(ViewMode::Pressure));
|
||||
VERIFY_ARE_EQUAL(StringReference(L"Angle"), NavCategory::GetFriendlyName(ViewMode::Angle));
|
||||
VERIFY_ARE_EQUAL(StringReference(L"Settings"), NavCategory::GetFriendlyName(ViewMode::Settings));
|
||||
|
||||
VERIFY_ARE_EQUAL(StringReference(L"None"), NavCategory::GetFriendlyName(ViewMode::None));
|
||||
}
|
||||
|
@ -283,7 +278,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Data));
|
||||
VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Pressure));
|
||||
VERIFY_ARE_EQUAL(CategoryGroupType::Converter, NavCategory::GetGroupType(ViewMode::Angle));
|
||||
VERIFY_ARE_EQUAL(CategoryGroupType::None, NavCategory::GetGroupType(ViewMode::Settings));
|
||||
}
|
||||
|
||||
void NavCategoryUnitTests::GetIndex()
|
||||
|
@ -296,13 +290,13 @@ namespace CalculatorUnitTests
|
|||
orderedModes = { ViewMode::Standard, ViewMode::Scientific, ViewMode::Graphing, ViewMode::Programmer, ViewMode::Date,
|
||||
ViewMode::Currency, ViewMode::Volume, ViewMode::Length, ViewMode::Weight, ViewMode::Temperature,
|
||||
ViewMode::Energy, ViewMode::Area, ViewMode::Speed, ViewMode::Time, ViewMode::Power,
|
||||
ViewMode::Data, ViewMode::Pressure, ViewMode::Angle, ViewMode::Settings };
|
||||
ViewMode::Data, ViewMode::Pressure, ViewMode::Angle };
|
||||
}
|
||||
else
|
||||
{
|
||||
orderedModes = { ViewMode::Standard, ViewMode::Scientific, ViewMode::Programmer, ViewMode::Date, ViewMode::Currency, ViewMode::Volume,
|
||||
ViewMode::Length, ViewMode::Weight, ViewMode::Temperature, ViewMode::Energy, ViewMode::Area, ViewMode::Speed,
|
||||
ViewMode::Time, ViewMode::Power, ViewMode::Data, ViewMode::Pressure, ViewMode::Angle, ViewMode::Settings };
|
||||
ViewMode::Time, ViewMode::Power, ViewMode::Data, ViewMode::Pressure, ViewMode::Angle };
|
||||
}
|
||||
|
||||
auto orderedModesSize = size(orderedModes);
|
||||
|
@ -325,13 +319,13 @@ namespace CalculatorUnitTests
|
|||
orderedModes = { ViewMode::Standard, ViewMode::Scientific, ViewMode::Graphing, ViewMode::Programmer, ViewMode::Date,
|
||||
ViewMode::Currency, ViewMode::Volume, ViewMode::Length, ViewMode::Weight, ViewMode::Temperature,
|
||||
ViewMode::Energy, ViewMode::Area, ViewMode::Speed, ViewMode::Time, ViewMode::Power,
|
||||
ViewMode::Data, ViewMode::Pressure, ViewMode::Angle, ViewMode::Settings };
|
||||
ViewMode::Data, ViewMode::Pressure, ViewMode::Angle };
|
||||
}
|
||||
else
|
||||
{
|
||||
orderedModes = { ViewMode::Standard, ViewMode::Scientific, ViewMode::Programmer, ViewMode::Date, ViewMode::Currency, ViewMode::Volume,
|
||||
ViewMode::Length, ViewMode::Weight, ViewMode::Temperature, ViewMode::Energy, ViewMode::Area, ViewMode::Speed,
|
||||
ViewMode::Time, ViewMode::Power, ViewMode::Data, ViewMode::Pressure, ViewMode::Angle, ViewMode::Settings };
|
||||
ViewMode::Time, ViewMode::Power, ViewMode::Data, ViewMode::Pressure, ViewMode::Angle };
|
||||
}
|
||||
|
||||
auto orderedModesSize = size(orderedModes);
|
||||
|
@ -381,7 +375,6 @@ namespace CalculatorUnitTests
|
|||
VERIFY_ARE_EQUAL(10, NavCategory::GetIndexInGroup(ViewMode::Data, CategoryGroupType::Converter));
|
||||
VERIFY_ARE_EQUAL(11, NavCategory::GetIndexInGroup(ViewMode::Pressure, CategoryGroupType::Converter));
|
||||
VERIFY_ARE_EQUAL(12, NavCategory::GetIndexInGroup(ViewMode::Angle, CategoryGroupType::Converter));
|
||||
VERIFY_ARE_EQUAL(0, NavCategory::GetIndexInGroup(ViewMode::Settings, CategoryGroupType::None));
|
||||
|
||||
VERIFY_ARE_EQUAL(-1, NavCategory::GetIndexInGroup(ViewMode::None, CategoryGroupType::Calculator));
|
||||
VERIFY_ARE_EQUAL(-1, NavCategory::GetIndexInGroup(ViewMode::None, CategoryGroupType::Converter));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue