Skip to content

Commit

Permalink
NumberBox: Change StepFrequency to SmallChange and LargeChange (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
jevansaks authored Nov 28, 2019
1 parent 028e26e commit 2237b09
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 63 deletions.
73 changes: 48 additions & 25 deletions dev/Generated/NumberBox.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ GlobalDependencyProperty NumberBoxProperties::s_DescriptionProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_HeaderTemplateProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_IsWrapEnabledProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_LargeChangeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MaximumProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_MinimumProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_NumberFormatterProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_PlaceholderTextProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_PreventKeyboardDisplayOnProgrammaticFocusProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_SelectionFlyoutProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_SelectionHighlightColorProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_SmallChangeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_SpinButtonPlacementModeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_StepFrequencyProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_TextProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_TextReadingOrderProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_ValidationModeProperty{ nullptr };
Expand Down Expand Up @@ -90,6 +91,17 @@ void NumberBoxProperties::EnsureProperties()
ValueHelper<bool>::BoxValueIfNecessary(false),
winrt::PropertyChangedCallback(&OnIsWrapEnabledPropertyChanged));
}
if (!s_LargeChangeProperty)
{
s_LargeChangeProperty =
InitializeDependencyProperty(
L"LargeChange",
winrt::name_of<double>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<double>::BoxValueIfNecessary(10),
nullptr);
}
if (!s_MaximumProperty)
{
s_MaximumProperty =
Expand Down Expand Up @@ -167,6 +179,17 @@ void NumberBoxProperties::EnsureProperties()
ValueHelper<winrt::SolidColorBrush>::BoxedDefaultValue(),
nullptr);
}
if (!s_SmallChangeProperty)
{
s_SmallChangeProperty =
InitializeDependencyProperty(
L"SmallChange",
winrt::name_of<double>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<double>::BoxValueIfNecessary(1),
winrt::PropertyChangedCallback(&OnSmallChangePropertyChanged));
}
if (!s_SpinButtonPlacementModeProperty)
{
s_SpinButtonPlacementModeProperty =
Expand All @@ -178,17 +201,6 @@ void NumberBoxProperties::EnsureProperties()
ValueHelper<winrt::NumberBoxSpinButtonPlacementMode>::BoxValueIfNecessary(winrt::NumberBoxSpinButtonPlacementMode::Hidden),
winrt::PropertyChangedCallback(&OnSpinButtonPlacementModePropertyChanged));
}
if (!s_StepFrequencyProperty)
{
s_StepFrequencyProperty =
InitializeDependencyProperty(
L"StepFrequency",
winrt::name_of<double>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<double>::BoxValueIfNecessary(1),
winrt::PropertyChangedCallback(&OnStepFrequencyPropertyChanged));
}
if (!s_TextProperty)
{
s_TextProperty =
Expand Down Expand Up @@ -242,15 +254,16 @@ void NumberBoxProperties::ClearProperties()
s_HeaderProperty = nullptr;
s_HeaderTemplateProperty = nullptr;
s_IsWrapEnabledProperty = nullptr;
s_LargeChangeProperty = nullptr;
s_MaximumProperty = nullptr;
s_MinimumProperty = nullptr;
s_NumberFormatterProperty = nullptr;
s_PlaceholderTextProperty = nullptr;
s_PreventKeyboardDisplayOnProgrammaticFocusProperty = nullptr;
s_SelectionFlyoutProperty = nullptr;
s_SelectionHighlightColorProperty = nullptr;
s_SmallChangeProperty = nullptr;
s_SpinButtonPlacementModeProperty = nullptr;
s_StepFrequencyProperty = nullptr;
s_TextProperty = nullptr;
s_TextReadingOrderProperty = nullptr;
s_ValidationModeProperty = nullptr;
Expand Down Expand Up @@ -299,20 +312,20 @@ void NumberBoxProperties::OnNumberFormatterPropertyChanged(
winrt::get_self<NumberBox>(owner)->OnNumberFormatterPropertyChanged(args);
}

void NumberBoxProperties::OnSpinButtonPlacementModePropertyChanged(
void NumberBoxProperties::OnSmallChangePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
{
auto owner = sender.as<winrt::NumberBox>();
winrt::get_self<NumberBox>(owner)->OnSpinButtonPlacementModePropertyChanged(args);
winrt::get_self<NumberBox>(owner)->OnSmallChangePropertyChanged(args);
}

void NumberBoxProperties::OnStepFrequencyPropertyChanged(
void NumberBoxProperties::OnSpinButtonPlacementModePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
{
auto owner = sender.as<winrt::NumberBox>();
winrt::get_self<NumberBox>(owner)->OnStepFrequencyPropertyChanged(args);
winrt::get_self<NumberBox>(owner)->OnSpinButtonPlacementModePropertyChanged(args);
}

void NumberBoxProperties::OnTextPropertyChanged(
Expand Down Expand Up @@ -389,6 +402,16 @@ bool NumberBoxProperties::IsWrapEnabled()
return ValueHelper<bool>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_IsWrapEnabledProperty));
}

void NumberBoxProperties::LargeChange(double value)
{
static_cast<NumberBox*>(this)->SetValue(s_LargeChangeProperty, ValueHelper<double>::BoxValueIfNecessary(value));
}

double NumberBoxProperties::LargeChange()
{
return ValueHelper<double>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_LargeChangeProperty));
}

void NumberBoxProperties::Maximum(double value)
{
static_cast<NumberBox*>(this)->SetValue(s_MaximumProperty, ValueHelper<double>::BoxValueIfNecessary(value));
Expand Down Expand Up @@ -461,24 +484,24 @@ winrt::SolidColorBrush NumberBoxProperties::SelectionHighlightColor()
return ValueHelper<winrt::SolidColorBrush>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_SelectionHighlightColorProperty));
}

void NumberBoxProperties::SpinButtonPlacementMode(winrt::NumberBoxSpinButtonPlacementMode const& value)
void NumberBoxProperties::SmallChange(double value)
{
static_cast<NumberBox*>(this)->SetValue(s_SpinButtonPlacementModeProperty, ValueHelper<winrt::NumberBoxSpinButtonPlacementMode>::BoxValueIfNecessary(value));
static_cast<NumberBox*>(this)->SetValue(s_SmallChangeProperty, ValueHelper<double>::BoxValueIfNecessary(value));
}

winrt::NumberBoxSpinButtonPlacementMode NumberBoxProperties::SpinButtonPlacementMode()
double NumberBoxProperties::SmallChange()
{
return ValueHelper<winrt::NumberBoxSpinButtonPlacementMode>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_SpinButtonPlacementModeProperty));
return ValueHelper<double>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_SmallChangeProperty));
}

void NumberBoxProperties::StepFrequency(double value)
void NumberBoxProperties::SpinButtonPlacementMode(winrt::NumberBoxSpinButtonPlacementMode const& value)
{
static_cast<NumberBox*>(this)->SetValue(s_StepFrequencyProperty, ValueHelper<double>::BoxValueIfNecessary(value));
static_cast<NumberBox*>(this)->SetValue(s_SpinButtonPlacementModeProperty, ValueHelper<winrt::NumberBoxSpinButtonPlacementMode>::BoxValueIfNecessary(value));
}

double NumberBoxProperties::StepFrequency()
winrt::NumberBoxSpinButtonPlacementMode NumberBoxProperties::SpinButtonPlacementMode()
{
return ValueHelper<double>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_StepFrequencyProperty));
return ValueHelper<winrt::NumberBoxSpinButtonPlacementMode>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_SpinButtonPlacementModeProperty));
}

void NumberBoxProperties::Text(winrt::hstring const& value)
Expand Down
19 changes: 12 additions & 7 deletions dev/Generated/NumberBox.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class NumberBoxProperties
void IsWrapEnabled(bool value);
bool IsWrapEnabled();

void LargeChange(double value);
double LargeChange();

void Maximum(double value);
double Maximum();

Expand All @@ -45,12 +48,12 @@ class NumberBoxProperties
void SelectionHighlightColor(winrt::SolidColorBrush const& value);
winrt::SolidColorBrush SelectionHighlightColor();

void SmallChange(double value);
double SmallChange();

void SpinButtonPlacementMode(winrt::NumberBoxSpinButtonPlacementMode const& value);
winrt::NumberBoxSpinButtonPlacementMode SpinButtonPlacementMode();

void StepFrequency(double value);
double StepFrequency();

void Text(winrt::hstring const& value);
winrt::hstring Text();

