From aee42bad6c0f1241ce9d86136f2c4b244e1f690a Mon Sep 17 00:00:00 2001 From: Eli Arbel Date: Mon, 28 Aug 2017 19:53:40 +0300 Subject: [PATCH] Add scroll bar & slider buttons --- src/Avalonia.Controls/Primitives/RangeBase.cs | 24 +++ src/Avalonia.Controls/Primitives/ScrollBar.cs | 103 +++++++++++- src/Avalonia.Controls/Primitives/Track.cs | 102 ++++++++--- src/Avalonia.Controls/ScrollViewer.cs | 4 +- src/Avalonia.Controls/Slider.cs | 38 ++++- src/Avalonia.Themes.Default/ScrollBar.xaml | 158 ++++++++++++++---- src/Avalonia.Themes.Default/ScrollViewer.xaml | 2 + src/Avalonia.Themes.Default/Slider.xaml | 26 ++- .../Primitives/ScrollBarTests.cs | 5 +- .../Primitives/TrackTests.cs | 6 +- .../FullLayoutTests.cs | 9 + 11 files changed, 407 insertions(+), 70 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index 878f76c033..b69dbba637 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -38,6 +38,18 @@ namespace Avalonia.Controls.Primitives o => o.Value, (o, v) => o.Value = v); + /// + /// Defines the property. + /// + public static readonly StyledProperty SmallChangeProperty = + AvaloniaProperty.Register(nameof(SmallChange), 0.1); + + /// + /// Defines the property. + /// + public static readonly StyledProperty LargeChangeProperty = + AvaloniaProperty.Register(nameof(LargeChange), 1); + private double _minimum; private double _maximum = 100.0; private double _value; @@ -103,6 +115,18 @@ namespace Avalonia.Controls.Primitives } } + public double SmallChange + { + get => GetValue(SmallChangeProperty); + set => SetValue(SmallChangeProperty, value); + } + + public double LargeChange + { + get => GetValue(LargeChangeProperty); + set => SetValue(LargeChangeProperty, value); + } + /// /// Throws an exception if the double valus is NaN or Inf. /// diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 1fab5ca4ad..0f69e4e5bc 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -5,6 +5,7 @@ using System; using System.Reactive; using System.Reactive.Linq; using Avalonia.Data; +using Avalonia.Interactivity; namespace Avalonia.Controls.Primitives { @@ -31,13 +32,18 @@ namespace Avalonia.Controls.Primitives public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation)); + private Button _lineUpButton; + private Button _lineDownButton; + private Button _pageUpButton; + private Button _pageDownButton; + /// /// Initializes static members of the class. /// static ScrollBar() { - PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Vertical, ":vertical"); - PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Horizontal, ":horizontal"); + PseudoClass(OrientationProperty, o => o == Orientation.Vertical, ":vertical"); + PseudoClass(OrientationProperty, o => o == Orientation.Horizontal, ":horizontal"); } /// @@ -97,12 +103,101 @@ namespace Avalonia.Controls.Primitives return false; case ScrollBarVisibility.Auto: - var viewportSize = ViewportSize; - return double.IsNaN(viewportSize) || viewportSize < Maximum - Minimum; + return double.IsNaN(ViewportSize) || Maximum > 0; default: throw new InvalidOperationException("Invalid value for ScrollBar.Visibility."); } } + + protected override void OnTemplateApplied(TemplateAppliedEventArgs e) + { + base.OnTemplateApplied(e); + + if (_lineUpButton != null) + { + _lineUpButton.Click -= LineUpClick; + } + + if (_lineDownButton != null) + { + _lineDownButton.Click -= LineDownClick; + } + + if (_pageUpButton != null) + { + _pageUpButton.Click -= PageUpClick; + } + + if (_pageDownButton != null) + { + _pageDownButton.Click -= PageDownClick; + } + + _lineUpButton = e.NameScope.Find protected double HorizontalScrollBarViewportSize { - get { return Max((_viewport.Width / _extent.Width) * (_extent.Width - _viewport.Width), 0); } + get { return _viewport.Width; } } /// @@ -308,7 +308,7 @@ namespace Avalonia.Controls /// protected double VerticalScrollBarViewportSize { - get { return Max((_viewport.Height / _extent.Height) * (_extent.Height - _viewport.Height), 0); } + get { return _viewport.Height; } } /// diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index 6bbfb8fd8d..beef4e842e 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -33,6 +33,8 @@ namespace Avalonia.Controls // Slider required parts private Track _track; + private Button _decreaseButton; + private Button _increaseButton; /// /// Initializes static members of the class. @@ -83,7 +85,39 @@ namespace Avalonia.Controls /// protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { - _track = e.NameScope.Get("PART_Track"); + if (_decreaseButton != null) + { + _decreaseButton.Click -= DecreaseClick; + } + + if (_increaseButton != null) + { + _increaseButton.Click -= IncreaseClick; + } + + _decreaseButton = e.NameScope.Find