Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions src/Eto.WinForms/Forms/Controls/NumericStepperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public NumericStepperHandler()
Handler = this,
Maximum = DoubleToDecimal(double.MaxValue),
Minimum = DoubleToDecimal(double.MinValue),
Width = 80
Width = 80,
TextAlign = TextAlignment.Left.ToSWF()
};
Control.ValueChanged += Control_ValueChanged;
Control.LostFocus += (sender, e) =>
Expand All @@ -145,7 +146,6 @@ public NumericStepperHandler()
}
};
}

int valueChanging;
double? lastValue;

Expand Down Expand Up @@ -351,7 +351,6 @@ void SetMinMaxValues()
}
valueChanging--;
}

decimal DoubleToDecimal(double value)
{
if (double.IsNegativeInfinity(value) || value < (double)decimal.MinValue)
Expand Down Expand Up @@ -380,5 +379,11 @@ void UpdateRequiredDigits()
Control.DecimalPlaces = Math.Max(Math.Min(GetNumberOfDigits(), MaximumDecimalPlaces), DecimalPlaces);
Control.UpdateText();
}

public TextAlignment TextAlignment
{
get => Control.TextAlign.ToEto();
set => Control.TextAlign = value.ToSWF();
}
}
}
14 changes: 12 additions & 2 deletions src/Eto.Wpf/Forms/Controls/NumericStepperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public NumericStepperHandler()
{
Handler = this,
FormatString = "0",
Value = 0
Value = 0,
TextAlignment = Eto.Forms.TextAlignment.Left.ToWpfTextAlignment()
};
Control.ValueChanged += Control_ValueChanged;
Control.Loaded += Control_Loaded;
Expand Down Expand Up @@ -128,7 +129,7 @@ private void TextBox_TextChanged(object sender, swc.TextChangedEventArgs e)
{
if (valueChanging > 0)
return;

var val = Value;
var newval = GetPreciseValue(val);
if (newval != val)
Expand Down Expand Up @@ -316,5 +317,14 @@ void UpdateRequiredDigits()
else
Control.FormatString = "0";
}

public Eto.Forms.TextAlignment TextAlignment
{
get { return Control.TextAlignment.ToEto(); }
set
{
Control.TextAlignment = value.ToWpfTextAlignment();
}
}
}
}
20 changes: 18 additions & 2 deletions src/Eto/Forms/Controls/NumericStepper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Eto.Forms;
namespace Eto.Forms;

/// <summary>
/// Control for the user to enter a numeric value (obsolete, use NumericStepper instead)
Expand Down Expand Up @@ -211,6 +211,16 @@ public bool Wrap
set => Handler.Wrap = value;
}

/// <summary>
/// Gets or sets the alignment of the text.
/// </summary>
/// <value>The text alignment.</value>
public TextAlignment TextAlignment
{
get => Handler.TextAlignment;
set => Handler.TextAlignment = value;
}

/// <summary>
/// Gets the binding for the <see cref="Value"/> property.
/// </summary>
Expand Down Expand Up @@ -371,11 +381,17 @@ public void OnValueChanged(NumericStepper widget, EventArgs e)
/// for the thousands separator, decimal separator, and currency symbol.
/// </remarks>
CultureInfo CultureInfo { get; set; }

/// <summary>
/// A value indicating whether to wrap the value after the user steps past the min or max value
/// </summary>
/// <value><c>true</c> to wrap the value when stepping past its bounds, <c>false</c> to stop</value>
bool Wrap { get; set; }

/// <summary>
/// Gets or sets the alignment of the text.
/// </summary>
/// <value>The text alignment.</value>
TextAlignment TextAlignment { get; set; }
}
}
26 changes: 22 additions & 4 deletions test/Eto.Test/Sections/Controls/NumericStepperSection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Eto.Drawing;
namespace Eto.Test.Sections.Controls
{
[Section("Controls", typeof(NumericStepper))]
Expand Down Expand Up @@ -52,14 +51,18 @@ public NumericStepperSection()

var cultureDropDown = new CultureDropDown();
cultureDropDown.SelectedValueBinding.Bind(numeric, c => c.CultureInfo);

var wrap = new CheckBox { Text = "Wrap" };
wrap.CheckedBinding.Bind(numeric, n => n.Wrap);


var increment = new NumericStepper { MaximumDecimalPlaces = 15 };
increment.ValueBinding.Bind(numeric, n => n.Increment);


var leftAligned = new NumericStepper { TextAlignment = TextAlignment.Left };
var centerAligned = new NumericStepper { TextAlignment = TextAlignment.Center };
var rightAligned = new NumericStepper { TextAlignment = TextAlignment.Right };

var options1 = new StackLayout
{
Spacing = 5,
Expand All @@ -84,6 +87,7 @@ public NumericStepperSection()
"Increment", increment
}
};

var options3 = new StackLayout
{
Spacing = 5,
Expand All @@ -96,6 +100,19 @@ public NumericStepperSection()
}
};

var options4 = new StackLayout
{
Spacing = 5,
Orientation = Orientation.Horizontal,
VerticalContentAlignment = VerticalAlignment.Center,
Items =
{
"Left Aligned", leftAligned,
"Center Aligned", centerAligned,
"Right Aligned", rightAligned
}
};

Content = new StackLayout
{
Spacing = 5,
Expand All @@ -104,6 +121,7 @@ public NumericStepperSection()
options1,
options2,
options3,
options4,
TableLayout.Horizontal(5, "FormatString", formatString, "CultureInfo", cultureDropDown),
"Result:", numeric
}
Expand Down
Loading