mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Add more themeing functionality
This commit is contained in:
parent
9f2d3e7949
commit
7195ebe9cf
4 changed files with 33 additions and 38 deletions
|
@ -71,18 +71,31 @@ App::App()
|
||||||
|
|
||||||
this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
|
this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
|
||||||
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||||
|
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
|
||||||
|
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
|
||||||
if (value != nullptr)
|
if (value != nullptr)
|
||||||
{
|
{
|
||||||
String ^ colorS = safe_cast<String ^>(value);
|
String ^ colorSetting = safe_cast<String ^>(value);
|
||||||
// Apply theme choice.
|
// Apply theme choice.
|
||||||
if (colorS == L"Dark")
|
if (colorSetting == L"Dark")
|
||||||
{
|
{
|
||||||
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||||
}
|
}
|
||||||
else if (colorS == L"Light")
|
else if (colorSetting == L"Light")
|
||||||
{
|
{
|
||||||
App::Current->RequestedTheme = ApplicationTheme::Light;
|
App::Current->RequestedTheme = ApplicationTheme::Light;
|
||||||
}
|
}
|
||||||
|
else if (colorSetting == L"System")
|
||||||
|
{
|
||||||
|
if (uiTheme == "#FF000000")
|
||||||
|
{
|
||||||
|
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||||
|
}
|
||||||
|
else if (uiTheme == "#FFFFFFFF")
|
||||||
|
{
|
||||||
|
App::Current->RequestedTheme = ApplicationTheme::Light;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "App.g.h"
|
#include "App.g.h"
|
||||||
#include "WindowFrameService.h"
|
#include "WindowFrameService.h"
|
||||||
|
#include "SettingsPage.g.h"
|
||||||
|
|
||||||
namespace CalculatorApp
|
namespace CalculatorApp
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
MinHeight="{StaticResource HamburgerHeight}"
|
MinHeight="{StaticResource HamburgerHeight}"
|
||||||
MaxHeight="52"/>
|
MaxHeight="52"/>
|
||||||
<RowDefinition Height="4*"/>
|
<RowDefinition Height="4*"/>
|
||||||
<RowDefinition Height="Auto" MinHeight="32"/>
|
<RowDefinition Height="Auto" MaxHeight="32"/>
|
||||||
<RowDefinition Height="4*"/>
|
<RowDefinition Height="4*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
@ -34,16 +34,16 @@
|
||||||
|
|
||||||
<TextBlock x:Name="SettingsRestartApp" Style="{StaticResource BodyTextBlockStyle}"/>
|
<TextBlock x:Name="SettingsRestartApp" Style="{StaticResource BodyTextBlockStyle}"/>
|
||||||
|
|
||||||
<RadioButton x:Name="SettingsLightTheme"
|
|
||||||
x:Uid="SettingsLightTheme"
|
|
||||||
Grid.Row="2"
|
|
||||||
Checked="LightChecked"/>
|
|
||||||
|
|
||||||
<RadioButton x:Name="SettingsDarkTheme"
|
<RadioButton x:Name="SettingsDarkTheme"
|
||||||
x:Uid="SettingsDarkTheme"
|
x:Uid="SettingsDarkTheme"
|
||||||
Grid.Row="3"
|
Grid.Row="2"
|
||||||
Checked="DarkChecked"/>
|
Checked="DarkChecked"/>
|
||||||
|
|
||||||
|
<RadioButton x:Name="SettingsLightTheme"
|
||||||
|
x:Uid="SettingsLightTheme"
|
||||||
|
Grid.Row="3"
|
||||||
|
Checked="LightChecked"/>
|
||||||
|
|
||||||
<RadioButton x:Name="SettingsSystemTheme"
|
<RadioButton x:Name="SettingsSystemTheme"
|
||||||
x:Uid="SettingsSystemTheme"
|
x:Uid="SettingsSystemTheme"
|
||||||
Grid.Row="4"
|
Grid.Row="4"
|
||||||
|
|
|
@ -24,11 +24,11 @@ using namespace Windows::UI::Xaml::Data;
|
||||||
#define BUILD_YEAR 2020
|
#define BUILD_YEAR 2020
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||||
|
|
||||||
SettingsPage::SettingsPage()
|
SettingsPage::SettingsPage()
|
||||||
{
|
{
|
||||||
auto locService = LocalizationService::GetInstance();
|
auto locService = LocalizationService::GetInstance();
|
||||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -42,20 +42,19 @@ SettingsPage::SettingsPage()
|
||||||
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||||
if (value != nullptr)
|
if (value != nullptr)
|
||||||
{
|
{
|
||||||
String ^ colorS = safe_cast<String ^>(value);
|
String ^ colorSetting = safe_cast<String ^>(value);
|
||||||
// Apply theme choice.
|
if (colorSetting == L"Dark")
|
||||||
if (colorS == L"Dark")
|
|
||||||
{
|
{
|
||||||
SettingsDarkTheme->IsChecked = true;
|
SettingsDarkTheme->IsChecked = true;
|
||||||
}
|
}
|
||||||
else if (Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"isSytemTheme"))
|
else if (colorSetting == L"Light")
|
||||||
{
|
|
||||||
SettingsSystemTheme->IsChecked = true;
|
|
||||||
}
|
|
||||||
else if (colorS == L"Light")
|
|
||||||
{
|
{
|
||||||
SettingsLightTheme->IsChecked = true;
|
SettingsLightTheme->IsChecked = true;
|
||||||
}
|
}
|
||||||
|
else if (colorSetting == L"System")
|
||||||
|
{
|
||||||
|
SettingsSystemTheme->IsChecked = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ void SettingsPage::SetVersionString()
|
||||||
|
|
||||||
void SettingsPage::SetCopyrightString()
|
void SettingsPage::SetCopyrightString()
|
||||||
{
|
{
|
||||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
||||||
auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
|
auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
|
||||||
|
|
||||||
SettingsCopyright->Text = copyrightText;
|
SettingsCopyright->Text = copyrightText;
|
||||||
|
@ -91,8 +89,6 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed
|
||||||
|
|
||||||
void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
||||||
|
|
||||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||||
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
||||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
|
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
|
||||||
|
@ -100,8 +96,6 @@ void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::Ro
|
||||||
|
|
||||||
void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
||||||
|
|
||||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||||
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
||||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
|
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
|
||||||
|
@ -109,20 +103,7 @@ void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::Rou
|
||||||
|
|
||||||
void SettingsPage::SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
void SettingsPage::SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
|
||||||
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
|
|
||||||
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
|
|
||||||
|
|
||||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||||
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice"));
|
||||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"isSytemTheme", true);
|
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", L"System");
|
||||||
|
|
||||||
if (uiTheme == Windows::UI::Colors::Black.ToString())
|
|
||||||
{
|
|
||||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
|
|
||||||
}
|
|
||||||
else if (uiTheme == Windows::UI::Colors::White.ToString())
|
|
||||||
{
|
|
||||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue