From 240792a7758b2fa1282e0a3520f8d452d2886694 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Fri, 10 Jan 2020 16:41:23 -0800 Subject: [PATCH] Adjustments to ghost textbox (#924) * adjustments * delete extra visual states * Fix hover bug * Fix a few more bugs * Fix high contrast crash --- .../GraphingCalculator/EquationViewModel.h | 2 +- src/Calculator/App.xaml | 2 +- src/Calculator/Controls/EquationTextBox.cpp | 34 ++++++++++------ src/Calculator/Controls/EquationTextBox.h | 1 + .../GraphingCalculator/EquationInputArea.xaml | 39 +++++++++++-------- .../EquationInputArea.xaml.cpp | 22 ++++++++--- 6 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h index 5ed0870d..143254b0 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h @@ -45,7 +45,7 @@ public OBSERVABLE_OBJECT(); OBSERVABLE_PROPERTY_R(GraphControl::Equation ^, GraphEquation); - OBSERVABLE_PROPERTY_R(int, FunctionLabelIndex); + OBSERVABLE_PROPERTY_RW(int, FunctionLabelIndex); OBSERVABLE_PROPERTY_RW(bool, IsLastItemInList); property Platform::String ^ Expression diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 7c282e9e..50472efd 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -1743,7 +1743,7 @@ Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" - Margin="{TemplateBinding BorderThickness}" + Margin="0,-1,0,0" Padding="{TemplateBinding Padding}" VerticalAlignment="Center" Foreground="{ThemeResource TextControlPlaceholderForeground}" diff --git a/src/Calculator/Controls/EquationTextBox.cpp b/src/Calculator/Controls/EquationTextBox.cpp index e97ae567..98b3cf1b 100644 --- a/src/Calculator/Controls/EquationTextBox.cpp +++ b/src/Calculator/Controls/EquationTextBox.cpp @@ -51,9 +51,9 @@ void EquationTextBox::OnApplyTemplate() { m_richEditBox->GotFocus += ref new RoutedEventHandler(this, &EquationTextBox::OnRichEditBoxGotFocus); m_richEditBox->LostFocus += ref new RoutedEventHandler(this, &EquationTextBox::OnRichEditBoxLostFocus); + m_richEditBox->TextChanged += ref new RoutedEventHandler(this, &EquationTextBox::OnRichEditTextChanged); m_richEditBox->SelectionFlyout = nullptr; - m_richEditBox->EquationSubmitted += - ref new EventHandler(this, &EquationTextBox::OnEquationSubmitted); + m_richEditBox->EquationSubmitted += ref new EventHandler(this, &EquationTextBox::OnEquationSubmitted); m_richEditBox->FormatRequest += ref new EventHandler(this, &EquationTextBox::OnEquationFormatRequested); } @@ -160,6 +160,12 @@ void EquationTextBox::OnColorFlyoutClosed(Object ^ sender, Object ^ e) UpdateCommonVisualState(); } +void EquationTextBox::OnRichEditTextChanged(Object ^ sender, RoutedEventArgs ^ e) +{ + UpdateCommonVisualState(); + UpdateButtonsVisualState(); +} + void EquationTextBox::OnRichEditBoxGotFocus(Object ^ sender, RoutedEventArgs ^ e) { m_HasFocus = true; @@ -182,7 +188,7 @@ void EquationTextBox::OnDeleteButtonClicked(Object ^ sender, RoutedEventArgs ^ e { if (m_richEditBox != nullptr) { - m_richEditBox->MathText = L""; + m_richEditBox->TextDocument->SetText(::TextSetOptions::None, ""); if (m_functionButton) { m_functionButton->IsEnabled = false; @@ -248,14 +254,14 @@ void EquationTextBox::UpdateButtonsVisualState() { String ^ state; - if (IsAddEquationMode) - { - state = "ButtonHideRemove"; - } - else if (RichEditHasContent()) + if (m_HasFocus && RichEditHasContent()) { state = "ButtonVisible"; } + else if (IsAddEquationMode) + { + state = "ButtonHideRemove"; + } else { state = "ButtonCollapsed"; @@ -272,6 +278,10 @@ void EquationTextBox::UpdateCommonVisualState() { state = "FocusedError"; } + else if (IsAddEquationMode && ((m_HasFocus || m_isPointerOver) && !RichEditHasContent())) + { + state = "AddEquation"; + } else if (m_HasFocus) { state = "Focused"; @@ -338,21 +348,21 @@ bool EquationTextBox::RichEditHasContent() if (m_richEditBox != nullptr) { - text = m_richEditBox->MathText; + m_richEditBox->TextDocument->GetText(Windows::UI::Text::TextGetOptions::NoHidden, &text); } - return !text->IsEmpty() && m_HasFocus; + return !text->IsEmpty(); } void EquationTextBox::OnRichEditMenuOpening(Object ^ /*sender*/, Object ^ /*args*/) { if (m_kgfEquationMenuItem != nullptr) { - m_kgfEquationMenuItem->IsEnabled = RichEditHasContent(); + m_kgfEquationMenuItem->IsEnabled = m_HasFocus && RichEditHasContent(); } if (m_colorChooserMenuItem != nullptr) { - m_colorChooserMenuItem->IsEnabled = !HasError; + m_colorChooserMenuItem->IsEnabled = !HasError && !IsAddEquationMode; } } diff --git a/src/Calculator/Controls/EquationTextBox.h b/src/Calculator/Controls/EquationTextBox.h index ed71b501..d2451ad0 100644 --- a/src/Calculator/Controls/EquationTextBox.h +++ b/src/Calculator/Controls/EquationTextBox.h @@ -52,6 +52,7 @@ namespace CalculatorApp void OnRichEditBoxGotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void OnRichEditBoxLostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void OnRichEditTextChanged(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void OnDeleteButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OnEquationButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml index 50132d68..e47be775 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml @@ -244,6 +244,12 @@ + + 0,1,1,1 @@ -255,6 +261,10 @@ + + 0,1,1,1 @@ -267,6 +277,8 @@ 1 + + @@ -289,7 +301,11 @@ - + + + + + @@ -377,7 +393,8 @@ FlowDirection="LeftToRight" Orientation="Horizontal"> - @@ -398,12 +415,6 @@ - - @@ -427,10 +438,6 @@ - - @@ -451,19 +458,19 @@