Merge branch 'main' of github.com:AlvinRey/Ursa.Avalonia into TimeBox
This commit is contained in:
@@ -210,7 +210,7 @@ public class IPv4Box: TemplatedControl
|
|||||||
if (!char.IsNumber(s![0])) return;
|
if (!char.IsNumber(s![0])) return;
|
||||||
if (_currentActivePresenter != null)
|
if (_currentActivePresenter != null)
|
||||||
{
|
{
|
||||||
int index = _currentActivePresenter.CaretIndex;
|
int index = Math.Min(_currentActivePresenter.CaretIndex, _currentActivePresenter.Text.Length);
|
||||||
string? oldText = _currentActivePresenter.Text;
|
string? oldText = _currentActivePresenter.Text;
|
||||||
if (oldText is null)
|
if (oldText is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,9 +25,17 @@ public class NumericIntUpDown : NumericUpDownBase<int>
|
|||||||
|
|
||||||
protected override int Zero => 0;
|
protected override int Zero => 0;
|
||||||
|
|
||||||
protected override int? Add(int? a, int? b) => a + b;
|
protected override int? Add(int? a, int? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return result < Value ? Maximum : result;
|
||||||
|
}
|
||||||
|
|
||||||
protected override int? Minus(int? a, int? b) => a - b;
|
protected override int? Minus(int? a, int? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return result > Value ? Minimum : result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericUIntUpDown : NumericUpDownBase<uint>
|
public class NumericUIntUpDown : NumericUpDownBase<uint>
|
||||||
@@ -53,9 +61,17 @@ public class NumericUIntUpDown : NumericUpDownBase<uint>
|
|||||||
|
|
||||||
protected override uint Zero => 0;
|
protected override uint Zero => 0;
|
||||||
|
|
||||||
protected override uint? Add(uint? a, uint? b) => a + b;
|
protected override uint? Add(uint? a, uint? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return result < Value ? Maximum : result;
|
||||||
|
}
|
||||||
|
|
||||||
protected override uint? Minus(uint? a, uint? b) => a - b;
|
protected override uint? Minus(uint? a, uint? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return result > Value ? Minimum : result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericDoubleUpDown : NumericUpDownBase<double>
|
public class NumericDoubleUpDown : NumericUpDownBase<double>
|
||||||
@@ -99,9 +115,17 @@ public class NumericByteUpDown : NumericUpDownBase<byte>
|
|||||||
|
|
||||||
protected override byte Zero => 0;
|
protected override byte Zero => 0;
|
||||||
|
|
||||||
protected override byte? Add(byte? a, byte? b) => (byte?)(a + b);
|
protected override byte? Add(byte? a, byte? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return (byte?)(result < Value ? Maximum : result);
|
||||||
|
}
|
||||||
|
|
||||||
protected override byte? Minus(byte? a, byte? b) => (byte?)(a - b);
|
protected override byte? Minus(byte? a, byte? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return (byte?)(result > Value ? Minimum : result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericSByteUpDown : NumericUpDownBase<sbyte>
|
public class NumericSByteUpDown : NumericUpDownBase<sbyte>
|
||||||
@@ -122,9 +146,17 @@ public class NumericSByteUpDown : NumericUpDownBase<sbyte>
|
|||||||
|
|
||||||
protected override sbyte Zero => 0;
|
protected override sbyte Zero => 0;
|
||||||
|
|
||||||
protected override sbyte? Add(sbyte? a, sbyte? b) => (sbyte?)(a + b);
|
protected override sbyte? Add(sbyte? a, sbyte? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return (sbyte?)(result < Value ? Maximum : result);
|
||||||
|
}
|
||||||
|
|
||||||
protected override sbyte? Minus(sbyte? a, sbyte? b) => (sbyte?)(a - b);
|
protected override sbyte? Minus(sbyte? a, sbyte? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return (sbyte?)(result > Value ? Minimum : result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericShortUpDown : NumericUpDownBase<short>
|
public class NumericShortUpDown : NumericUpDownBase<short>
|
||||||
@@ -145,9 +177,17 @@ public class NumericShortUpDown : NumericUpDownBase<short>
|
|||||||
|
|
||||||
protected override short Zero => 0;
|
protected override short Zero => 0;
|
||||||
|
|
||||||
protected override short? Add(short? a, short? b) => (short?)(a + b);
|
protected override short? Add(short? a, short? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return (short?)(result < Value ? Maximum : result);
|
||||||
|
}
|
||||||
|
|
||||||
protected override short? Minus(short? a, short? b) => (short?)(a - b);
|
protected override short? Minus(short? a, short? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return (short?)(result > Value ? Minimum : result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
||||||
@@ -168,9 +208,17 @@ public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
|||||||
|
|
||||||
protected override ushort Zero => 0;
|
protected override ushort Zero => 0;
|
||||||
|
|
||||||
protected override ushort? Add(ushort? a, ushort? b) => (ushort?)(a + b);
|
protected override ushort? Add(ushort? a, ushort? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return (ushort?)(result < Value ? Maximum : result);
|
||||||
|
}
|
||||||
|
|
||||||
protected override ushort? Minus(ushort? a, ushort? b) => (ushort?)(a - b);
|
protected override ushort? Minus(ushort? a, ushort? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return (ushort?)(result > Value ? Minimum : result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericLongUpDown : NumericUpDownBase<long>
|
public class NumericLongUpDown : NumericUpDownBase<long>
|
||||||
@@ -191,9 +239,17 @@ public class NumericLongUpDown : NumericUpDownBase<long>
|
|||||||
|
|
||||||
protected override long Zero => 0;
|
protected override long Zero => 0;
|
||||||
|
|
||||||
protected override long? Add(long? a, long? b) => a + b;
|
protected override long? Add(long? a, long? b)
|
||||||
|
{
|
||||||
|
var result = a + b;
|
||||||
|
return result < Value ? Maximum : result;
|
||||||
|
}
|
||||||
|
|
||||||
protected override long? Minus(long? a, long? b) => a - b;
|
protected override long? Minus(long? a, long? b)
|
||||||
|
{
|
||||||
|
var result = a - b;
|
||||||
|
return result > Value ? Minimum : result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NumericULongUpDown : NumericUpDownBase<ulong>
|
public class NumericULongUpDown : NumericUpDownBase<ulong>
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
protected abstract void SetValidSpinDirection();
|
protected abstract void SetValidSpinDirection();
|
||||||
|
|
||||||
protected abstract void Increase();
|
protected abstract void Increase();
|
||||||
|
|
||||||
protected abstract void Decrease();
|
protected abstract void Decrease();
|
||||||
|
|
||||||
protected virtual bool CommitInput(bool forceTextUpdate = false)
|
protected virtual bool CommitInput(bool forceTextUpdate = false)
|
||||||
@@ -466,7 +467,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<Pagination, ICommand?>(
|
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, ICommand?>(
|
||||||
nameof(Command));
|
nameof(Command));
|
||||||
|
|
||||||
public ICommand? Command
|
public ICommand? Command
|
||||||
@@ -476,7 +477,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<object?> CommandParameterProperty =
|
public static readonly StyledProperty<object?> CommandParameterProperty =
|
||||||
AvaloniaProperty.Register<Pagination, object?>(nameof(CommandParameter));
|
AvaloniaProperty.Register<NumericUpDownBase<T>, object?>(nameof(CommandParameter));
|
||||||
|
|
||||||
public object? CommandParameter
|
public object? CommandParameter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ public class RangeSlider: TemplatedControl
|
|||||||
var isHorizontal = Orientation == Orientation.Horizontal;
|
var isHorizontal = Orientation == Orientation.Horizontal;
|
||||||
var lowerThumbPosition = isHorizontal? _track?.LowerThumb?.Bounds.Center.X : _track?.LowerThumb?.Bounds.Center.Y;
|
var lowerThumbPosition = isHorizontal? _track?.LowerThumb?.Bounds.Center.X : _track?.LowerThumb?.Bounds.Center.Y;
|
||||||
var upperThumbPosition = isHorizontal? _track?.UpperThumb?.Bounds.Center.X : _track?.UpperThumb?.Bounds.Center.Y;
|
var upperThumbPosition = isHorizontal? _track?.UpperThumb?.Bounds.Center.X : _track?.UpperThumb?.Bounds.Center.Y;
|
||||||
|
var mid = isHorizontal? _track?.Bounds.Center.X : _track?.Bounds.Center.Y;
|
||||||
var pointerPosition = isHorizontal? point.Position.X : point.Position.Y;
|
var pointerPosition = isHorizontal? point.Position.X : point.Position.Y;
|
||||||
|
|
||||||
var lowerDistance = Math.Abs((lowerThumbPosition ?? 0) - pointerPosition);
|
var lowerDistance = Math.Abs((lowerThumbPosition ?? 0) - pointerPosition);
|
||||||
@@ -280,10 +281,12 @@ public class RangeSlider: TemplatedControl
|
|||||||
{
|
{
|
||||||
return _track?.LowerThumb;
|
return _track?.LowerThumb;
|
||||||
}
|
}
|
||||||
else
|
if(lowerDistance>upperDistance)
|
||||||
{
|
{
|
||||||
return _track?.UpperThumb;
|
return _track?.UpperThumb;
|
||||||
}
|
}
|
||||||
|
if (IsDirectionReversed) return pointerPosition < mid ? _track?.LowerThumb : _track?.UpperThumb;
|
||||||
|
return pointerPosition > mid ? _track?.LowerThumb : _track?.UpperThumb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double GetValueByPoint(PointerPoint point)
|
private double GetValueByPoint(PointerPoint point)
|
||||||
|
|||||||
Reference in New Issue
Block a user