Skip to content

Commit a43a2ab

Browse files
authored
NumberBox: Visual updates (#5032)
* Visual updates * Quick accessibility fix -- we need this to run AFTER m_textBox is set. * Adjusted the size of popup buttons, fixed keyboard focus issue. * Removed test -- now that corners are only applied to the TextBox, we don't need to worry about which elements have corners anymore.
1 parent 4fc34de commit a43a2ab

File tree

5 files changed

+140
-111
lines changed

5 files changed

+140
-111
lines changed

dev/NumberBox/APITests/NumberBoxTests.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,66 +49,6 @@ public void VerifyTextAlignmentPropogates()
4949
});
5050
}
5151

52-
[TestMethod]
53-
public void VerifyNumberBoxCornerRadius()
54-
{
55-
if (Common.PlatformConfiguration.IsOSVersionLessThan(Common.OSVersion.Redstone5))
56-
{
57-
Log.Warning("NumberBox CornerRadius property is not available pre-rs5");
58-
return;
59-
}
60-
61-
var numberBox = SetupNumberBox();
62-
63-
RepeatButton spinButtonDown = null;
64-
TextBox textBox = null;
65-
RunOnUIThread.Execute(() =>
66-
{
67-
// first test: Uniform corner radius of '2' with no spin buttons shown
68-
numberBox.SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Hidden;
69-
numberBox.CornerRadius = new CornerRadius(2);
70-
71-
Content.UpdateLayout();
72-
73-
textBox = TestUtilities.FindDescendents<TextBox>(numberBox).Where(e => e.Name == "InputBox").Single();
74-
Verify.AreEqual(new CornerRadius(2, 2, 2, 2), textBox.CornerRadius);
75-
76-
// second test: Uniform corner radius of '2' with spin buttons in inline mode (T-rule applies now)
77-
numberBox.SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Inline;
78-
Content.UpdateLayout();
79-
80-
spinButtonDown = TestUtilities.FindDescendents<RepeatButton>(numberBox).Where(e => e.Name == "DownSpinButton").Single();
81-
82-
Verify.AreEqual(new CornerRadius(2, 0, 0, 2), textBox.CornerRadius);
83-
Verify.AreEqual(new CornerRadius(0, 2, 2, 0), spinButtonDown.CornerRadius);
84-
85-
// third test: Set uniform corner radius to '4' with spin buttons in inline mode
86-
numberBox.CornerRadius = new CornerRadius(4);
87-
});
88-
IdleSynchronizer.Wait();
89-
90-
RunOnUIThread.Execute(() =>
91-
{
92-
// This check makes sure that updating the CornerRadius values of the numberbox in inline mode
93-
// does not break the T-rule.
94-
Verify.AreEqual(new CornerRadius(4, 0, 0, 4), textBox.CornerRadius);
95-
Verify.AreEqual(new CornerRadius(0, 4, 4, 0), spinButtonDown.CornerRadius);
96-
97-
// fourth test: Update the spin button placement mode to 'compact' and verify that all corners
98-
// of the textbox are now rounded again
99-
numberBox.SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Compact;
100-
Content.UpdateLayout();
101-
102-
Verify.AreEqual(new CornerRadius(4), textBox.CornerRadius);
103-
104-
// fifth test: Check corner radius of 0 in compact mode.
105-
numberBox.CornerRadius = new CornerRadius(0);
106-
Content.UpdateLayout();
107-
108-
Verify.AreEqual(new CornerRadius(0), textBox.CornerRadius);
109-
});
110-
}
111-
11252
[TestMethod]
11353
public void VerifyInputScopePropogates()
11454
{

dev/NumberBox/NumberBox.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,6 @@ void NumberBox::OnApplyTemplate()
172172
}
173173

