|
@@ -1,3 +1,4 @@
|
|
|
|
+#nullable enable
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
using Terminal.Gui;
|
|
using Terminal.Gui;
|
|
|
|
|
|
@@ -5,7 +6,7 @@ using Terminal.Gui;
|
|
/// Enables the user to increase or decrease a value by clicking on the up or down buttons.
|
|
/// Enables the user to increase or decrease a value by clicking on the up or down buttons.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <remarks>
|
|
-/// Supports the following types: <see cref="int"/>, <see cref="long"/>, <see cref="float"/>, <see cref="double"/>,
|
|
|
|
|
|
+/// Supports the following types: <see cref="int"/>, <see cref="long"/>, <see cref="double"/>, <see cref="double"/>,
|
|
/// <see cref="decimal"/>.
|
|
/// <see cref="decimal"/>.
|
|
/// Supports only one digit of precision.
|
|
/// Supports only one digit of precision.
|
|
/// </remarks>
|
|
/// </remarks>
|
|
@@ -21,7 +22,7 @@ public class NumericUpDown<T> : View
|
|
{
|
|
{
|
|
Type type = typeof (T);
|
|
Type type = typeof (T);
|
|
|
|
|
|
- if (!(type == typeof (int) || type == typeof (long) || type == typeof (float) || type == typeof (double) || type == typeof (decimal)))
|
|
|
|
|
|
+ if (!(type == typeof (int) || type == typeof (long) || type == typeof (double) || type == typeof (float) || type == typeof (double) || type == typeof (decimal)))
|
|
{
|
|
{
|
|
// Support object for AllViewsTester
|
|
// Support object for AllViewsTester
|
|
if (type != typeof (object))
|
|
if (type != typeof (object))
|
|
@@ -30,6 +31,45 @@ public class NumericUpDown<T> : View
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ switch (typeof (T))
|
|
|
|
+ {
|
|
|
|
+ case { } i when i == typeof (int):
|
|
|
|
+ Minimum = (dynamic)int.MinValue;
|
|
|
|
+ Maximum = (dynamic)int.MaxValue;
|
|
|
|
+ Increment = (dynamic)1;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case { } i when i == typeof (long):
|
|
|
|
+ Minimum = (dynamic)long.MinValue;
|
|
|
|
+ Maximum = (dynamic)long.MaxValue;
|
|
|
|
+ Increment = (dynamic)1;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case { } i when i == typeof (double):
|
|
|
|
+ Minimum = (dynamic)double.MinValue;
|
|
|
|
+ Maximum = (dynamic)double.MaxValue;
|
|
|
|
+ Increment = (dynamic)1;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case { } i when i == typeof (float):
|
|
|
|
+ Minimum = (dynamic)float.MinValue;
|
|
|
|
+ Maximum = (dynamic)float.MaxValue;
|
|
|
|
+ Increment = (dynamic)1;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ case { } i when i == typeof (decimal):
|
|
|
|
+ Minimum = (dynamic)decimal.MinValue;
|
|
|
|
+ Maximum = (dynamic)decimal.MaxValue;
|
|
|
|
+ Increment = (dynamic)1;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button
|
|
Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button
|
|
Height = Dim.Auto (DimAutoStyle.Content);
|
|
Height = Dim.Auto (DimAutoStyle.Content);
|
|
|
|
|
|
@@ -86,8 +126,11 @@ public class NumericUpDown<T> : View
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- Value = (dynamic)Value + 1;
|
|
|
|
- _number.Text = Value?.ToString () ?? string.Empty;
|
|
|
|
|
|
+ if (Value is { })
|
|
|
|
+ {
|
|
|
|
+ Value = (dynamic)Value + Increment;
|
|
|
|
+ _number.Text = Value?.ToString () ?? string.Empty;
|
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
@@ -101,8 +144,11 @@ public class NumericUpDown<T> : View
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- Value = (dynamic)Value - 1;
|
|
|
|
- _number.Text = Value.ToString () ?? string.Empty;
|
|
|
|
|
|
+ if (Value is { })
|
|
|
|
+ {
|
|
|
|
+ Value = (dynamic)Value - Increment;
|
|
|
|
+ _number.Text = Value.ToString () ?? string.Empty;
|
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
@@ -112,9 +158,15 @@ public class NumericUpDown<T> : View
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
|
|
- void OnDownButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollDown); }
|
|
|
|
|
|
+ void OnDownButtonOnAccept (object s, HandledEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ InvokeCommand (Command.ScrollDown);
|
|
|
|
+ }
|
|
|
|
|
|
- void OnUpButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollUp); }
|
|
|
|
|
|
+ void OnUpButtonOnAccept (object s, HandledEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ InvokeCommand (Command.ScrollUp);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void _up_Enter (object sender, FocusEventArgs e) { throw new NotImplementedException (); }
|
|
private void _up_Enter (object sender, FocusEventArgs e) { throw new NotImplementedException (); }
|
|
@@ -143,8 +195,18 @@ public class NumericUpDown<T> : View
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (Comparer<T>.Default.Compare (value, Minimum) < 0)
|
|
|
|
+ {
|
|
|
|
+ value = Minimum;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Comparer<T>.Default.Compare (value, Maximum) > 0)
|
|
|
|
+ {
|
|
|
|
+ value = Maximum;
|
|
|
|
+ }
|
|
|
|
+
|
|
_value = value;
|
|
_value = value;
|
|
- _number.Text = _value.ToString ();
|
|
|
|
|
|
+ _number.Text = _value?.ToString () ?? string.Empty;
|
|
ValueChanged?.Invoke (this, new (ref _value));
|
|
ValueChanged?.Invoke (this, new (ref _value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -166,6 +228,39 @@ public class NumericUpDown<T> : View
|
|
/// plus the buttons. The default is 3.
|
|
/// plus the buttons. The default is 3.
|
|
/// </summary>
|
|
/// </summary>
|
|
public int Digits { get; set; } = 3;
|
|
public int Digits { get; set; } = 3;
|
|
|
|
+
|
|
|
|
+ private T _minimum;
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
|
|
+ public T Minimum
|
|
|
|
+ {
|
|
|
|
+ get { return _minimum; }
|
|
|
|
+ set { _minimum = value; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private T _maximum;
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
|
|
+ public T Maximum
|
|
|
|
+ {
|
|
|
|
+ get { return _maximum; }
|
|
|
|
+ set { _maximum = value; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private T _increment;
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
|
|
+ public T Increment
|
|
|
|
+ {
|
|
|
|
+ get { return _increment; }
|
|
|
|
+ set { _increment = value; }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|