SPARK-2360 Lean's cross threshold in the UI can be made to overflow
This commit is contained in:
1 parent
8f9321701e
commit
014c1e968a
9 files changed
+112
-37
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Windows.Controls;
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
@@ -24,5 +25,66 @@ namespace mbts.ui.controls {
|
||||
UpdateSourceTrigger = update_source_trigger
|
||||
});
|
||||
}
|
||||
|
||||
// int
|
||||
public static bool tick_up(int value, int increment, out int result) => _tick(value, value + increment, 1, out result);
|
||||
public static bool tick_down(int value, int increment, out int result) => _tick(value, value - increment, -1, out result);
|
||||
// int?
|
||||
public static bool tick_up(int? value, int increment, out int result) => value.HasValue ? _tick(value.Value, value.Value + increment, 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(int? value, int increment, out int result) => value.HasValue ? _tick(value.Value, value.Value - increment, -1, out result) : _no_op(out result);
|
||||
|
||||
// uint
|
||||
public static bool tick_up(uint value, uint increment, out uint result) => _tick(value, value + increment, 1, out result);
|
||||
public static bool tick_down(uint value, uint increment, out uint result) => _tick(value, value - increment, -1, out result);
|
||||
// uint?
|
||||
public static bool tick_up(uint? value, uint increment, out uint result) => value.HasValue ? _tick(value.Value, value.Value + increment, 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(uint? value, uint increment, out uint result) => value.HasValue ? _tick(value.Value, value.Value - increment, -1, out result) : _no_op(out result);
|
||||
|
||||
// short
|
||||
public static bool tick_up(short value, short incremented, out short result) => _tick(value, (short)(value + incremented), 1, out result);
|
||||
public static bool tick_down(short value, short incremented, out short result) => _tick(value, (short)(value - incremented), -1, out result);
|
||||
// short?
|
||||
public static bool tick_up(short? value, short increment, out short result) => value.HasValue ? _tick(value.Value, (short)(value.Value + increment), 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(short? value, short increment, out short result) => value.HasValue ? _tick(value.Value, (short)(value.Value - increment), -1, out result) : _no_op(out result);
|
||||
|
||||
// ushort
|
||||
public static bool tick_up(ushort value, ushort incremented, out ushort result) => _tick(value, (ushort)(value + incremented), 1, out result);
|
||||
public static bool tick_down(ushort value, ushort incremented, out ushort result) => _tick(value, (ushort)(value - incremented), -1, out result);
|
||||
// ushort?
|
||||
public static bool tick_up(ushort? value, ushort increment, out ushort result) => value.HasValue ? _tick(value.Value, (ushort)(value.Value + increment), 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(ushort? value, ushort increment, out ushort result) => value.HasValue ? _tick(value.Value, (ushort)(value.Value - increment), -1, out result) : _no_op(out result);
|
||||
|
||||
// long
|
||||
public static bool tick_up(long value, long incremented, out long result) => _tick(value, (long)(value + incremented), 1, out result);
|
||||
public static bool tick_down(long value, long incremented, out long result) => _tick(value, (long)(value - incremented), -1, out result);
|
||||
// long?
|
||||
public static bool tick_up(long? value, long increment, out long result) => value.HasValue ? _tick(value.Value, (long)(value.Value + increment), 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(long? value, long increment, out long result) => value.HasValue ? _tick(value.Value, (long)(value.Value - increment), -1, out result) : _no_op(out result);
|
||||
|
||||
// ulong
|
||||
public static bool tick_up(ulong value, ulong incremented, out ulong result) => _tick(value, (ulong)(value + incremented), 1, out result);
|
||||
public static bool tick_down(ulong value, ulong incremented, out ulong result) => _tick(value, (ulong)(value - incremented), -1, out result);
|
||||
// ulong?
|
||||
public static bool tick_up(ulong? value, ulong increment, out ulong result) => value.HasValue ? _tick(value.Value, (ulong)(value.Value + increment), 1, out result) : _no_op(out result);
|
||||
public static bool tick_down(ulong? value, ulong increment, out ulong result) => value.HasValue ? _tick(value.Value, (ulong)(value.Value - increment), -1, out result) : _no_op(out result);
|
||||
|
||||
// generic logic to avoid ticking across zero, in either direction.
|
||||
static bool _tick<T>(T value, T incremented, int expected_comparison, out T result) where T : struct, IComparable<T> {
|
||||
if (expected_comparison == 0) {
|
||||
result = value;
|
||||
return incremented.CompareTo(value) == 0;
|
||||
} else if ((incremented.CompareTo(value) > 0) == (expected_comparison > 0)) {
|
||||
result = incremented;
|
||||
return true;
|
||||
} else {
|
||||
result = value;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool _no_op<T>(out T result) {
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,10 +121,14 @@ namespace mbts.ui.controls {
|
||||
SetCurrentValue(ValueProperty, int.TryParse(_text_box.Text, out int i) ? i : 0);
|
||||
}
|
||||
|
||||
void _tick_up() =>
|
||||
SetCurrentValue(ValueProperty, Value + Increment);
|
||||
void _tick_up() {
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out int result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() =>
|
||||
SetCurrentValue(ValueProperty, Value - Increment);
|
||||
void _tick_down() {
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out int result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,13 +88,13 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
void _tick_up() {
|
||||
int? v = Value;
|
||||
SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out int result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() {
|
||||
int? v = Value;
|
||||
SetCurrentValue(ValueProperty, v.HasValue ? v.Value - Increment : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out int result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,14 +103,13 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
void _tick_up() {
|
||||
uint? v = Value;
|
||||
SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out uint result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() {
|
||||
uint? v = Value;
|
||||
uint inc = Increment;
|
||||
SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out uint result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,14 +101,13 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
void _tick_up() {
|
||||
ulong? v = Value;
|
||||
SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out ulong result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() {
|
||||
ulong? v = Value;
|
||||
ulong inc = Increment;
|
||||
SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out ulong result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,14 +101,13 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
void _tick_up() {
|
||||
ushort? v = Value;
|
||||
SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out ushort result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() {
|
||||
ushort? v = Value;
|
||||
ushort inc = Increment;
|
||||
SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out ushort result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,14 @@ namespace mbts.ui.controls {
|
||||
SetCurrentValue(ValueProperty, uint.TryParse(_text_box.Text, out uint u) ? u : 0u);
|
||||
}
|
||||
|
||||
void _tick_up() =>
|
||||
SetCurrentValue(ValueProperty, Value + Increment);
|
||||
void _tick_up() {
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out uint result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() =>
|
||||
SetCurrentValue(ValueProperty, Value - Increment);
|
||||
void _tick_down() {
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out uint result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,10 +95,14 @@ namespace mbts.ui.controls {
|
||||
SetCurrentValue(ValueProperty, ulong.TryParse(_text_box.Text, out ulong u) ? u : 0u);
|
||||
}
|
||||
|
||||
void _tick_up() =>
|
||||
SetCurrentValue(ValueProperty, Value + Increment);
|
||||
void _tick_up() {
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out ulong result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() =>
|
||||
SetCurrentValue(ValueProperty, Value - Increment);
|
||||
void _tick_down() {
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out ulong result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,10 +95,14 @@ namespace mbts.ui.controls {
|
||||
SetCurrentValue(ValueProperty, ushort.TryParse(_text_box.Text, out ushort u) ? u : 0u);
|
||||
}
|
||||
|
||||
void _tick_up() =>
|
||||
SetCurrentValue(ValueProperty, Value + Increment);
|
||||
void _tick_up() {
|
||||
if (TickUpDownHelper.tick_up(Value, Increment, out ushort result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
|
||||
void _tick_down() =>
|
||||
SetCurrentValue(ValueProperty, Value - Increment);
|
||||
void _tick_down() {
|
||||
if (TickUpDownHelper.tick_down(Value, Increment, out ushort result))
|
||||
SetCurrentValue(ValueProperty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user