GraphControl: refactoring and optimizations (#831)
* GraphControl cleaning * replace textbox value after submission * rebase * rebase * rebase * Add filters * rebase! * rebase
This commit is contained in:
@@ -11,7 +11,6 @@ using namespace Platform;
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::Controls;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::ApplicationModel;
|
||||
|
@@ -32,11 +32,19 @@ void EquationStylePanelControl::SelectionChanged(Object ^ /*sender */, Selection
|
||||
{
|
||||
if (e->AddedItems->Size > 0)
|
||||
{
|
||||
SelectedColor = static_cast<SolidColorBrush ^>(e->AddedItems->GetAt(0));
|
||||
auto brush = dynamic_cast<SolidColorBrush ^>(e->AddedItems->GetAt(0));
|
||||
if (brush == nullptr)
|
||||
{
|
||||
SelectedColor = Colors::Black;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedColor = brush->Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EquationStylePanelControl::OnSelectedColorPropertyChanged(SolidColorBrush ^ /*oldColor*/, SolidColorBrush ^ newColor)
|
||||
void EquationStylePanelControl::OnSelectedColorPropertyChanged(Color /*oldColor*/, Color newColor)
|
||||
{
|
||||
SelectColor(newColor);
|
||||
}
|
||||
@@ -46,13 +54,8 @@ void EquationStylePanelControl::ColorChooserLoaded(Object ^ sender, RoutedEventA
|
||||
SelectColor(SelectedColor);
|
||||
}
|
||||
|
||||
void EquationStylePanelControl::SelectColor(SolidColorBrush ^ selectedColor)
|
||||
void EquationStylePanelControl::SelectColor(Color selectedColor)
|
||||
{
|
||||
if (selectedColor == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto item : ColorChooser->Items->GetView())
|
||||
{
|
||||
auto brush = static_cast<SolidColorBrush ^>(item);
|
||||
@@ -63,7 +66,7 @@ void EquationStylePanelControl::SelectColor(SolidColorBrush ^ selectedColor)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (brush->Color == selectedColor->Color)
|
||||
if (Utils::AreColorsEqual(brush->Color, selectedColor))
|
||||
{
|
||||
gridViewItem->IsSelected = true;
|
||||
return;
|
||||
|
@@ -14,13 +14,15 @@ namespace CalculatorApp
|
||||
EquationStylePanelControl();
|
||||
DEPENDENCY_PROPERTY_OWNER(EquationStylePanelControl);
|
||||
|
||||
DEPENDENCY_PROPERTY_WITH_CALLBACK(Windows::UI::Xaml::Media::SolidColorBrush ^, SelectedColor);
|
||||
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, SelectedColor, Windows::UI::Colors::Black);
|
||||
DEPENDENCY_PROPERTY_WITH_DEFAULT(Windows::Foundation::Collections::IVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors, nullptr);
|
||||
|
||||
private:
|
||||
void SelectionChanged(Platform::Object ^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^ e);
|
||||
void OnSelectedColorPropertyChanged(Windows::UI::Xaml::Media::SolidColorBrush ^ oldValue, Windows::UI::Xaml::Media::SolidColorBrush ^ newValue);
|
||||
void ColorChooserLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SelectColor(Windows::UI::Xaml::Media::SolidColorBrush ^ selectedColor);
|
||||
void OnSelectedColorPropertyChanged(Windows::UI::Color oldColor, Windows::UI::Color newColor);
|
||||
void ColorChooserLoaded(
|
||||
Platform::Object ^ sender,
|
||||
Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SelectColor(Windows::UI::Color selectedColor);
|
||||
};
|
||||
}
|
||||
|
@@ -235,7 +235,7 @@
|
||||
DataContextChanged="InputTextBox_DataContextChanged"
|
||||
EquationButtonClicked="EquationTextBox_EquationButtonClicked"
|
||||
EquationButtonContentIndex="{x:Bind FunctionLabelIndex, Mode=OneWay}"
|
||||
EquationColor="{x:Bind LineColor, Mode=OneWay}"
|
||||
EquationColor="{x:Bind local:EquationInputArea.ToSolidColorBrush(LineColor), Mode=OneWay}"
|
||||
EquationSubmitted="InputTextBox_Submitted"
|
||||
GotFocus="InputTextBox_GotFocus"
|
||||
HasError="{x:Bind GraphEquation.HasGraphError, Mode=OneWay}"
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace GraphControl;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace CalculatorApp::Controls;
|
||||
using namespace Platform;
|
||||
@@ -61,19 +62,14 @@ void EquationInputArea::OnEquationsPropertyChanged()
|
||||
|
||||
void EquationInputArea::AddNewEquation()
|
||||
{
|
||||
auto eq = ref new EquationViewModel(ref new Equation());
|
||||
eq->IsLastItemInList = true;
|
||||
|
||||
if (Equations->Size > 0)
|
||||
{
|
||||
Equations->GetAt(Equations->Size - 1)->IsLastItemInList = false;
|
||||
}
|
||||
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
|
||||
|
||||
eq->LineColor = AvailableColors->GetAt(m_lastLineColorIndex);
|
||||
eq->IsLineEnabled = true;
|
||||
eq->FunctionLabelIndex = ++m_lastFunctionLabelIndex;
|
||||
auto eq = ref new EquationViewModel(ref new Equation(), ++m_lastFunctionLabelIndex, AvailableColors->GetAt(m_lastLineColorIndex)->Color);
|
||||
eq->IsLastItemInList = true;
|
||||
m_equationToFocus = eq;
|
||||
Equations->Append(eq);
|
||||
}
|
||||
@@ -192,8 +188,7 @@ void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ s
|
||||
}
|
||||
|
||||
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
|
||||
EquationVM = eq;
|
||||
KeyGraphFeaturesRequested(EquationVM, ref new RoutedEventArgs());
|
||||
KeyGraphFeaturesRequested(this, eq);
|
||||
}
|
||||
|
||||
void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||
@@ -210,7 +205,7 @@ void EquationInputArea::InputTextBox_Loaded(Object ^ sender, RoutedEventArgs ^ e
|
||||
auto colorChooser = static_cast<EquationStylePanelControl ^>(tb->ColorChooserFlyout->Content);
|
||||
colorChooser->AvailableColors = AvailableColors;
|
||||
|
||||
if (m_equationToFocus!=nullptr && tb->DataContext == m_equationToFocus)
|
||||
if (m_equationToFocus != nullptr && tb->DataContext == m_equationToFocus)
|
||||
{
|
||||
m_equationToFocus = nullptr;
|
||||
tb->FocusTextBox();
|
||||
@@ -227,9 +222,7 @@ void EquationInputArea::InputTextBox_Loaded(Object ^ sender, RoutedEventArgs ^ e
|
||||
}
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_DataContextChanged(
|
||||
Windows::UI::Xaml::FrameworkElement ^ sender,
|
||||
Windows::UI::Xaml::DataContextChangedEventArgs ^ args)
|
||||
void EquationInputArea::InputTextBox_DataContextChanged(Windows::UI::Xaml::FrameworkElement ^ sender, Windows::UI::Xaml::DataContextChangedEventArgs ^ args)
|
||||
{
|
||||
auto tb = static_cast<EquationTextBox ^>(sender);
|
||||
if (!tb->IsLoaded)
|
||||
@@ -237,7 +230,7 @@ void EquationInputArea::InputTextBox_DataContextChanged(
|
||||
return;
|
||||
}
|
||||
|
||||
FocusEquationIfNecessary(tb);
|
||||
FocusEquationIfNecessary(tb);
|
||||
}
|
||||
|
||||
void EquationInputArea::FocusEquationIfNecessary(CalculatorApp::Controls::EquationTextBox ^ textBox)
|
||||
@@ -296,18 +289,12 @@ void EquationInputArea::ReloadAvailableColors(bool isHighContrast)
|
||||
return;
|
||||
}
|
||||
|
||||
// Use a blank brush to clear out the color before setting it. This is needed because going
|
||||
// from High Contrast White -> High Contrast Black, the high contrast colors seem to be equivalent,
|
||||
// causing the change to not take place.
|
||||
auto blankBrush = ref new SolidColorBrush();
|
||||
|
||||
// Reassign colors for each equation
|
||||
m_lastLineColorIndex = -1;
|
||||
for (auto equationViewModel : Equations)
|
||||
{
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
|
||||
equationViewModel->LineColor = blankBrush;
|
||||
equationViewModel->LineColor = AvailableColors->GetAt(m_lastLineColorIndex);
|
||||
equationViewModel->LineColor = AvailableColors->GetAt(m_lastLineColorIndex)->Color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,23 +306,35 @@ void EquationInputArea::TextBoxGotFocus(TextBox ^ sender, RoutedEventArgs ^ e)
|
||||
void EquationInputArea::SubmitTextbox(TextBox ^ sender)
|
||||
{
|
||||
auto variableViewModel = static_cast<VariableViewModel ^>(sender->DataContext);
|
||||
|
||||
double val;
|
||||
if (sender->Name == "ValueTextBox")
|
||||
{
|
||||
variableViewModel->SetValue(validateDouble(sender->Text, variableViewModel->Value));
|
||||
val = validateDouble(sender->Text, variableViewModel->Value);
|
||||
variableViewModel->Value = val;
|
||||
}
|
||||
else if (sender->Name == "MinTextBox")
|
||||
{
|
||||
variableViewModel->Min = validateDouble(sender->Text, variableViewModel->Min);
|
||||
val = validateDouble(sender->Text, variableViewModel->Min);
|
||||
variableViewModel->Min = val;
|
||||
}
|
||||
else if (sender->Name == "MaxTextBox")
|
||||
{
|
||||
variableViewModel->Max = validateDouble(sender->Text, variableViewModel->Max);
|
||||
val = validateDouble(sender->Text, variableViewModel->Max);
|
||||
variableViewModel->Max = val;
|
||||
}
|
||||
else if (sender->Name == "StepTextBox")
|
||||
{
|
||||
variableViewModel->Step = validateDouble(sender->Text, variableViewModel->Step);
|
||||
val = validateDouble(sender->Text, variableViewModel->Step);
|
||||
variableViewModel->Step = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
wostringstream oss;
|
||||
oss << std::noshowpoint << val;
|
||||
sender->Text = ref new String(oss.str().c_str());
|
||||
}
|
||||
|
||||
void EquationInputArea::TextBoxLosingFocus(TextBox ^ sender, LosingFocusEventArgs ^)
|
||||
|
@@ -23,13 +23,15 @@ namespace CalculatorApp
|
||||
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
|
||||
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::EquationViewModel ^> ^, Equations);
|
||||
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::VariableViewModel ^> ^, Variables);
|
||||
OBSERVABLE_PROPERTY_RW_ALWAYS_NOTIFY(ViewModel::EquationViewModel ^, EquationVM);
|
||||
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors);
|
||||
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesRequested;
|
||||
event Windows::Foundation::EventHandler<ViewModel::EquationViewModel^>^ KeyGraphFeaturesRequested;
|
||||
|
||||
public:
|
||||
static Windows::UI::Xaml::Visibility ManageEditVariablesButtonVisibility(unsigned int numberOfVariables);
|
||||
|
||||
static Windows::UI::Xaml::Media::SolidColorBrush
|
||||
^ ToSolidColorBrush(Windows::UI::Color color) { return ref new Windows::UI::Xaml::Media::SolidColorBrush(color); }
|
||||
|
||||
private:
|
||||
void OnPropertyChanged(Platform::String^ propertyName);
|
||||
void OnEquationsPropertyChanged();
|
||||
|
@@ -480,7 +480,7 @@
|
||||
Grid.RowSpan="2"
|
||||
Margin="0,4,0,0"
|
||||
KeyGraphFeaturesClosed="OnKeyGraphFeaturesClosed"
|
||||
ViewModel="{x:Bind EquationInputAreaControl.EquationVM, Mode=OneWay}"
|
||||
ViewModel="{x:Bind ViewModel.SelectedEquation, Mode=OneWay}"
|
||||
Visibility="{x:Bind IsKeyGraphFeaturesVisible, Mode=OneWay}"
|
||||
x:Load="{x:Bind IsKeyGraphFeaturesVisible, Mode=OneWay}"/>
|
||||
|
||||
|
@@ -53,8 +53,6 @@ DEPENDENCY_PROPERTY_INITIALIZATION(GraphingCalculator, IsSmallState);
|
||||
|
||||
GraphingCalculator::GraphingCalculator()
|
||||
{
|
||||
Equation::RegisterDependencyProperties();
|
||||
Grapher::RegisterDependencyProperties();
|
||||
InitializeComponent();
|
||||
|
||||
DataTransferManager ^ dataTransferManager = DataTransferManager::GetForCurrentView();
|
||||
@@ -219,7 +217,7 @@ void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataReque
|
||||
continue;
|
||||
}
|
||||
|
||||
auto color = equation->LineColor->Color;
|
||||
auto color = equation->LineColor;
|
||||
hasEquations = true;
|
||||
|
||||
expression = GraphingControl->ConvertToLinear(expression);
|
||||
@@ -380,12 +378,15 @@ void GraphingCalculator::GraphingControl_LosingFocus(UIElement ^ sender, LosingF
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnEquationKeyGraphFeaturesRequested(Object ^ sender, RoutedEventArgs ^ e)
|
||||
void GraphingCalculator::OnEquationKeyGraphFeaturesRequested(Object ^ sender, EquationViewModel ^ equationViewModel)
|
||||
{
|
||||
auto equationViewModel = static_cast<EquationViewModel ^>(sender);
|
||||
GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation);
|
||||
equationViewModel->PopulateKeyGraphFeatures();
|
||||
IsKeyGraphFeaturesVisible = true;
|
||||
ViewModel->SetSelectedEquation(equationViewModel);
|
||||
if (equationViewModel != nullptr)
|
||||
{
|
||||
auto keyGraphFeatureInfo = GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation);
|
||||
equationViewModel->PopulateKeyGraphFeatures(keyGraphFeatureInfo);
|
||||
IsKeyGraphFeaturesVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnKeyGraphFeaturesClosed(Object ^ sender, RoutedEventArgs ^ e)
|
||||
|
@@ -24,7 +24,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
||||
COMMAND_FOR_METHOD(ZoomOutButtonPressed, GraphingCalculator::OnZoomOutCommand);
|
||||
COMMAND_FOR_METHOD(ZoomInButtonPressed, GraphingCalculator::OnZoomInCommand);
|
||||
COMMAND_FOR_METHOD(ZoomResetButtonPressed, GraphingCalculator::OnZoomResetCommand);
|
||||
OBSERVABLE_PROPERTY_RW(bool, IsKeyGraphFeaturesVisible);
|
||||
OBSERVABLE_PROPERTY_R(bool, IsKeyGraphFeaturesVisible);
|
||||
DEPENDENCY_PROPERTY(bool, IsSmallState);
|
||||
|
||||
property CalculatorApp::ViewModel::GraphingCalculatorViewModel^ ViewModel
|
||||
@@ -64,7 +64,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
||||
void GraphingControl_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void GraphingControl_LosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
|
||||
void GraphingControl_VariablesUpdated(Platform::Object ^ sender, Object ^ args);
|
||||
void OnEquationKeyGraphFeaturesRequested(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnEquationKeyGraphFeaturesRequested(Platform::Object ^ sender, CalculatorApp::ViewModel::EquationViewModel ^ e);
|
||||
void OnKeyGraphFeaturesClosed(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SwitchModeToggleButton_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void TraceValuePopup_SizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
|
||||
|
@@ -67,7 +67,7 @@
|
||||
<Button.Resources>
|
||||
<SolidColorBrush x:Name="ButtonBackgroundPointerOver"
|
||||
Opacity="0.7"
|
||||
Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EquationColor.Color}"/>
|
||||
Color="{TemplateBinding EquationColor}"/>
|
||||
<SolidColorBrush x:Name="ButtonForegroundPointerOver" Color="{ThemeResource SystemChromeWhiteColor}"/>
|
||||
<SolidColorBrush x:Name="ButtonBorderBrushPointerOver" Color="Transparent"/>
|
||||
</Button.Resources>
|
||||
@@ -330,8 +330,11 @@
|
||||
DataContext="{x:Bind ViewModel, Mode=OneWay}"
|
||||
EquationButtonClicked="EquationButtonClicked"
|
||||
EquationButtonContentIndex="{x:Bind ViewModel.FunctionLabelIndex, Mode=OneWay}"
|
||||
EquationColor="{x:Bind ViewModel.LineColor, Mode=OneWay}"
|
||||
Loaded="EquationInputTextBox_Loaded"/>
|
||||
Loaded="EquationInputTextBox_Loaded">
|
||||
<controls:EquationTextBox.EquationColor>
|
||||
<SolidColorBrush Color="{x:Bind ViewModel.LineColor, Mode=OneWay}"/>
|
||||
</controls:EquationTextBox.EquationColor>
|
||||
</controls:EquationTextBox>
|
||||
<TextBlock x:Uid="KeyGraphFeaturesLabel"
|
||||
Grid.Row="1"
|
||||
Margin="12,20,10,0"
|
||||
|
@@ -18,19 +18,6 @@ KeyGraphFeaturesPanel::KeyGraphFeaturesPanel()
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
void KeyGraphFeaturesPanel::OnPropertyChanged(String ^ propertyName)
|
||||
{
|
||||
if (propertyName == L"ViewModel")
|
||||
{
|
||||
if (ViewModel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetEquationTextBoxProperties();
|
||||
}
|
||||
}
|
||||
|
||||
void KeyGraphFeaturesPanel::EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
KeyGraphFeaturesClosed(this, ref new RoutedEventArgs());
|
||||
|
@@ -17,15 +17,34 @@ public
|
||||
public:
|
||||
KeyGraphFeaturesPanel();
|
||||
|
||||
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
|
||||
OBSERVABLE_PROPERTY_RW_ALWAYS_NOTIFY(CalculatorApp::ViewModel::EquationViewModel ^, ViewModel);
|
||||
OBSERVABLE_OBJECT();
|
||||
|
||||
public:
|
||||
property CalculatorApp::ViewModel::EquationViewModel ^ ViewModel
|
||||
{
|
||||
CalculatorApp::ViewModel::EquationViewModel ^ get()
|
||||
{
|
||||
return m_viewModel;
|
||||
}
|
||||
void set(CalculatorApp::ViewModel::EquationViewModel ^ value)
|
||||
{
|
||||
m_viewModel = value;
|
||||
RaisePropertyChanged(L"EquationViewModel");
|
||||
if (value != nullptr)
|
||||
{
|
||||
SetEquationTextBoxProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesClosed;
|
||||
|
||||
private:
|
||||
|
||||
void OnPropertyChanged(Platform::String ^ propertyName);
|
||||
void EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SetEquationTextBoxProperties();
|
||||
void EquationInputTextBox_Loaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
|
||||
private:
|
||||
CalculatorApp::ViewModel::EquationViewModel ^ m_viewModel;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user