From fad2e317ba413b0624de7600ebc1bdeaa02a3272 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 7 Sep 2018 02:13:57 +0200 Subject: [PATCH 01/11] Make AffectsMeasure/Arrange/Render typed. --- src/Avalonia.Controls/Border.cs | 4 ++-- src/Avalonia.Controls/Decorator.cs | 2 +- src/Avalonia.Controls/DrawingPresenter.cs | 6 ++--- src/Avalonia.Controls/Image.cs | 3 +-- .../Presenters/ContentPresenter.cs | 4 ++-- .../Presenters/ScrollContentPresenter.cs | 2 +- .../Presenters/TextPresenter.cs | 2 +- .../Primitives/AccessText.cs | 2 +- src/Avalonia.Controls/Primitives/Track.cs | 2 +- src/Avalonia.Controls/Shapes/Shape.cs | 5 ++--- src/Avalonia.Controls/StackPanel.cs | 4 ++-- src/Avalonia.Controls/TabControl.cs | 2 +- src/Avalonia.Controls/TextBlock.cs | 9 ++++---- src/Avalonia.Controls/TopLevel.cs | 2 +- src/Avalonia.Controls/WrapPanel.cs | 2 +- src/Avalonia.Layout/Layoutable.cs | 22 +++++++++++-------- src/Avalonia.Visuals/Visual.cs | 12 +++++----- 17 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/Avalonia.Controls/Border.cs b/src/Avalonia.Controls/Border.cs index 5f84421c64..8b2a45b090 100644 --- a/src/Avalonia.Controls/Border.cs +++ b/src/Avalonia.Controls/Border.cs @@ -43,8 +43,8 @@ namespace Avalonia.Controls /// static Border() { - AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty); - AffectsMeasure(BorderThicknessProperty); + AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty); + AffectsMeasure(BorderThicknessProperty); } /// diff --git a/src/Avalonia.Controls/Decorator.cs b/src/Avalonia.Controls/Decorator.cs index 389cf66d34..15651b918e 100644 --- a/src/Avalonia.Controls/Decorator.cs +++ b/src/Avalonia.Controls/Decorator.cs @@ -28,7 +28,7 @@ namespace Avalonia.Controls /// static Decorator() { - AffectsMeasure(ChildProperty, PaddingProperty); + AffectsMeasure(ChildProperty, PaddingProperty); ChildProperty.Changed.AddClassHandler(x => x.ChildChanged); } diff --git a/src/Avalonia.Controls/DrawingPresenter.cs b/src/Avalonia.Controls/DrawingPresenter.cs index af3665fabc..34ce598218 100644 --- a/src/Avalonia.Controls/DrawingPresenter.cs +++ b/src/Avalonia.Controls/DrawingPresenter.cs @@ -8,8 +8,8 @@ namespace Avalonia.Controls { static DrawingPresenter() { - AffectsMeasure(DrawingProperty); - AffectsRender(DrawingProperty); + AffectsMeasure(DrawingProperty); + AffectsRender(DrawingProperty); } public static readonly StyledProperty DrawingProperty = @@ -56,4 +56,4 @@ namespace Avalonia.Controls } } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Controls/Image.cs b/src/Avalonia.Controls/Image.cs index f146e3571c..802b700a07 100644 --- a/src/Avalonia.Controls/Image.cs +++ b/src/Avalonia.Controls/Image.cs @@ -25,8 +25,7 @@ namespace Avalonia.Controls static Image() { - AffectsRender(SourceProperty); - AffectsRender(StretchProperty); + AffectsRender(SourceProperty, StretchProperty); } /// diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs index 6badf91367..8d703cfc1c 100644 --- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs @@ -90,8 +90,8 @@ namespace Avalonia.Controls.Presenters /// static ContentPresenter() { - AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty); - AffectsMeasure(BorderThicknessProperty, PaddingProperty); + AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty); + AffectsMeasure(BorderThicknessProperty, PaddingProperty); ContentProperty.Changed.AddClassHandler(x => x.ContentChanged); ContentTemplateProperty.Changed.AddClassHandler(x => x.ContentChanged); TemplatedParentProperty.Changed.AddClassHandler(x => x.TemplatedParentChanged); diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index 2ef7941b55..c05c1672f8 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -72,7 +72,7 @@ namespace Avalonia.Controls.Presenters { ClipToBoundsProperty.OverrideDefaultValue(typeof(ScrollContentPresenter), true); ChildProperty.Changed.AddClassHandler(x => x.ChildChanged); - AffectsArrange(OffsetProperty); + AffectsArrange(OffsetProperty); } /// diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index a30d9bfc48..f73a335de5 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -38,7 +38,7 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { - AffectsRender(PasswordCharProperty); + AffectsRender(PasswordCharProperty); } public TextPresenter() diff --git a/src/Avalonia.Controls/Primitives/AccessText.cs b/src/Avalonia.Controls/Primitives/AccessText.cs index 32a0efc440..5adc8d2448 100644 --- a/src/Avalonia.Controls/Primitives/AccessText.cs +++ b/src/Avalonia.Controls/Primitives/AccessText.cs @@ -28,7 +28,7 @@ namespace Avalonia.Controls.Primitives /// static AccessText() { - AffectsRender(ShowAccessKeyProperty); + AffectsRender(ShowAccessKeyProperty); } /// diff --git a/src/Avalonia.Controls/Primitives/Track.cs b/src/Avalonia.Controls/Primitives/Track.cs index 648fe5f4b0..8ff3ced770 100644 --- a/src/Avalonia.Controls/Primitives/Track.cs +++ b/src/Avalonia.Controls/Primitives/Track.cs @@ -42,7 +42,7 @@ namespace Avalonia.Controls.Primitives ThumbProperty.Changed.AddClassHandler(x => x.ThumbChanged); IncreaseButtonProperty.Changed.AddClassHandler(x => x.ButtonChanged); DecreaseButtonProperty.Changed.AddClassHandler(x => x.ButtonChanged); - AffectsArrange(MinimumProperty, MaximumProperty, ValueProperty, OrientationProperty); + AffectsArrange(MinimumProperty, MaximumProperty, ValueProperty, OrientationProperty); } public double Minimum diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index 604051ef28..f77c43acd0 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -30,11 +30,10 @@ namespace Avalonia.Controls.Shapes private Geometry _renderedGeometry; bool _calculateTransformOnArrange = false; - static Shape() { - AffectsMeasure(StretchProperty, StrokeThicknessProperty); - AffectsRender(FillProperty, StrokeProperty, StrokeDashArrayProperty); + AffectsMeasure(StretchProperty, StrokeThicknessProperty); + AffectsRender(FillProperty, StrokeProperty, StrokeDashArrayProperty); } public Geometry DefiningGeometry diff --git a/src/Avalonia.Controls/StackPanel.cs b/src/Avalonia.Controls/StackPanel.cs index 645cdbd926..df0c113cc0 100644 --- a/src/Avalonia.Controls/StackPanel.cs +++ b/src/Avalonia.Controls/StackPanel.cs @@ -29,8 +29,8 @@ namespace Avalonia.Controls /// static StackPanel() { - AffectsMeasure(SpacingProperty); - AffectsMeasure(OrientationProperty); + AffectsMeasure(SpacingProperty); + AffectsMeasure(OrientationProperty); } /// diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index 70cf8b4e05..3aae256858 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -44,7 +44,7 @@ namespace Avalonia.Controls { SelectionModeProperty.OverrideDefaultValue(SelectionMode.AlwaysSelected); FocusableProperty.OverrideDefaultValue(false); - AffectsMeasure(TabStripPlacementProperty); + AffectsMeasure(TabStripPlacementProperty); } /// diff --git a/src/Avalonia.Controls/TextBlock.cs b/src/Avalonia.Controls/TextBlock.cs index e91d2e8fa7..541e55625a 100644 --- a/src/Avalonia.Controls/TextBlock.cs +++ b/src/Avalonia.Controls/TextBlock.cs @@ -99,10 +99,11 @@ namespace Avalonia.Controls static TextBlock() { ClipToBoundsProperty.OverrideDefaultValue(true); - AffectsRender(ForegroundProperty); - AffectsRender(FontWeightProperty); - AffectsRender(FontSizeProperty); - AffectsRender(FontStyleProperty); + AffectsRender( + ForegroundProperty, + FontWeightProperty, + FontSizeProperty, + FontStyleProperty); } /// diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 1161ded25f..5f8eac1fe3 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -59,7 +59,7 @@ namespace Avalonia.Controls /// static TopLevel() { - AffectsMeasure(ClientSizeProperty); + AffectsMeasure(ClientSizeProperty); } /// diff --git a/src/Avalonia.Controls/WrapPanel.cs b/src/Avalonia.Controls/WrapPanel.cs index 8ee0636124..597734d400 100644 --- a/src/Avalonia.Controls/WrapPanel.cs +++ b/src/Avalonia.Controls/WrapPanel.cs @@ -30,7 +30,7 @@ namespace Avalonia.Controls /// static WrapPanel() { - AffectsMeasure(OrientationProperty); + AffectsMeasure(OrientationProperty); } /// diff --git a/src/Avalonia.Layout/Layoutable.cs b/src/Avalonia.Layout/Layoutable.cs index 54bdbb5d48..b8b24e6d31 100644 --- a/src/Avalonia.Layout/Layoutable.cs +++ b/src/Avalonia.Layout/Layoutable.cs @@ -140,7 +140,7 @@ namespace Avalonia.Layout /// static Layoutable() { - AffectsMeasure( + AffectsMeasure( IsVisibleProperty, WidthProperty, HeightProperty, @@ -427,11 +427,12 @@ namespace Avalonia.Layout /// After a call to this method in a control's static constructor, any change to the /// property will cause to be called on the element. /// - protected static void AffectsMeasure(params AvaloniaProperty[] properties) + protected static void AffectsMeasure(params AvaloniaProperty[] properties) + where T : class, ILayoutable { foreach (var property in properties) { - property.Changed.Subscribe(AffectsMeasureInvalidate); + property.Changed.Subscribe(AffectsMeasureInvalidate); } } @@ -443,11 +444,12 @@ namespace Avalonia.Layout /// After a call to this method in a control's static constructor, any change to the /// property will cause to be called on the element. /// - protected static void AffectsArrange(params AvaloniaProperty[] properties) + protected static void AffectsArrange(params AvaloniaProperty[] properties) + where T : class, ILayoutable { foreach (var property in properties) { - property.Changed.Subscribe(AffectsArrangeInvalidate); + property.Changed.Subscribe(AffectsArrangeInvalidate); } } @@ -636,9 +638,10 @@ namespace Avalonia.Layout /// Calls on the control on which a property changed. /// /// The event args. - private static void AffectsMeasureInvalidate(AvaloniaPropertyChangedEventArgs e) + private static void AffectsMeasureInvalidate(AvaloniaPropertyChangedEventArgs e) + where T : class, ILayoutable { - ILayoutable control = e.Sender as ILayoutable; + var control = e.Sender as T; control?.InvalidateMeasure(); } @@ -646,9 +649,10 @@ namespace Avalonia.Layout /// Calls on the control on which a property changed. /// /// The event args. - private static void AffectsArrangeInvalidate(AvaloniaPropertyChangedEventArgs e) + private static void AffectsArrangeInvalidate(AvaloniaPropertyChangedEventArgs e) + where T : class, ILayoutable { - ILayoutable control = e.Sender as ILayoutable; + var control = e.Sender as T; control?.InvalidateArrange(); } diff --git a/src/Avalonia.Visuals/Visual.cs b/src/Avalonia.Visuals/Visual.cs index 81e1a93a6f..c2db20306e 100644 --- a/src/Avalonia.Visuals/Visual.cs +++ b/src/Avalonia.Visuals/Visual.cs @@ -100,7 +100,7 @@ namespace Avalonia /// static Visual() { - AffectsRender( + AffectsRender( BoundsProperty, ClipProperty, ClipToBoundsProperty, @@ -320,11 +320,12 @@ namespace Avalonia /// on the control which when changed should cause a redraw. This is similar to WPF's /// FrameworkPropertyMetadata.AffectsRender flag. /// - protected static void AffectsRender(params AvaloniaProperty[] properties) + protected static void AffectsRender(params AvaloniaProperty[] properties) + where T : class, IVisual { foreach (var property in properties) { - property.Changed.Subscribe(AffectsRenderInvalidate); + property.Changed.Subscribe(AffectsRenderInvalidate); } } @@ -416,9 +417,10 @@ namespace Avalonia /// Called when a property changes that should invalidate the visual. /// /// The event args. - private static void AffectsRenderInvalidate(AvaloniaPropertyChangedEventArgs e) + private static void AffectsRenderInvalidate(AvaloniaPropertyChangedEventArgs e) + where T : class, IVisual { - (e.Sender as Visual)?.InvalidateVisual(); + (e.Sender as T)?.InvalidateVisual(); } /// From 576cc915731892c2c6f55b928ed0588d5ecac889 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 7 Sep 2018 02:30:00 +0200 Subject: [PATCH 02/11] Make Pseudoclass method typed. --- src/Avalonia.Controls/Button.cs | 2 +- src/Avalonia.Controls/ButtonSpinner.cs | 6 +++--- src/Avalonia.Controls/ContentControl.cs | 4 ++-- src/Avalonia.Controls/Expander.cs | 10 +++++----- src/Avalonia.Controls/Primitives/ScrollBar.cs | 4 ++-- .../Primitives/ToggleButton.cs | 6 +++--- src/Avalonia.Controls/Primitives/Track.cs | 2 ++ src/Avalonia.Controls/ProgressBar.cs | 6 +++--- src/Avalonia.Controls/Slider.cs | 2 ++ src/Avalonia.Input/InputElement.cs | 6 +++--- src/Avalonia.Styling/StyledElement.cs | 20 +++++++++++-------- 11 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs index fa69d72d67..24b2af7996 100644 --- a/src/Avalonia.Controls/Button.cs +++ b/src/Avalonia.Controls/Button.cs @@ -80,7 +80,7 @@ namespace Avalonia.Controls FocusableProperty.OverrideDefaultValue(typeof(Button), true); CommandProperty.Changed.Subscribe(CommandChanged); IsDefaultProperty.Changed.Subscribe(IsDefaultChanged); - PseudoClass(IsPressedProperty, ":pressed"); + PseudoClass