From a33c1a44941753d0968b0dde3e4d9eac51653e6e Mon Sep 17 00:00:00 2001 From: Stephanie Anderl <46726333+sanderl@users.noreply.github.com> Date: Thu, 21 Nov 2019 15:07:45 -0800 Subject: [PATCH] Equation button updates: Enable/Disable on click, button content f1, f2, f3..., visibility icon on hover (#804) * Added enable/disable line functionality * Update EquationTextBox to change the opacity of functions have are not visible. Update the function label for the EquationTextBox to increment the label to show f1, f2, f3, etc * rebase key-graph-features and fix issue where removing an equation box and adding a new one repopulates the previous equation * Added visibility icon for the equation button hover * updated EquationButton to be a toggle button to better handle the LineHidden state and other PR comment fixes. * Updated EquationButton style to use a toggle button and to have placeholder icons for the show/hide states * Updated equation button after pulling the refactor work into the branch. Fixed the Equation Button in KGF UI * Fixed Pepe's bugs * Uncomment temporary.pfx in calculator.vcxproj --- src/CalcViewModel/CalcViewModel.vcxproj | 2 +- .../GraphingCalculator/EquationViewModel.cpp | 1 + .../GraphingCalculator/EquationViewModel.h | 17 ++ src/Calculator/App.xaml | 147 ++++++++++++++++-- src/Calculator/Calculator.vcxproj.filters | 6 + src/Calculator/Controls/EquationTextBox.cpp | 11 +- src/Calculator/Controls/EquationTextBox.h | 3 +- .../GraphingCalculator/EquationInputArea.xaml | 3 + .../EquationInputArea.xaml.cpp | 11 +- .../EquationInputArea.xaml.h | 3 +- .../KeyGraphFeaturesPanel.xaml | 45 +++--- .../KeyGraphFeaturesPanel.xaml.cpp | 3 - .../KeyGraphFeaturesPanel.xaml.h | 1 - src/GraphControl/Control/Equation.cpp | 19 ++- src/GraphControl/Control/Equation.h | 24 +++ src/GraphControl/Control/EquationCollection.h | 7 +- src/GraphControl/Control/Grapher.cpp | 48 +++--- src/GraphControl/Control/Grapher.h | 3 +- src/MockGraphingImpl/MockGraphingImpl.vcxproj | 2 +- 19 files changed, 288 insertions(+), 68 deletions(-) diff --git a/src/CalcViewModel/CalcViewModel.vcxproj b/src/CalcViewModel/CalcViewModel.vcxproj index e1cc190..e7b661d 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj +++ b/src/CalcViewModel/CalcViewModel.vcxproj @@ -448,4 +448,4 @@ - \ No newline at end of file + diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp index f52302f..b2eca55 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp @@ -34,6 +34,7 @@ namespace CalculatorApp::ViewModel EquationViewModel::EquationViewModel(GraphControl::Equation ^ equation) : m_AnalysisErrorVisible{ false } + , m_FunctionLabelIndex{ 0 } , m_KeyGraphFeaturesItems{ ref new Vector() } , m_resourceLoader{ Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView() } { diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h index 82c3144..cf435e6 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h @@ -40,6 +40,7 @@ public OBSERVABLE_OBJECT(); OBSERVABLE_PROPERTY_R(GraphControl::Equation ^, GraphEquation); + OBSERVABLE_PROPERTY_RW(int, FunctionLabelIndex); property Platform::String ^ Expression { @@ -73,6 +74,22 @@ public } } + property bool IsLineEnabled + { + bool get() + { + return GraphEquation->IsLineEnabled; + } + void set(bool value) + { + if (GraphEquation->IsLineEnabled != value) + { + GraphEquation->IsLineEnabled = value; + RaisePropertyChanged("IsLineEnabled"); + } + } + } + // Key Graph Features OBSERVABLE_PROPERTY_R(Platform::String ^, AnalysisErrorString); OBSERVABLE_PROPERTY_R(bool, AnalysisErrorVisible); diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 1d38b5f..7120ab1 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="using:CalculatorApp.Controls" xmlns:common="using:CalculatorApp.Common" - xmlns:converters="using:CalculatorApp.Converters" xmlns:local="using:CalculatorApp"> @@ -15,6 +14,8 @@ 0,0,0,0 0 + 0.3 + 0.5 #FF000000 #FF2B2B2B @@ -51,6 +52,13 @@ + + + @@ -75,6 +83,8 @@ 0 #FFF2F2F2 #FFE0E0E0 + 0.2 + 0.4 @@ -108,6 +118,11 @@ + + + @@ -130,6 +145,8 @@ 0,1,0,0 2 + 1.0 + 1.0 @@ -152,7 +169,9 @@ - + + + @@ -1477,6 +1496,7 @@ + @@ -1496,19 +1516,116 @@ - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Calculator/Controls/EquationTextBox.cpp b/src/Calculator/Controls/EquationTextBox.cpp index d4b70f6..b066175 100644 --- a/src/Calculator/Controls/EquationTextBox.cpp +++ b/src/Calculator/Controls/EquationTextBox.cpp @@ -21,10 +21,12 @@ using namespace Windows::UI::Xaml::Controls::Primitives; DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationColor); DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, ColorChooserFlyout); +DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationButtonContentIndex); + void EquationTextBox::OnApplyTemplate() { - m_equationButton = dynamic_cast + + SetEquationText(ViewModel->Expression); - EquationInputTextBox->EquationColor = ViewModel->LineColor; } diff --git a/src/Calculator/Views/GraphingCalculator/KeyGraphFeaturesPanel.xaml.h b/src/Calculator/Views/GraphingCalculator/KeyGraphFeaturesPanel.xaml.h index daf15ba..e0d4af0 100644 --- a/src/Calculator/Views/GraphingCalculator/KeyGraphFeaturesPanel.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/KeyGraphFeaturesPanel.xaml.h @@ -18,7 +18,6 @@ public OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_PROPERTY_RW_ALWAYS_NOTIFY(CalculatorApp::ViewModel::EquationViewModel ^, ViewModel); - event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesClosed; private: diff --git a/src/GraphControl/Control/Equation.cpp b/src/GraphControl/Control/Equation.cpp index fc3af48..74e72b2 100644 --- a/src/GraphControl/Control/Equation.cpp +++ b/src/GraphControl/Control/Equation.cpp @@ -23,7 +23,10 @@ namespace GraphControl DependencyProperty ^ Equation::s_lineColorProperty; static constexpr auto s_propertyName_LineColor = L"LineColor"; - DependencyProperty ^ Equation::s_xInterceptProperty; + DependencyProperty ^ Equation::s_isLineEnabledProperty; + static constexpr auto s_propertyName_IsLineEnabled = L"IsLineEnabled"; + + DependencyProperty ^ Equation::s_xInterceptProperty; static constexpr auto s_propertyName_XIntercept = L"XIntercept"; DependencyProperty ^ Equation::s_yInterceptProperty; @@ -75,6 +78,7 @@ namespace GraphControl { String ^ Expression = StringReference(s_propertyName_Expression); String ^ LineColor = StringReference(s_propertyName_LineColor); + String ^ IsLineEnabled = StringReference(s_propertyName_IsLineEnabled); String ^ XIntercept = StringReference(s_propertyName_XIntercept); String ^ YIntercept = StringReference(s_propertyName_YIntercept); String ^ Parity = StringReference(s_propertyName_Parity); @@ -116,6 +120,15 @@ namespace GraphControl ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged))); } + if (!s_isLineEnabledProperty) + { + s_isLineEnabledProperty = DependencyProperty::Register( + EquationProperties::IsLineEnabled, + bool ::typeid, + Equation::typeid, + ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged))); + } + if (!s_xInterceptProperty) { s_xInterceptProperty = DependencyProperty::Register( @@ -273,6 +286,10 @@ namespace GraphControl { propertyName = EquationProperties::LineColor; } + else if (args->Property == s_isLineEnabledProperty) + { + propertyName = EquationProperties::IsLineEnabled; + } else if (args->Property == s_xInterceptProperty) { propertyName = EquationProperties::XIntercept; diff --git a/src/GraphControl/Control/Equation.h b/src/GraphControl/Control/Equation.h index 7eeee60..39b04e4 100644 --- a/src/GraphControl/Control/Equation.h +++ b/src/GraphControl/Control/Equation.h @@ -9,6 +9,7 @@ namespace GraphControl { extern Platform::String ^ Expression; extern Platform::String ^ LineColor; + extern Platform::String ^ IsLineEnabled; } ref class Equation; @@ -68,6 +69,28 @@ namespace GraphControl } #pragma endregion +#pragma region bool IsLineEnabled DependencyProperty + static property Windows::UI::Xaml::DependencyProperty ^ IsLineEnabledProperty + { + Windows::UI::Xaml::DependencyProperty ^ get() + { + return s_isLineEnabledProperty; + } + } + property bool IsLineEnabled + { + bool get() + { + return static_cast(GetValue(s_isLineEnabledProperty)); + } + void set(bool value) + { + SetValue(s_isLineEnabledProperty, value); + } + } + +#pragma endregion + #pragma region Key Graph Features @@ -422,6 +445,7 @@ namespace GraphControl private: static Windows::UI::Xaml::DependencyProperty ^ s_expressionProperty; static Windows::UI::Xaml::DependencyProperty ^ s_lineColorProperty; + static Windows::UI::Xaml::DependencyProperty ^ s_isLineEnabledProperty; static Windows::UI::Xaml::DependencyProperty ^ s_xInterceptProperty; static Windows::UI::Xaml::DependencyProperty ^ s_yInterceptProperty; static Windows::UI::Xaml::DependencyProperty ^ s_parityProperty; diff --git a/src/GraphControl/Control/EquationCollection.h b/src/GraphControl/Control/EquationCollection.h index 3001b08..5fac827 100644 --- a/src/GraphControl/Control/EquationCollection.h +++ b/src/GraphControl/Control/EquationCollection.h @@ -148,6 +148,7 @@ public event EquationChangedEventHandler ^ EquationChanged; event EquationChangedEventHandler ^ EquationStyleChanged; + event EquationChangedEventHandler ^ EquationLineEnabledChanged; private: void OnEquationPropertyChanged(GraphControl::Equation ^, Platform::String ^ propertyName) @@ -160,8 +161,12 @@ public { EquationChanged(); } + else if (propertyName == EquationProperties::IsLineEnabled) + { + EquationLineEnabledChanged(); + } } - + private: Platform::Collections::Vector ^ m_vector; std::vector m_tokens; diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index c93ce2d..105b840 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -79,6 +79,8 @@ namespace GraphControl auto cw = CoreWindow::GetForCurrentThread(); cw->KeyDown += ref new TypedEventHandler(this, &Grapher::OnCoreKeyDown); cw->KeyUp += ref new TypedEventHandler(this, &Grapher::OnCoreKeyUp); + + auto& formatOptions = m_solver->FormatOptions(); } void Grapher::OnLoaded(Object ^ sender, RoutedEventArgs ^ args) @@ -222,6 +224,9 @@ namespace GraphControl m_tokenEquationChanged = newer->EquationChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationChanged); m_tokenEquationStyleChanged = newer->EquationStyleChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationStyleChanged); + + m_tokenEquationLineEnabledChanged = newer->EquationLineEnabledChanged += + ref new EquationChangedEventHandler(this, &Grapher::OnEquationLineEnabledChanged); } UpdateGraph(); @@ -245,6 +250,11 @@ namespace GraphControl } } + void Grapher::OnEquationLineEnabledChanged() + { + UpdateGraph(); + } + void Grapher::PlotGraph() { UpdateGraph(); @@ -258,7 +268,9 @@ namespace GraphControl { if (analyzer->CanFunctionAnalysisBePerformed()) { - if (S_OK == analyzer->PerformFunctionAnalysis((Graphing::Analyzer::NativeAnalysisType)Graphing::Analyzer::PerformAnalysisType::PerformAnalysisType_All)) + if (S_OK + == analyzer->PerformFunctionAnalysis( + (Graphing::Analyzer::NativeAnalysisType)Graphing::Analyzer::PerformAnalysisType::PerformAnalysisType_All)) { Graphing::IGraphFunctionAnalysisData functionAnalysisData = m_solver->Analyze(analyzer.get()); { @@ -297,6 +309,8 @@ namespace GraphControl void Grapher::UpdateGraph() { + optional>> initResult = nullopt; + if (m_renderMain && m_graph != nullptr) { auto validEqs = GetValidEquations(); @@ -323,28 +337,22 @@ namespace GraphControl unique_ptr graphExpression; if (graphExpression = m_solver->ParseInput(request)) { - if (m_graph->TryInitialize(graphExpression.get())) - { - UpdateGraphOptions(m_graph->GetOptions(), validEqs); - SetGraphArgs(); - - m_renderMain->Graph = m_graph; - - UpdateVariables(); - } + initResult = m_graph->TryInitialize(graphExpression.get()); } } - else + + if (initResult == nullopt) { - if (m_graph->TryInitialize()) - { - UpdateGraphOptions(m_graph->GetOptions(), validEqs); - SetGraphArgs(); + initResult = m_graph->TryInitialize(); + } - m_renderMain->Graph = m_graph; + if (initResult != nullopt) + { + UpdateGraphOptions(m_graph->GetOptions(), validEqs); + SetGraphArgs(); - UpdateVariables(); - } + UpdateVariables(); + m_renderMain->Graph = m_graph; } } } @@ -385,7 +393,7 @@ namespace GraphControl IObservableVector ^ Grapher::ConvertWStringVector(vector inVector) { Vector ^ outVector = ref new Vector(); - + for (auto v : inVector) { outVector->Append(ref new String(v.c_str())); @@ -482,7 +490,7 @@ namespace GraphControl for (Equation ^ eq : Equations) { - if (!eq->Expression->IsEmpty()) + if (!eq->Expression->IsEmpty() && eq->IsLineEnabled) { validEqs.push_back(eq); } diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h index 9f82bdd..c16c0ac 100644 --- a/src/GraphControl/Control/Grapher.h +++ b/src/GraphControl/Control/Grapher.h @@ -173,7 +173,7 @@ public void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args); void OnEquationChanged(); void OnEquationStyleChanged(); - + void OnEquationLineEnabledChanged(); void UpdateGraph(); void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector& validEqs); std::vector GetValidEquations(); @@ -210,6 +210,7 @@ public Windows::Foundation::EventRegistrationToken m_tokenEquationsChanged; Windows::Foundation::EventRegistrationToken m_tokenEquationStyleChanged; Windows::Foundation::EventRegistrationToken m_tokenEquationChanged; + Windows::Foundation::EventRegistrationToken m_tokenEquationLineEnabledChanged; static Windows::UI::Xaml::DependencyProperty ^ s_forceProportionalAxesTemplateProperty; diff --git a/src/MockGraphingImpl/MockGraphingImpl.vcxproj b/src/MockGraphingImpl/MockGraphingImpl.vcxproj index a797e58..7ab41b1 100644 --- a/src/MockGraphingImpl/MockGraphingImpl.vcxproj +++ b/src/MockGraphingImpl/MockGraphingImpl.vcxproj @@ -297,4 +297,4 @@ - \ No newline at end of file +