Expand All @@ -68,15 +71,16 @@ class NumberBoxProperties
static winrt::DependencyProperty HeaderProperty() { return s_HeaderProperty; }
static winrt::DependencyProperty HeaderTemplateProperty() { return s_HeaderTemplateProperty; }
static winrt::DependencyProperty IsWrapEnabledProperty() { return s_IsWrapEnabledProperty; }
static winrt::DependencyProperty LargeChangeProperty() { return s_LargeChangeProperty; }
static winrt::DependencyProperty MaximumProperty() { return s_MaximumProperty; }
static winrt::DependencyProperty MinimumProperty() { return s_MinimumProperty; }
static winrt::DependencyProperty NumberFormatterProperty() { return s_NumberFormatterProperty; }
static winrt::DependencyProperty PlaceholderTextProperty() { return s_PlaceholderTextProperty; }
static winrt::DependencyProperty PreventKeyboardDisplayOnProgrammaticFocusProperty() { return s_PreventKeyboardDisplayOnProgrammaticFocusProperty; }
static winrt::DependencyProperty SelectionFlyoutProperty() { return s_SelectionFlyoutProperty; }
static winrt::DependencyProperty SelectionHighlightColorProperty() { return s_SelectionHighlightColorProperty; }
static winrt::DependencyProperty SmallChangeProperty() { return s_SmallChangeProperty; }
static winrt::DependencyProperty SpinButtonPlacementModeProperty() { return s_SpinButtonPlacementModeProperty; }
static winrt::DependencyProperty StepFrequencyProperty() { return s_StepFrequencyProperty; }
static winrt::DependencyProperty TextProperty() { return s_TextProperty; }
static winrt::DependencyProperty TextReadingOrderProperty() { return s_TextReadingOrderProperty; }
static winrt::DependencyProperty ValidationModeProperty() { return s_ValidationModeProperty; }
Expand All @@ -87,15 +91,16 @@ class NumberBoxProperties
static GlobalDependencyProperty s_HeaderProperty;
static GlobalDependencyProperty s_HeaderTemplateProperty;
static GlobalDependencyProperty s_IsWrapEnabledProperty;
static GlobalDependencyProperty s_LargeChangeProperty;
static GlobalDependencyProperty s_MaximumProperty;
static GlobalDependencyProperty s_MinimumProperty;
static GlobalDependencyProperty s_NumberFormatterProperty;
static GlobalDependencyProperty s_PlaceholderTextProperty;
static GlobalDependencyProperty s_PreventKeyboardDisplayOnProgrammaticFocusProperty;
static GlobalDependencyProperty s_SelectionFlyoutProperty;
static GlobalDependencyProperty s_SelectionHighlightColorProperty;
static GlobalDependencyProperty s_SmallChangeProperty;
static GlobalDependencyProperty s_SpinButtonPlacementModeProperty;
static GlobalDependencyProperty s_StepFrequencyProperty;
static GlobalDependencyProperty s_TextProperty;
static GlobalDependencyProperty s_TextReadingOrderProperty;
static GlobalDependencyProperty s_ValidationModeProperty;
Expand Down Expand Up @@ -125,11 +130,11 @@ class NumberBoxProperties
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnSpinButtonPlacementModePropertyChanged(
static void OnSmallChangePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnStepFrequencyPropertyChanged(
static void OnSpinButtonPlacementModePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

Expand Down
11 changes: 8 additions & 3 deletions dev/NumberBox/InteractionTests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public void UpDownTest()
downButton.InvokeAndWait();
Verify.AreEqual(0, numBox.Value);

Log.Comment("Change Step value to 5");
RangeValueSpinner stepNumBox = FindElement.ByName<RangeValueSpinner>("StepNumberBox");
stepNumBox.SetValue(5);
Log.Comment("Change SmallChange value to 5");
RangeValueSpinner smallChangeNumBox = FindElement.ByName<RangeValueSpinner>("SmallChangeNumberBox");
smallChangeNumBox.SetValue(5);
Wait.ForIdle();

Log.Comment("Verify that up button increases value by 5");
Expand Down Expand Up @@ -267,6 +267,11 @@ public void BasicKeyboardTest()
KeyboardHelper.PressKey(Key.Down);
Wait.ForIdle();
Verify.AreEqual(75, numBox.Value);

Log.Comment("Verify that pressing PageUp key increases value by 10");
KeyboardHelper.PressKey(Key.PageUp);
Wait.ForIdle();
Verify.AreEqual(85, numBox.Value);
}
}

