Select the equation when the EquationTextBox has focus and during analysis (#1067)

* Select equation on focus

* PR comment
This commit is contained in:
Pepe Rivera 2020-03-12 10:12:01 -07:00 committed by GitHub
parent a2794b3705
commit 102782df47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 27 deletions

View File

@ -98,21 +98,28 @@ void EquationInputArea::AddNewEquation()
void EquationInputArea::EquationTextBox_GotFocus(Object ^ sender, RoutedEventArgs ^ e) void EquationInputArea::EquationTextBox_GotFocus(Object ^ sender, RoutedEventArgs ^ e)
{ {
KeyboardShortcutManager::HonorShortcuts(false); KeyboardShortcutManager::HonorShortcuts(false);
auto eq = GetViewModelFromEquationTextBox(sender);
if (eq != nullptr)
{
eq->GraphEquation->IsSelected = true;
}
} }
void EquationInputArea::EquationTextBox_LostFocus(Object ^ sender, RoutedEventArgs ^ e) void EquationInputArea::EquationTextBox_LostFocus(Object ^ sender, RoutedEventArgs ^ e)
{ {
KeyboardShortcutManager::HonorShortcuts(true); KeyboardShortcutManager::HonorShortcuts(true);
auto eq = GetViewModelFromEquationTextBox(sender);
if (eq != nullptr)
{
eq->GraphEquation->IsSelected = false;
}
} }
void EquationInputArea::EquationTextBox_Submitted(Object ^ sender, MathRichEditBoxSubmission ^ submission) void EquationInputArea::EquationTextBox_Submitted(Object ^ sender, MathRichEditBoxSubmission ^ submission)
{ {
auto tb = static_cast<EquationTextBox ^>(sender); auto eq = GetViewModelFromEquationTextBox(sender);
if (tb == nullptr)
{
return;
}
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
if (eq == nullptr) if (eq == nullptr)
{ {
return; return;
@ -176,8 +183,7 @@ void EquationInputArea::FocusEquationTextBox(EquationViewModel ^ equation)
void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e) void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
{ {
auto tb = static_cast<EquationTextBox ^>(sender); auto eq = GetViewModelFromEquationTextBox(sender);
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
unsigned int index; unsigned int index;
if (Equations->IndexOf(eq, &index)) if (Equations->IndexOf(eq, &index))
@ -206,15 +212,12 @@ void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, Rou
void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ sender, RoutedEventArgs ^ e) void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
{ {
auto tb = static_cast<EquationTextBox ^>(sender); KeyGraphFeaturesRequested(this, GetViewModelFromEquationTextBox(sender));
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
KeyGraphFeaturesRequested(this, eq);
} }
void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e) void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
{ {
auto tb = static_cast<EquationTextBox ^>(sender); auto eq = GetViewModelFromEquationTextBox(sender);
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
eq->IsLineEnabled = !eq->IsLineEnabled; eq->IsLineEnabled = !eq->IsLineEnabled;
} }
@ -410,8 +413,21 @@ void EquationInputArea::VariableAreaTapped(Object ^ sender, TappedRoutedEventArg
} }
} }
} }
void EquationInputArea::EquationTextBox_EquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ e) void EquationInputArea::EquationTextBox_EquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ e)
{ {
EquationFormatRequested(sender, e); EquationFormatRequested(sender, e);
} }
EquationViewModel ^ EquationInputArea::GetViewModelFromEquationTextBox(Object ^ sender)
{
auto tb = static_cast<EquationTextBox ^>(sender);
if (tb == nullptr)
{
return nullptr;
}
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
return eq;
}

View File

