Skip to content

Commit

Permalink
Fix focus for EquationTextBox (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseartrivera authored Nov 13, 2019
1 parent 442ed6a commit afc1b21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Calculator/Controls/EquationTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void EquationTextBox::OnRichEditBoxTextChanged(Object ^ sender, RoutedEventArgs

void EquationTextBox::OnRichEditBoxGotFocus(Object ^ sender, RoutedEventArgs ^ e)
{
m_isFocused = true;
m_HasFocus = true;
UpdateCommonVisualState();
UpdateDeleteButtonVisualState();
}
Expand All @@ -151,7 +151,7 @@ void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^
{
if (!m_richEditBox->ContextFlyout->IsOpen)
{
m_isFocused = false;
m_HasFocus = false;
}
UpdateCommonVisualState();
UpdateDeleteButtonVisualState();
Expand Down Expand Up @@ -222,7 +222,7 @@ void EquationTextBox::UpdateCommonVisualState()
{
String ^ state = "Normal";

if (m_isFocused)
if (m_HasFocus)
{
state = "Focused";
}
Expand Down Expand Up @@ -271,5 +271,5 @@ bool EquationTextBox::ShouldDeleteButtonBeVisible()
{
text = m_richEditBox->MathText;
}
return (!text->IsEmpty() && m_isFocused);
return (!text->IsEmpty() && m_HasFocus);
}
3 changes: 2 additions & 1 deletion src/Calculator/Controls/EquationTextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace CalculatorApp
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Media::SolidColorBrush^, EquationColor);
DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Flyout^, ColorChooserFlyout);

PROPERTY_R(bool, HasFocus);

event Windows::UI::Xaml::RoutedEventHandler ^ RemoveButtonClicked;
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesButtonClicked;
event Windows::UI::Xaml::RoutedEventHandler ^ EquationSubmitted;
Expand Down Expand Up @@ -64,7 +66,6 @@ namespace CalculatorApp
Windows::UI::Xaml::Controls::Button^ m_functionButton;
Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_colorChooserButton;

bool m_isFocused;
bool m_isPointerOver;
bool m_isColorChooserFlyoutOpen;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ void EquationInputArea::InputTextBox_Submitted(Object ^ sender, RoutedEventArgs
auto tb = static_cast<EquationTextBox ^>(sender);
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
eq->Expression = tb->GetEquationText();
FocusManager::TryMoveFocus(::FocusNavigationDirection::Left);

if (tb->HasFocus)
{
FocusManager::TryMoveFocus(::FocusNavigationDirection::Left);
}
}

void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
Expand Down

0 comments on commit afc1b21

Please sign in to comment.