Expand Down
37 changes: 20 additions & 17 deletions dev/NumberBox/NumberBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void NumberBox::OnMaximumPropertyChanged(const winrt::DependencyPropertyChangedE
UpdateSpinButtonEnabled();
}

void NumberBox::OnStepFrequencyPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
void NumberBox::OnSmallChangePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
{
UpdateSpinButtonEnabled();
}
Expand Down Expand Up @@ -353,12 +353,12 @@ void NumberBox::ValidateInput()

void NumberBox::OnSpinDownClick(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args)
{
StepValueDown();
StepValue(-SmallChange());
}

void NumberBox::OnSpinUpClick(winrt::IInspectable const& sender, winrt::RoutedEventArgs const& args)
{
StepValueUp();
StepValue(SmallChange());
}

void NumberBox::OnNumberBoxKeyDown(winrt::IInspectable const& sender, winrt::KeyRoutedEventArgs const& args)
Expand All @@ -367,12 +367,22 @@ void NumberBox::OnNumberBoxKeyDown(winrt::IInspectable const& sender, winrt::Key
switch (args.OriginalKey())
{
case winrt::VirtualKey::Up:
StepValueUp();
args.Handled(true);
StepValue(SmallChange());
args.Handled(true);
break;

case winrt::VirtualKey::Down:
StepValueDown();
StepValue(-SmallChange());
args.Handled(true);
break;

case winrt::VirtualKey::PageUp:
StepValue(LargeChange());
args.Handled(true);
break;

case winrt::VirtualKey::PageDown:
StepValue(-LargeChange());
args.Handled(true);
break;
}
Expand Down Expand Up @@ -405,32 +415,25 @@ void NumberBox::OnNumberBoxScroll(winrt::IInspectable const& sender, winrt::Poin
const auto delta = args.GetCurrentPoint(*this).Properties().MouseWheelDelta();
if (delta > 0)
{
StepValueUp();
StepValue(SmallChange());
}
else if (delta < 0)
{
StepValueDown();
StepValue(-SmallChange());
}
}
}
}

void NumberBox::StepValue(bool isPositive)
void NumberBox::StepValue(double change)
{
// Before adjusting the value, validate the contents of the textbox so we don't override it.
ValidateInput();

auto newVal = Value();
if (!std::isnan(newVal))
{
if (isPositive)
{
newVal += StepFrequency();
}
else
{
newVal -= StepFrequency();
}
newVal += change;

if (IsWrapEnabled())
{
Expand Down
7 changes: 3 additions & 4 deletions dev/NumberBox/NumberBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class NumberBox :
void OnValuePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnMinimumPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnMaximumPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnStepFrequencyPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnSmallChangePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnLargeChangePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnIsWrapEnabledPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);

void OnNumberFormatterPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
Expand All @@ -72,9 +73,7 @@ class NumberBox :

void UpdateSpinButtonPlacement();
void UpdateSpinButtonEnabled();
void StepValue(bool isPositive);
void StepValueUp() { StepValue(true); }
void StepValueDown() { StepValue(false); }
void StepValue(double change);

bool IsInBounds(double value);

Expand Down
8 changes: 6 additions & 2 deletions dev/NumberBox/NumberBox.idl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control

[MUX_DEFAULT_VALUE("1")]
[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
Double StepFrequency;
Double SmallChange;

[MUX_DEFAULT_VALUE("10")]
Double LargeChange;

[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
String Text;
Expand Down Expand Up @@ -84,7 +87,8 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
static Windows.UI.Xaml.DependencyProperty MinimumProperty{ get; };
static Windows.UI.Xaml.DependencyProperty MaximumProperty{ get; };
static Windows.UI.Xaml.DependencyProperty ValueProperty{ get; };
static Windows.UI.Xaml.DependencyProperty StepFrequencyProperty{ get; };
static Windows.UI.Xaml.DependencyProperty SmallChangeProperty{ get; };
static Windows.UI.Xaml.DependencyProperty LargeChangeProperty{ get; };
static Windows.UI.Xaml.DependencyProperty TextProperty{ get; };

static Windows.UI.Xaml.DependencyProperty HeaderProperty{ get; };
Expand Down
Loading

0 comments on commit 2237b09

Please sign in to comment.