@ -15,17 +15,18 @@
namespace CalculatorApp namespace CalculatorApp
{ {
public ref class EquationInputArea sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public
{ ref class EquationInputArea sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
public: {
EquationInputArea(); public:
EquationInputArea();
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::EquationViewModel ^> ^, Equations); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::EquationViewModel ^> ^, Equations);
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::VariableViewModel ^> ^, Variables); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<ViewModel::VariableViewModel ^> ^, Variables);
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors);
event Windows::Foundation::EventHandler<ViewModel::EquationViewModel^>^ KeyGraphFeaturesRequested; event Windows::Foundation::EventHandler<ViewModel::EquationViewModel ^> ^ KeyGraphFeaturesRequested;
event Windows::Foundation::EventHandler<CalculatorApp::Controls::MathRichEditBoxFormatRequest^> ^ EquationFormatRequested; event Windows::Foundation::EventHandler<CalculatorApp::Controls::MathRichEditBoxFormatRequest ^> ^ EquationFormatRequested;
public: public:
static Windows::UI::Xaml::Visibility ManageEditVariablesButtonVisibility(unsigned int numberOfVariables); static Windows::UI::Xaml::Visibility ManageEditVariablesButtonVisibility(unsigned int numberOfVariables);
@ -37,20 +38,20 @@ namespace CalculatorApp
^ ToSolidColorBrush(Windows::UI::Color color) { return ref new Windows::UI::Xaml::Media::SolidColorBrush(color); } ^ ToSolidColorBrush(Windows::UI::Color color) { return ref new Windows::UI::Xaml::Media::SolidColorBrush(color); }
private: private:
void OnPropertyChanged(Platform::String^ propertyName); void OnPropertyChanged(Platform::String ^ propertyName);
void OnEquationsPropertyChanged(); void OnEquationsPropertyChanged();
void AddNewEquation(); void AddNewEquation();
void EquationTextBox_GotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void EquationTextBox_GotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_LostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void EquationTextBox_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_Submitted(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxSubmission ^ e); void EquationTextBox_Submitted(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxSubmission ^ e);
void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args); void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);
void ReloadAvailableColors(bool isHighContrast); void ReloadAvailableColors(bool isHighContrast);
void FocusEquationTextBox(ViewModel::EquationViewModel ^ equation); void FocusEquationTextBox(ViewModel::EquationViewModel ^ equation);
void EquationTextBox_RemoveButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void EquationTextBox_RemoveButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_KeyGraphFeaturesButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_KeyGraphFeaturesButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void EquationTextBox_Loaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_Loaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
@ -65,6 +66,8 @@ namespace CalculatorApp
void VariableAreaTapped(Platform::Object ^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void VariableAreaTapped(Platform::Object ^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
void EquationTextBox_EquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e); void EquationTextBox_EquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);
CalculatorApp::ViewModel::EquationViewModel ^ GetViewModelFromEquationTextBox(Platform::Object ^ sender);
Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings; Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings;
int m_lastLineColorIndex; int m_lastLineColorIndex;
int m_lastFunctionLabelIndex; int m_lastFunctionLabelIndex;

View File

@ -420,12 +420,14 @@ void GraphingCalculator::OnEquationKeyGraphFeaturesRequested(Object ^ sender, Eq
auto keyGraphFeatureInfo = GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation); auto keyGraphFeatureInfo = GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation);
equationViewModel->PopulateKeyGraphFeatures(keyGraphFeatureInfo); equationViewModel->PopulateKeyGraphFeatures(keyGraphFeatureInfo);
IsKeyGraphFeaturesVisible = true; IsKeyGraphFeaturesVisible = true;
equationViewModel->GraphEquation->IsSelected = true;
} }
} }
void GraphingCalculator::OnKeyGraphFeaturesClosed(Object ^ sender, RoutedEventArgs ^ e) void GraphingCalculator::OnKeyGraphFeaturesClosed(Object ^ sender, RoutedEventArgs ^ e)
{ {
IsKeyGraphFeaturesVisible = false; IsKeyGraphFeaturesVisible = false;
ViewModel->SelectedEquation->GraphEquation->IsSelected = false;
} }
Visibility GraphingCalculator::ShouldDisplayPanel(bool isSmallState, bool isEquationModeActivated, bool isGraphPanel) Visibility GraphingCalculator::ShouldDisplayPanel(bool isSmallState, bool isEquationModeActivated, bool isGraphPanel)

