mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
DraggableNumberBox - Fixed min and max value
This commit is contained in:
parent
4703c0890a
commit
0e3d26e89e
@ -17,7 +17,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="0.10.15" />
|
<PackageReference Include="Avalonia" Version="0.10.15" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.15"/>
|
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.15" />
|
||||||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.15" />
|
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.15" />
|
||||||
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.10.14" />
|
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.10.14" />
|
||||||
<PackageReference Include="DynamicData" Version="7.8.6" />
|
<PackageReference Include="DynamicData" Version="7.8.6" />
|
||||||
|
|||||||
@ -25,15 +25,13 @@
|
|||||||
<Panel>
|
<Panel>
|
||||||
<controls:NumberBox Name="NumberBox"
|
<controls:NumberBox Name="NumberBox"
|
||||||
AcceptsExpression="True"
|
AcceptsExpression="True"
|
||||||
Value="{Binding $parent[sharedControls:DraggableNumberBox].Value}"
|
|
||||||
Minimum="{Binding $parent[sharedControls:DraggableNumberBox].Minimum}"
|
|
||||||
Maximum="{Binding $parent[sharedControls:DraggableNumberBox].Maximum}"
|
|
||||||
LargeChange="{Binding $parent[sharedControls:DraggableNumberBox].LargeChange}"
|
LargeChange="{Binding $parent[sharedControls:DraggableNumberBox].LargeChange}"
|
||||||
SmallChange="{Binding $parent[sharedControls:DraggableNumberBox].SmallChange}"
|
SmallChange="{Binding $parent[sharedControls:DraggableNumberBox].SmallChange}"
|
||||||
SimpleNumberFormat="{Binding $parent[sharedControls:DraggableNumberBox].SimpleNumberFormat}"
|
SimpleNumberFormat="{Binding $parent[sharedControls:DraggableNumberBox].SimpleNumberFormat}"
|
||||||
attachedProperties:NumberBoxAssist.PrefixText="{Binding $parent[sharedControls:DraggableNumberBox].Prefix}"
|
attachedProperties:NumberBoxAssist.PrefixText="{Binding $parent[sharedControls:DraggableNumberBox].Prefix}"
|
||||||
attachedProperties:NumberBoxAssist.SuffixText="{Binding $parent[sharedControls:DraggableNumberBox].Suffix}"
|
attachedProperties:NumberBoxAssist.SuffixText="{Binding $parent[sharedControls:DraggableNumberBox].Suffix}"
|
||||||
HorizontalAlignment="{Binding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}" />
|
HorizontalAlignment="{Binding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}"
|
||||||
|
ValueChanged="NumberBox_OnValueChanged"/>
|
||||||
<Rectangle Name="DragCollider" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="Transparent"></Rectangle>
|
<Rectangle Name="DragCollider" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="Transparent"></Rectangle>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|
||||||
|
|||||||
@ -19,17 +19,31 @@ public class DraggableNumberBox : UserControl
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="Value" /> property.
|
/// Defines the <see cref="Value" /> property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly StyledProperty<double> ValueProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Value), defaultBindingMode: BindingMode.TwoWay);
|
public static readonly StyledProperty<double> ValueProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Value), defaultBindingMode: BindingMode.TwoWay, notifying: ValueChanged);
|
||||||
|
|
||||||
|
private static void ValueChanged(IAvaloniaObject sender, bool before)
|
||||||
|
{
|
||||||
|
if (before)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DraggableNumberBox draggable = (DraggableNumberBox) sender;
|
||||||
|
if (!(Math.Abs(draggable._numberBox.Value - draggable.Value) > 0.00001))
|
||||||
|
return;
|
||||||
|
|
||||||
|
draggable._updating = true;
|
||||||
|
draggable._numberBox.Value = draggable.Value;
|
||||||
|
draggable._updating = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="Minimum" /> property.
|
/// Defines the <see cref="Minimum" /> property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly StyledProperty<double> MinimumProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Minimum));
|
public static readonly StyledProperty<double> MinimumProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Minimum), double.MinValue);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="Maximum" /> property.
|
/// Defines the <see cref="Maximum" /> property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly StyledProperty<double> MaximumProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Maximum));
|
public static readonly StyledProperty<double> MaximumProperty = AvaloniaProperty.Register<DraggableNumberBox, double>(nameof(Maximum), double.MaxValue);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="LargeChange" /> property.
|
/// Defines the <see cref="LargeChange" /> property.
|
||||||
@ -61,6 +75,7 @@ public class DraggableNumberBox : UserControl
|
|||||||
private double _lastX;
|
private double _lastX;
|
||||||
private bool _moved;
|
private bool _moved;
|
||||||
private double _startX;
|
private double _startX;
|
||||||
|
private bool _updating;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="DraggableNumberBox" /> class.
|
/// Creates a new instance of the <see cref="DraggableNumberBox" /> class.
|
||||||
@ -69,6 +84,7 @@ public class DraggableNumberBox : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_numberBox = this.Get<NumberBox>("NumberBox");
|
_numberBox = this.Get<NumberBox>("NumberBox");
|
||||||
|
_numberBox.Value = Value;
|
||||||
|
|
||||||
PointerPressed += OnPointerPressed;
|
PointerPressed += OnPointerPressed;
|
||||||
PointerMoved += OnPointerMoved;
|
PointerMoved += OnPointerMoved;
|
||||||
@ -237,4 +253,25 @@ public class DraggableNumberBox : UserControl
|
|||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
|
||||||
|
{
|
||||||
|
if (_updating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (args.NewValue < Minimum)
|
||||||
|
{
|
||||||
|
_numberBox.Value = Minimum;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.NewValue > Maximum)
|
||||||
|
{
|
||||||
|
_numberBox.Value = Maximum;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.Abs(Value - _numberBox.Value) > 0.00001)
|
||||||
|
Value = _numberBox.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user