calculator/src/Calculator/Views/GraphingCalculator/GraphingSettings.xaml.cpp
Pepe Rivera 3a808b5022
Update styling of graph settings textbox and add shadow (#1079)
* Update internal package vers

* fix more bugs

* PR comments

* PR comments

* Undo last PR changes

* Pr comments
2020-04-09 16:58:18 -07:00

102 lines
3.0 KiB
C++

#include "pch.h"
#include "GraphingSettings.xaml.h"
#include "CalcViewModel\Common\AppResourceProvider.cpp"
using namespace std;
using namespace Graphing;
using namespace GraphControl;
using namespace CalculatorApp;
using namespace CalculatorApp::ViewModel;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::System;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
GraphingSettings::GraphingSettings()
: m_ViewModel(ref new GraphingSettingsViewModel())
, m_IsMatchAppTheme(false)
{
InitializeComponent();
}
void GraphingSettings::SetGrapher(Grapher ^ grapher)
{
m_ViewModel->SetGrapher(grapher);
}
Style ^ GraphingSettings::SelectTextBoxStyle(bool incorrectRange, bool error)
{
if (incorrectRange || error)
{
return static_cast<::Style ^>(Application::Current->Resources->Lookup(L"VariableTextErrorBoxStyle"));
}
else
{
return static_cast<::Style ^>(Application::Current->Resources->Lookup(L"ThemedVariableTextBoxStyle"));
}
}
void GraphingSettings::GridSettingsTextBox_PreviewKeyDown(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e)
{
if (e->Key == VirtualKey::Enter)
{
if (!FocusManager::TryMoveFocusAsync(FocusNavigationDirection::Next))
{
FocusManager::TryMoveFocusAsync(FocusNavigationDirection::Previous);
}
e->Handled = true;
}
}
void GraphingSettings::RefreshRanges()
{
ViewModel->InitRanges();
}
void GraphingSettings::ResetViewButton_Clicked(Object ^ sender, RoutedEventArgs ^ e)
{
ViewModel->ResetView();
}
String ^ GraphingSettings::GetLineWidthAutomationName(double width)
{
auto resourceLoader = AppResourceProvider::GetInstance();
if (width == 1.0)
{
return resourceLoader->GetResourceString("SmallLineWidthAutomationName");
}
else if(width == 2.0)
{
return resourceLoader->GetResourceString("MediumLineWidthAutomationName");
}
else if (width == 3.0)
{
return resourceLoader->GetResourceString("LargeLineWidthAutomationName");
}
else
{
return resourceLoader->GetResourceString("ExtraLargeLineWidthAutomationName");
}
}
void GraphingSettings::SetGraphTheme(bool isMatchAppTheme)
{
String ^ propertyName = isMatchAppTheme ? L"IsMatchAppTheme" : L"IsAlwaysLightTheme";
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
localSettings->Values->Insert(L"IsGraphThemeMatchApp", isMatchAppTheme);
GraphThemeSettingChanged(this, isMatchAppTheme);
TraceLogger::GetInstance()->LogGraphSettingsChanged(GraphSettingsType::Theme, propertyName);
}