Add error handling to graph and equations (#827)

* add error handling

* Handle regraphing on certain errors

* Fix high contrast

* Hide KGF button in error state
This commit is contained in:
Pepe Rivera
2019-12-03 14:41:39 -08:00
committed by Eric Wong
parent 3ca4f4ffa7
commit 89c3fc3e4d
14 changed files with 397 additions and 202 deletions

View File

@@ -24,13 +24,13 @@ using namespace Windows::UI::Xaml::Controls::Primitives;
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationColor);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, ColorChooserFlyout);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationButtonContentIndex);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, HasError);
void EquationTextBox::OnApplyTemplate()
{
m_equationButton = dynamic_cast<ToggleButton ^>(GetTemplateChild("EquationButton"));
m_kgfEquationButton = dynamic_cast<Button ^>(GetTemplateChild("KGFEquationButton"));
m_richEditBox = dynamic_cast<MathRichEditBox ^>(GetTemplateChild("EquationTextBox"));
m_richEditBox = dynamic_cast<MathRichEditBox ^>(GetTemplateChild("MathRichEditBox"));
m_deleteButton = dynamic_cast<Button ^>(GetTemplateChild("DeleteButton"));
m_removeButton = dynamic_cast<Button ^>(GetTemplateChild("RemoveButton"));
m_functionButton = dynamic_cast<Button ^>(GetTemplateChild("FunctionButton"));
@@ -127,7 +127,7 @@ void EquationTextBox::OnKeyDown(KeyRoutedEventArgs ^ e)
void EquationTextBox::OnLostFocus(RoutedEventArgs ^ e)
{
if (!m_richEditBox->ContextFlyout->IsOpen)
if (m_richEditBox != nullptr && !m_richEditBox->ContextFlyout->IsOpen)
{
EquationSubmitted(this, ref new RoutedEventArgs());
if (m_functionButton && m_richEditBox->MathText != L"")
@@ -168,6 +168,7 @@ void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^
{
m_HasFocus = false;
}
UpdateCommonVisualState();
UpdateDeleteButtonVisualState();
}
@@ -259,26 +260,38 @@ void EquationTextBox::UpdateCommonVisualState()
{
state = "Focused";
}
else if ((m_isPointerOver && HasError) || (m_isColorChooserFlyoutOpen && HasError))
{
state = "PointerOverError";
}
else if (m_isPointerOver || m_isColorChooserFlyoutOpen)
{
state = "PointerOver";
}
else if (HasError)
{
state = "Error";
}
VisualStateManager::GoToState(this, state, true);
}
void EquationTextBox::OnHasErrorPropertyChanged(bool, bool)
{
UpdateCommonVisualState();
}
Platform::String ^ EquationTextBox::GetEquationText()
{
String ^ text;
if (m_richEditBox != nullptr)
{
// Clear formatting since the graph control doesn't work with bold/italic/underlines
// Clear formatting since the graph control doesn't work with bold/underlines
ITextRange ^ range = m_richEditBox->TextDocument->GetRange(0, m_richEditBox->TextDocument->Selection->EndPosition);
if (range != nullptr)
{
range->CharacterFormat->Bold = FormatEffect::Off;
range->CharacterFormat->Italic = FormatEffect::Off;
range->CharacterFormat->Underline = UnderlineType::None;
}

View File

@@ -22,6 +22,7 @@ namespace CalculatorApp
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Media::SolidColorBrush^, EquationColor);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Flyout^, ColorChooserFlyout);
DEPENDENCY_PROPERTY(Platform::String ^, EquationButtonContentIndex);
DEPENDENCY_PROPERTY_WITH_CALLBACK(bool, HasError);
PROPERTY_R(bool, HasFocus);
@@ -61,6 +62,8 @@ namespace CalculatorApp
void OnColorFlyoutOpened(Platform::Object^ sender, Platform::Object^ e);
void OnColorFlyoutClosed(Platform::Object^ sender, Platform::Object^ e);
void OnHasErrorPropertyChanged(bool oldValue, bool newValue);
CalculatorApp::Controls::MathRichEditBox^ m_richEditBox;
Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_equationButton;
Windows::UI::Xaml::Controls::Button^ m_kgfEquationButton;