From 5fbf15be7e468fdc2095d2ada507b30ace4e47c1 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 17 Jun 2020 19:07:52 -0300 Subject: [PATCH] use template properties class. --- src/Avalonia.Controls/ProgressBar.cs | 178 ++++++++++---------- src/Avalonia.Themes.Fluent/ProgressBar.xaml | 40 ++--- 2 files changed, 112 insertions(+), 106 deletions(-) diff --git a/src/Avalonia.Controls/ProgressBar.cs b/src/Avalonia.Controls/ProgressBar.cs index fc59f45650..d29e878b73 100644 --- a/src/Avalonia.Controls/ProgressBar.cs +++ b/src/Avalonia.Controls/ProgressBar.cs @@ -9,12 +9,88 @@ namespace Avalonia.Controls /// public class ProgressBar : RangeBase { - private double _Container2Width; - private double _ContainerWidth; - private double _containerAnimationStartPosition; - private double _containerAnimationEndPosition; - private double _container2AnimationStartPosition; - private double _container2AnimationEndPosition; + public class ProgressBarTemplateProperties : AvaloniaObject + { + private double _Container2Width; + private double _ContainerWidth; + private double _containerAnimationStartPosition; + private double _containerAnimationEndPosition; + private double _container2AnimationStartPosition; + private double _container2AnimationEndPosition; + + public static readonly DirectProperty ContainerAnimationStartPositionProperty = + AvaloniaProperty.RegisterDirect( + nameof(ContainerAnimationStartPosition), + p => p.ContainerAnimationStartPosition, + (p, o) => p.ContainerAnimationStartPosition = o, 0d); + + public static readonly DirectProperty ContainerAnimationEndPositionProperty = + AvaloniaProperty.RegisterDirect( + nameof(ContainerAnimationEndPosition), + p => p.ContainerAnimationEndPosition, + (p, o) => p.ContainerAnimationEndPosition = o, 0d); + + public static readonly DirectProperty Container2AnimationStartPositionProperty = + AvaloniaProperty.RegisterDirect( + nameof(Container2AnimationStartPosition), + p => p.Container2AnimationStartPosition, + (p, o) => p.Container2AnimationStartPosition = o, 0d); + + public static readonly DirectProperty Container2AnimationEndPositionProperty = + AvaloniaProperty.RegisterDirect( + nameof(Container2AnimationEndPosition), + p => p.Container2AnimationEndPosition, + (p, o) => p.Container2AnimationEndPosition = o); + + public static readonly DirectProperty Container2WidthProperty = + AvaloniaProperty.RegisterDirect( + nameof(Container2Width), + p => p.Container2Width, + (p, o) => p.Container2Width = o); + + public static readonly DirectProperty ContainerWidthProperty = + AvaloniaProperty.RegisterDirect( + nameof(ContainerWidth), + p => p.ContainerWidth, + (p, o) => p.ContainerWidth = o); + + public double ContainerAnimationStartPosition + { + get => _containerAnimationStartPosition; + set => SetAndRaise(ContainerAnimationStartPositionProperty, ref _containerAnimationStartPosition, value); + } + + public double ContainerAnimationEndPosition + { + get => _containerAnimationEndPosition; + set => SetAndRaise(ContainerAnimationEndPositionProperty, ref _containerAnimationEndPosition, value); + } + + public double Container2AnimationStartPosition + { + get => _container2AnimationStartPosition; + set => SetAndRaise(Container2AnimationStartPositionProperty, ref _container2AnimationStartPosition, value); + } + + public double Container2Width + { + get => _Container2Width; + set => SetAndRaise(Container2WidthProperty, ref _Container2Width, value); + } + + public double ContainerWidth + { + get => _ContainerWidth; + set => SetAndRaise(ContainerWidthProperty, ref _ContainerWidth, value); + } + + public double Container2AnimationEndPosition + { + get => _container2AnimationEndPosition; + set => SetAndRaise(Container2AnimationEndPositionProperty, ref _container2AnimationEndPosition, value); + } + } + private Border _indicator; public static readonly StyledProperty IsIndeterminateProperty = @@ -24,43 +100,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(ShowProgressText)); public static readonly StyledProperty OrientationProperty = - AvaloniaProperty.Register(nameof(Orientation), Orientation.Horizontal); - - public static readonly DirectProperty ContainerAnimationStartPositionProperty = - AvaloniaProperty.RegisterDirect( - nameof(ContainerAnimationStartPosition), - p => p.ContainerAnimationStartPosition, - (p, o) => p.ContainerAnimationStartPosition = o, 0d); - - public static readonly DirectProperty ContainerAnimationEndPositionProperty = - AvaloniaProperty.RegisterDirect( - nameof(ContainerAnimationEndPosition), - p => p.ContainerAnimationEndPosition, - (p, o) => p.ContainerAnimationEndPosition = o, 0d); - - public static readonly DirectProperty Container2AnimationStartPositionProperty = - AvaloniaProperty.RegisterDirect( - nameof(Container2AnimationStartPosition), - p => p.Container2AnimationStartPosition, - (p, o) => p.Container2AnimationStartPosition = o, 0d); - - public static readonly DirectProperty Container2AnimationEndPositionProperty = - AvaloniaProperty.RegisterDirect( - nameof(Container2AnimationEndPosition), - p => p.Container2AnimationEndPosition, - (p, o) => p.Container2AnimationEndPosition = o); - - public static readonly DirectProperty Container2WidthProperty = - AvaloniaProperty.RegisterDirect( - nameof(Container2Width), - p => p.Container2Width, - (p, o) => p.Container2Width = o); - - public static readonly DirectProperty ContainerWidthProperty = - AvaloniaProperty.RegisterDirect( - nameof(ContainerWidth), - p => p.ContainerWidth, - (p, o) => p.ContainerWidth = o); + AvaloniaProperty.Register(nameof(Orientation), Orientation.Horizontal); static ProgressBar() { @@ -73,6 +113,8 @@ namespace Avalonia.Controls UpdatePseudoClasses(IsIndeterminate, Orientation); } + public ProgressBarTemplateProperties TemplateProperties { get; } = new ProgressBarTemplateProperties(); + public bool IsIndeterminate { get => GetValue(IsIndeterminateProperty); @@ -89,43 +131,7 @@ namespace Avalonia.Controls { get => GetValue(OrientationProperty); set => SetValue(OrientationProperty, value); - } - - public double ContainerAnimationStartPosition - { - get => _containerAnimationStartPosition; - set => SetAndRaise(ContainerAnimationStartPositionProperty, ref _containerAnimationStartPosition, value); - } - - public double ContainerAnimationEndPosition - { - get => _containerAnimationEndPosition; - set => SetAndRaise(ContainerAnimationEndPositionProperty, ref _containerAnimationEndPosition, value); - } - - public double Container2AnimationStartPosition - { - get => _container2AnimationStartPosition; - set => SetAndRaise(Container2AnimationStartPositionProperty, ref _container2AnimationStartPosition, value); - } - - public double Container2Width - { - get => _Container2Width; - set => SetAndRaise(Container2WidthProperty, ref _Container2Width, value); - } - - public double ContainerWidth - { - get => _ContainerWidth; - set => SetAndRaise(ContainerWidthProperty, ref _ContainerWidth, value); - } - - public double Container2AnimationEndPosition - { - get => _container2AnimationEndPosition; - set => SetAndRaise(Container2AnimationEndPositionProperty, ref _container2AnimationEndPosition, value); - } + } /// protected override Size ArrangeOverride(Size finalSize) @@ -168,14 +174,14 @@ namespace Avalonia.Controls var barIndicatorWidth = dim * 0.4; // Indicator width at 40% of ProgressBar var barIndicatorWidth2 = dim * 0.6; // Indicator width at 60% of ProgressBar - ContainerWidth = barIndicatorWidth; - Container2Width = barIndicatorWidth2; + TemplateProperties.ContainerWidth = barIndicatorWidth; + TemplateProperties.Container2Width = barIndicatorWidth2; - ContainerAnimationStartPosition = barIndicatorWidth * -1.8; // Position at -180% - ContainerAnimationEndPosition = barIndicatorWidth * 3.0; // Position at 300% + TemplateProperties.ContainerAnimationStartPosition = barIndicatorWidth * -1.8; // Position at -180% + TemplateProperties.ContainerAnimationEndPosition = barIndicatorWidth * 3.0; // Position at 300% - Container2AnimationStartPosition = barIndicatorWidth2 * -1.5; // Position at -150% - Container2AnimationEndPosition = barIndicatorWidth2 * 1.66; // Position at 166% + TemplateProperties.Container2AnimationStartPosition = barIndicatorWidth2 * -1.5; // Position at -150% + TemplateProperties.Container2AnimationEndPosition = barIndicatorWidth2 * 1.66; // Position at 166% var padding = Padding; var rectangle = new RectangleGeometry( diff --git a/src/Avalonia.Themes.Fluent/ProgressBar.xaml b/src/Avalonia.Themes.Fluent/ProgressBar.xaml index e60029a89a..6e2b4138b3 100644 --- a/src/Avalonia.Themes.Fluent/ProgressBar.xaml +++ b/src/Avalonia.Themes.Fluent/ProgressBar.xaml @@ -87,13 +87,13 @@ - + - + - + @@ -102,13 +102,13 @@ - + - + - + @@ -117,13 +117,13 @@ - + - + - + @@ -132,46 +132,46 @@ - + - + - +