feat: :pressed, comparison.

This commit is contained in:
Zhang Dian
2024-01-22 15:15:51 +08:00
parent 5964108da0
commit d2f01c1257
3 changed files with 11 additions and 4 deletions

View File

@@ -52,6 +52,7 @@
<u:RangeTrack
Name="{x:Static u:RangeSlider.PART_Track}"
Grid.Row="1"
Cursor="Hand"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Orientation="{Binding Orientation, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
@@ -142,6 +143,7 @@
Ticks="{TemplateBinding Ticks}" />
<u:RangeTrack
Name="{x:Static u:RangeSlider.PART_Track}"
Cursor="Hand"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"

View File

@@ -13,12 +13,13 @@ using Avalonia.Utilities;
namespace Ursa.Controls;
[TemplatePart(PART_Track, typeof(RangeTrack))]
[PseudoClasses(PC_Horizontal, PC_Vertical)]
[PseudoClasses(PC_Horizontal, PC_Vertical, PC_Pressed)]
public class RangeSlider: TemplatedControl
{
public const string PART_Track = "PART_Track";
private const string PC_Horizontal= ":horizontal";
private const string PC_Vertical = ":vertical";
private const string PC_Pressed = ":pressed";
private RangeTrack? _track;
private bool _isDragging;
@@ -26,6 +27,8 @@ public class RangeSlider: TemplatedControl
private IDisposable? _pointerMoveDisposable;
private IDisposable? _pointerReleasedDisposable;
private const double Tolerance = 0.0001;
public static readonly StyledProperty<double> MinimumProperty = RangeTrack.MinimumProperty.AddOwner<RangeSlider>();
public double Minimum
{
@@ -144,7 +147,7 @@ public class RangeSlider: TemplatedControl
{
var oldValue = args.OldValue.Value;
var newValue = args.NewValue.Value;
if (oldValue != newValue)
if (Math.Abs(oldValue - newValue) > Tolerance)
{
RaiseEvent(new RangeValueChangedEventArgs(ValueChangedEvent, this, oldValue, newValue, isLower));
}

View File

@@ -22,7 +22,9 @@ public class RangeTrack: Control
public const string PC_Vertical = ":vertical";
private double _density;
private Vector _lastDrag;
private const double Tolerance = 0.0001;
public static readonly StyledProperty<double> MinimumProperty = AvaloniaProperty.Register<RangeTrack, double>(
nameof(Minimum), coerce: CoerceMinimum, defaultBindingMode:BindingMode.TwoWay);
@@ -165,7 +167,7 @@ public class RangeTrack: Control
{
var oldValue = args.OldValue.Value;
var newValue = args.NewValue.Value;
if (oldValue != newValue)
if (Math.Abs(oldValue - newValue) > Tolerance)
{
RaiseEvent(new RangeValueChangedEventArgs(ValueChangedEvent, this, oldValue, newValue, isLower));
}