174174
m_textBoxKeyUpRevoker = textBox.KeyUp(winrt::auto_revoke, { this, &NumberBox::OnNumberBoxKeyUp });
175-
176-
// Listen to NumberBox::CornerRadius changes so that we can enfore the T-rule for the textbox in SpinButtonPlacementMode::Inline.
177-
// We need to explicitly go to the corresponding visual state each time the NumberBox' CornerRadius is changed in order for the new
178-
// corner radius values to be filtered correctly.
179-
// If we only go to the SpinButtonsVisible visual state whenever the SpinButtonPlacementMode is changed to Inline, all subsequent
180-
// corner radius changes would apply to all four textbox corners (this can be easily seen in the CornerRadius test page of the MUXControlsTestApp).
181-
// This will break the T-rule in the Inline SpinButtonPlacementMode.
182-
if (SharedHelpers::IsControlCornerRadiusAvailable())
183-
{
184-
m_cornerRadiusChangedRevoker = RegisterPropertyChanged(*this,
185-
winrt::Control::CornerRadiusProperty(), { this, &NumberBox::OnCornerRadiusPropertyChanged });
186-
}
187175
}
188176
return textBox;
189177
}());
@@ -226,6 +214,8 @@ void NumberBox::OnApplyTemplate()
226214

227215
UpdateVisualStateForIsEnabledChange();
228216

217+
ReevaluateForwardedUIAName();
218+
229219
if (ReadLocalValue(s_ValueProperty) == winrt::DependencyProperty::UnsetValue()
230220
&& ReadLocalValue(s_TextProperty) != winrt::DependencyProperty::UnsetValue())
231221
{
@@ -238,15 +228,6 @@ void NumberBox::OnApplyTemplate()
238228
}
239229
}
240230

241-
void NumberBox::OnCornerRadiusPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&)
242-
{
243-
if (this->SpinButtonPlacementMode() == winrt::NumberBoxSpinButtonPlacementMode::Inline)
244-
{
245-
// Enforce T-rule for the textbox in Inline SpinButtonPlacementMode.
246-
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsVisible", false);
247-
}
248-
}
249-
250231
void NumberBox::OnValuePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
251232
{
252233
// This handler may change Value; don't send extra events in that case.
@@ -643,18 +624,21 @@ void NumberBox::UpdateTextToValue()
643624
void NumberBox::UpdateSpinButtonPlacement()
644625
{
645626
const auto spinButtonMode = SpinButtonPlacementMode();
627+
auto state = L"SpinButtonsCollapsed";
646628

647629
if (spinButtonMode == winrt::NumberBoxSpinButtonPlacementMode::Inline)
648630
{
649-
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsVisible", false);
631+
state = L"SpinButtonsVisible";
650632
}
651633
else if (spinButtonMode == winrt::NumberBoxSpinButtonPlacementMode::Compact)
652634
{
653-
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsPopup", false);
635+
state = L"SpinButtonsPopup";
654636
}
655-
else
637+
638+
winrt::VisualStateManager::GoToState(*this, state, false);
639+
if (const auto textbox = m_textBox.get())
656640
{
657-
winrt::VisualStateManager::GoToState(*this, L"SpinButtonsCollapsed", false);
641+
winrt::VisualStateManager::GoToState(textbox, state, false);
658642
}
659643
}
660644

dev/NumberBox/NumberBox.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class NumberBox :
6868
void OnNumberBoxGotFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
6969
void OnNumberBoxLostFocus(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args);
7070
void OnNumberBoxScroll(winrt::IInspectable const& sender, winrt::PointerRoutedEventArgs const& args);
71-
void OnCornerRadiusPropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);
7271
void OnIsEnabledChanged(const winrt::IInspectable&, const winrt::DependencyPropertyChangedEventArgs&);
7372
void OnAutomationPropertiesNamePropertyChanged(const winrt::DependencyObject&, const winrt::DependencyProperty&);
7473

@@ -112,7 +111,5 @@ class NumberBox :
112111
winrt::RepeatButton::Click_revoker m_popupUpButtonClickRevoker{};
113112
winrt::RepeatButton::Click_revoker m_popupDownButtonClickRevoker{};
114113

115-
PropertyChanged_revoker m_cornerRadiusChangedRevoker{};
116-
117114
winrt::Control::IsEnabledChanged_revoker m_isEnabledChangedRevoker{};
118115
};

0 commit comments

Comments
 (0)