Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberBox: Visual updates #5032

Merged
merged 4 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions dev/NumberBox/NumberBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,6 @@ void NumberBox::OnApplyTemplate()
}

m_textBoxKeyUpRevoker = textBox.KeyUp(winrt::auto_revoke, { this, &NumberBox::OnNumberBoxKeyUp });

// Listen to NumberBox::CornerRadius changes so that we can enfore the T-rule for the textbox in SpinButtonPlacementMode::Inline.
// We need to explicitly go to the corresponding visual state each time the NumberBox' CornerRadius is changed in order for the new
// corner radius values to be filtered correctly.
// If we only go to the SpinButtonsVisible visual state whenever the SpinButtonPlacementMode is changed to Inline, all subsequent
// corner radius changes would apply to all four textbox corners (this can be easily seen in the CornerRadius test page of the MUXControlsTestApp).
// This will break the T-rule in the Inline SpinButtonPlacementMode.
if (SharedHelpers::IsControlCornerRadiusAvailable())
ranjeshj marked this conversation as resolved.
Show resolved Hide resolved
{
m_cornerRadiusChangedRevoker = RegisterPropertyChanged(*this,
winrt::Control::CornerRadiusProperty(), { this, &NumberBox::OnCornerRadiusPropertyChanged });
}
}
return textBox;
}());
Expand Down Expand Up @@ -226,6 +214,8 @@ void NumberBox::OnApplyTemplate()

UpdateVisualStateForIsEnabledChange();

ReevaluateForwardedUIAName();

if (ReadLocalValue(s_ValueProperty) == winrt::DependencyProperty::UnsetValue()
&& ReadLocalValue(s_TextProperty) != winrt::DependencyProperty::UnsetValue())
{
Expand All @@ -238,15 +228,6 @@ void NumberBox::OnApplyTemplate()
}
}

void NumberBox::OnCornerRadiusPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&)
{
if (this->SpinButtonPlacementMode() == winrt::NumberBoxSpinButtonPlacementMode::Inline)
{
// Enforce T-rule for the textbox in Inline SpinButtonPlacementMode.
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsVisible", false);
}
}

void NumberBox::OnValuePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
{
// This handler may change Value; don't send extra events in that case.
Expand Down Expand Up @@ -643,18 +624,21 @@ void NumberBox::UpdateTextToValue()
void NumberBox::UpdateSpinButtonPlacement()
{
const auto spinButtonMode = SpinButtonPlacementMode();
auto state = L"SpinButtonsCollapsed";

if (spinButtonMode == winrt::NumberBoxSpinButtonPlacementMode::Inline)
{
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsVisible", false);
state = L"SpinButtonsVisible";
}
else if (spinButtonMode == winrt::NumberBoxSpinButtonPlacementMode::Compact)
{
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsPopup", false);
state = L"SpinButtonsPopup";
Comment on lines +627 to +635
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use const expr's for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never have before, so 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, in other controls, we do that all the time🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - that's up to you. We typically define the state names in the .h file, like
static constexpr std::wstring_view s_scrollBarsSeparatorExpanded{ L"ScrollBarsSeparatorExpanded"sv };

}
Comment on lines +627 to 636
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could convert this to a lambda and have a constant string, but not sure if that adds more value. @teaP @StephenLPeters thoughts?

else

winrt::VisualStateManager::GoToState(*this, state, false);
if (const auto textbox = m_textBox.get())
{
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsCollapsed", false);
winrt::VisualStateManager::GoToState(textbox, state, false);
}
}

Expand Down
3 changes: 0 additions & 3 deletions dev/NumberBox/NumberBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class NumberBox :
void OnNumberBoxGotFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnNumberBoxLostFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
void OnNumberBoxScroll(winrt::IInspectable const& sender, winrt::PointerRoutedEventArgs const& args);
void OnCornerRadiusPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);
void OnIsEnabledChanged(const winrt::IInspectable&, const winrt::DependencyPropertyChangedEventArgs&);
void OnAutomationPropertiesNamePropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);

Expand Down Expand Up @@ -112,7 +111,5 @@ class NumberBox :
winrt::RepeatButton::Click_revoker m_popupUpButtonClickRevoker{};
winrt::RepeatButton::Click_revoker m_popupDownButtonClickRevoker{};

PropertyChanged_revoker m_cornerRadiusChangedRevoker{};

winrt::Control::IsEnabledChanged_revoker m_isEnabledChangedRevoker{};
};
Loading