View File

@ -179,6 +179,7 @@ namespace GraphControl
{ {
if (m_graph) if (m_graph)
{ {
m_graph->TryResetSelection();
UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations()); UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations());
} }
@ -325,6 +326,13 @@ namespace GraphControl
if (initResult != nullopt) if (initResult != nullopt)
{ {
auto graphedEquations = initResult.value();
for (int i = 0; i < validEqs.size(); i++)
{
validEqs[i]->GraphedEquation = graphedEquations[i];
}
UpdateGraphOptions(m_graph->GetOptions(), validEqs); UpdateGraphOptions(m_graph->GetOptions(), validEqs);
SetGraphArgs(m_graph); SetGraphArgs(m_graph);
@ -498,6 +506,11 @@ namespace GraphControl
{ {
auto lineColor = eq->LineColor; auto lineColor = eq->LineColor;
graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A); graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A);
if (eq->IsSelected)
{
eq->GraphedEquation->TrySelectEquation();
}
} }
options.SetGraphColors(graphColors); options.SetGraphColors(graphColors);
} }

View File

@ -30,8 +30,7 @@ namespace GraphControl
// Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to. // Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to.
if (expr.find(L">&#x3E;<") != wstring_view::npos || expr.find(L">&#x3C;<") != wstring_view::npos || expr.find(L">&#x2265;<") != wstring_view::npos if (expr.find(L">&#x3E;<") != wstring_view::npos || expr.find(L">&#x3C;<") != wstring_view::npos || expr.find(L">&#x2265;<") != wstring_view::npos
|| expr.find(L">&#x2264;<") != wstring_view::npos || expr.find(8805) != wstring_view::npos || expr.find(8804) != wstring_view::npos || expr.find(L">&#x2264;<") != wstring_view::npos || expr.find(8805) != wstring_view::npos || expr.find(8804) != wstring_view::npos
|| expr.find(L">&lt;<") != wstring_view::npos || expr.find(L">&lt;<") != wstring_view::npos || expr.find(L">&gt;<") != wstring_view::npos)
|| expr.find(L">&gt;<") != wstring_view::npos)
{ {
request = L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">"; request = L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">";
} }

View File

@ -17,6 +17,7 @@ namespace GraphControl
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsLineEnabled); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsLineEnabled);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsValidated); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsValidated);
OBSERVABLE_NAMED_PROPERTY_RW(bool, HasGraphError); OBSERVABLE_NAMED_PROPERTY_RW(bool, HasGraphError);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsSelected);
property Windows::UI::Color LineColor property Windows::UI::Color LineColor
{ {
@ -32,10 +33,24 @@ namespace GraphControl
bool IsGraphableEquation(); bool IsGraphableEquation();
internal:
property std::shared_ptr<Graphing::IEquation> GraphedEquation
{
void set(std::shared_ptr<Graphing::IEquation> graphedEquation)
{
m_graphedEquation = graphedEquation;
}
std::shared_ptr<Graphing::IEquation> get()
{
return m_graphedEquation;
}
}
private: private:
std::wstring GetExpression(); std::wstring GetExpression();
private: private:
Windows::UI::Color m_LineColor; Windows::UI::Color m_LineColor;
std::shared_ptr<Graphing::IEquation> m_graphedEquation;
}; };
} }

View File

@ -158,7 +158,7 @@ public
{ {
auto equation = static_cast<Equation ^>(sender); auto equation = static_cast<Equation ^>(sender);
auto propertyName = args->PropertyName; auto propertyName = args->PropertyName;
if (propertyName == GraphControl::Equation::LineColorPropertyName) if (propertyName == GraphControl::Equation::LineColorPropertyName || propertyName == GraphControl::Equation::IsSelectedPropertyName)
{ {
EquationStyleChanged(equation); EquationStyleChanged(equation);
} }