diff --git a/src/Ursa/Controls/RangeSlider/RangeSlider.cs b/src/Ursa/Controls/RangeSlider/RangeSlider.cs new file mode 100644 index 0000000..57f0c1e --- /dev/null +++ b/src/Ursa/Controls/RangeSlider/RangeSlider.cs @@ -0,0 +1,15 @@ +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Primitives; + +namespace Ursa.Controls.RangeSlider; + +[TemplatePart(PART_DecreaseButton, typeof(Button))] +[TemplatePart(PART_IncreaseButton, typeof(Button))] +[TemplatePart(PART_Track, typeof(Track))] +public class RangeSlider: TemplatedControl +{ + public const string PART_DecreaseButton = "PART_DecreaseButton"; + public const string PART_IncreaseButton = "PART_IncreaseButton"; + public const string PART_Track = "PART_Track"; +} \ No newline at end of file diff --git a/src/Ursa/Controls/RangeSlider/RangeTrack.cs b/src/Ursa/Controls/RangeSlider/RangeTrack.cs new file mode 100644 index 0000000..5c65243 --- /dev/null +++ b/src/Ursa/Controls/RangeSlider/RangeTrack.cs @@ -0,0 +1,138 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Layout; + +namespace Ursa.Controls.RangeSlider; + +/// +/// Notice that this is not used in ScrollBar, so ViewportSize related feature is not necessary. +/// +public class RangeTrack: Control +{ + public static readonly StyledProperty MinimumProperty = AvaloniaProperty.Register( + nameof(Minimum)); + + public double Minimum + { + get => GetValue(MinimumProperty); + set => SetValue(MinimumProperty, value); + } + + public static readonly StyledProperty MaximumProperty = AvaloniaProperty.Register( + nameof(Maximum)); + + public double Maximum + { + get => GetValue(MaximumProperty); + set => SetValue(MaximumProperty, value); + } + + public static readonly StyledProperty LowerValueProperty = AvaloniaProperty.Register( + nameof(LowerValue)); + + public double LowerValue + { + get => GetValue(LowerValueProperty); + set => SetValue(LowerValueProperty, value); + } + + public static readonly StyledProperty UpperValueProperty = AvaloniaProperty.Register( + nameof(UpperValue)); + + public double UpperValue + { + get => GetValue(UpperValueProperty); + set => SetValue(UpperValueProperty, value); + } + + public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register( + nameof(Orientation)); + + public Orientation Orientation + { + get => GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } + + public static readonly StyledProperty UpperButtonProperty = AvaloniaProperty.Register( + nameof(UpperButton)); + + public RepeatButton UpperButton + { + get => GetValue(UpperButtonProperty); + set => SetValue(UpperButtonProperty, value); + } + + public static readonly StyledProperty LowerButtonProperty = AvaloniaProperty.Register( + nameof(LowerButton)); + + public Button? LowerButton + { + get => GetValue(LowerButtonProperty); + set => SetValue(LowerButtonProperty, value); + } + + public static readonly StyledProperty InnerButtonProperty = AvaloniaProperty.Register( + nameof(InnerButton)); + + public Button? InnerButton + { + get => GetValue(InnerButtonProperty); + set => SetValue(InnerButtonProperty, value); + } + + public static readonly StyledProperty UpperThumbProperty = AvaloniaProperty.Register( + nameof(UpperThumb)); + + public Thumb? UpperThumb + { + get => GetValue(UpperThumbProperty); + set => SetValue(UpperThumbProperty, value); + } + + public static readonly StyledProperty LowerThumbProperty = AvaloniaProperty.Register( + nameof(LowerThumb)); + + public Thumb? LowerThumb + { + get => GetValue(LowerThumbProperty); + set => SetValue(LowerThumbProperty, value); + } + + public static readonly StyledProperty IsDirectionReversedProperty = AvaloniaProperty.Register( + nameof(IsDirectionReversed)); + + public bool IsDirectionReversed + { + get => GetValue(IsDirectionReversedProperty); + set => SetValue(IsDirectionReversedProperty, value); + } + + static RangeTrack() + { + AffectsArrange(MinimumProperty, MaximumProperty, LowerValueProperty, UpperValueProperty, OrientationProperty, IsDirectionReversedProperty); + } + + protected override Size MeasureOverride(Size availableSize) + { + var desiredSize = new Size(0.0, 0.0); + if (LowerThumb is not null && UpperThumb is not null) + { + LowerThumb.Measure(availableSize); + UpperThumb.Measure(availableSize); + if (Orientation == Orientation.Horizontal) + { + desiredSize = new Size(LowerThumb.DesiredSize.Width + UpperThumb.DesiredSize.Width, + Math.Max(LowerThumb.DesiredSize.Height, UpperThumb.DesiredSize.Height)); + } + else + { + desiredSize = new Size(Math.Max(LowerThumb.DesiredSize.Width, UpperThumb.DesiredSize.Width), + LowerThumb.DesiredSize.Height + UpperThumb.DesiredSize.Height); + } + } + + return desiredSize; + } +} \ No newline at end of file