浏览代码

Make AffectsMeasure/Arrange/Render typed.

Steven Kirk 7 年之前
父节点
当前提交
fad2e317ba

+ 2 - 2
src/Avalonia.Controls/Border.cs

@@ -43,8 +43,8 @@ namespace Avalonia.Controls
         /// </summary>
         static Border()
         {
-            AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
-            AffectsMeasure(BorderThicknessProperty);
+            AffectsRender<Border>(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+            AffectsMeasure<Border>(BorderThicknessProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/Decorator.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Controls
         /// </summary>
         static Decorator()
         {
-            AffectsMeasure(ChildProperty, PaddingProperty);
+            AffectsMeasure<Decorator>(ChildProperty, PaddingProperty);
             ChildProperty.Changed.AddClassHandler<Decorator>(x => x.ChildChanged);
         }
 

+ 3 - 3
src/Avalonia.Controls/DrawingPresenter.cs

@@ -8,8 +8,8 @@ namespace Avalonia.Controls
     {
         static DrawingPresenter()
         {
-            AffectsMeasure(DrawingProperty);
-            AffectsRender(DrawingProperty);
+            AffectsMeasure<DrawingPresenter>(DrawingProperty);
+            AffectsRender<DrawingPresenter>(DrawingProperty);
         }
 
         public static readonly StyledProperty<Drawing> DrawingProperty =
@@ -56,4 +56,4 @@ namespace Avalonia.Controls
             }
         }
     }
-}
+}

+ 1 - 2
src/Avalonia.Controls/Image.cs

@@ -25,8 +25,7 @@ namespace Avalonia.Controls
 
         static Image()
         {
-            AffectsRender(SourceProperty);
-            AffectsRender(StretchProperty);
+            AffectsRender<Image>(SourceProperty, StretchProperty);
         }
 
         /// <summary>

+ 2 - 2
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@@ -90,8 +90,8 @@ namespace Avalonia.Controls.Presenters
         /// </summary>
         static ContentPresenter()
         {
-            AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
-            AffectsMeasure(BorderThicknessProperty, PaddingProperty);
+            AffectsRender<ContentPresenter>(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+            AffectsMeasure<ContentPresenter>(BorderThicknessProperty, PaddingProperty);
             ContentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
             ContentTemplateProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
             TemplatedParentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.TemplatedParentChanged);

+ 1 - 1
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@@ -72,7 +72,7 @@ namespace Avalonia.Controls.Presenters
         {
             ClipToBoundsProperty.OverrideDefaultValue(typeof(ScrollContentPresenter), true);
             ChildProperty.Changed.AddClassHandler<ScrollContentPresenter>(x => x.ChildChanged);
-            AffectsArrange(OffsetProperty);
+            AffectsArrange<ScrollContentPresenter>(OffsetProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/Presenters/TextPresenter.cs

@@ -38,7 +38,7 @@ namespace Avalonia.Controls.Presenters
         
         static TextPresenter()
         {
-            AffectsRender(PasswordCharProperty);
+            AffectsRender<TextPresenter>(PasswordCharProperty);
         }
 
         public TextPresenter()

+ 1 - 1
src/Avalonia.Controls/Primitives/AccessText.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Controls.Primitives
         /// </summary>
         static AccessText()
         {
-            AffectsRender(ShowAccessKeyProperty);
+            AffectsRender<AccessText>(ShowAccessKeyProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/Primitives/Track.cs

@@ -42,7 +42,7 @@ namespace Avalonia.Controls.Primitives
             ThumbProperty.Changed.AddClassHandler<Track>(x => x.ThumbChanged);
             IncreaseButtonProperty.Changed.AddClassHandler<Track>(x => x.ButtonChanged);
             DecreaseButtonProperty.Changed.AddClassHandler<Track>(x => x.ButtonChanged);
-            AffectsArrange(MinimumProperty, MaximumProperty, ValueProperty, OrientationProperty);
+            AffectsArrange<Track>(MinimumProperty, MaximumProperty, ValueProperty, OrientationProperty);
         }
 
         public double Minimum

+ 2 - 3
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<Shape>(StretchProperty, StrokeThicknessProperty);
+            AffectsRender<Shape>(FillProperty, StrokeProperty, StrokeDashArrayProperty);
         }
 
         public Geometry DefiningGeometry

+ 2 - 2
src/Avalonia.Controls/StackPanel.cs

@@ -29,8 +29,8 @@ namespace Avalonia.Controls
         /// </summary>
         static StackPanel()
         {
-            AffectsMeasure(SpacingProperty);
-            AffectsMeasure(OrientationProperty);
+            AffectsMeasure<StackPanel>(SpacingProperty);
+            AffectsMeasure<StackPanel>(OrientationProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/TabControl.cs

@@ -44,7 +44,7 @@ namespace Avalonia.Controls
         {
             SelectionModeProperty.OverrideDefaultValue<TabControl>(SelectionMode.AlwaysSelected);
             FocusableProperty.OverrideDefaultValue<TabControl>(false);
-            AffectsMeasure(TabStripPlacementProperty);
+            AffectsMeasure<TabControl>(TabStripPlacementProperty);
         }
 
         /// <summary>

+ 5 - 4
src/Avalonia.Controls/TextBlock.cs

@@ -99,10 +99,11 @@ namespace Avalonia.Controls
         static TextBlock()
         {
             ClipToBoundsProperty.OverrideDefaultValue<TextBlock>(true);
-            AffectsRender(ForegroundProperty);
-            AffectsRender(FontWeightProperty);
-            AffectsRender(FontSizeProperty);
-            AffectsRender(FontStyleProperty);
+            AffectsRender<TextBlock>(
+                ForegroundProperty,
+                FontWeightProperty,
+                FontSizeProperty,
+                FontStyleProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/TopLevel.cs

@@ -59,7 +59,7 @@ namespace Avalonia.Controls
         /// </summary>
         static TopLevel()
         {
-            AffectsMeasure(ClientSizeProperty);
+            AffectsMeasure<TopLevel>(ClientSizeProperty);
         }
 
         /// <summary>

+ 1 - 1
src/Avalonia.Controls/WrapPanel.cs

@@ -30,7 +30,7 @@ namespace Avalonia.Controls
         /// </summary>
         static WrapPanel()
         {
-            AffectsMeasure(OrientationProperty);
+            AffectsMeasure<WrapPanel>(OrientationProperty);
         }
 
         /// <summary>

+ 13 - 9
src/Avalonia.Layout/Layoutable.cs

@@ -140,7 +140,7 @@ namespace Avalonia.Layout
         /// </summary>
         static Layoutable()
         {
-            AffectsMeasure(
+            AffectsMeasure<Layoutable>(
                 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 <see cref="InvalidateMeasure"/> to be called on the element.
         /// </remarks>
-        protected static void AffectsMeasure(params AvaloniaProperty[] properties)
+        protected static void AffectsMeasure<T>(params AvaloniaProperty[] properties)
+            where T : class, ILayoutable
         {
             foreach (var property in properties)
             {
-                property.Changed.Subscribe(AffectsMeasureInvalidate);
+                property.Changed.Subscribe(AffectsMeasureInvalidate<T>);
             }
         }
 
@@ -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 <see cref="InvalidateArrange"/> to be called on the element.
         /// </remarks>
-        protected static void AffectsArrange(params AvaloniaProperty[] properties)
+        protected static void AffectsArrange<T>(params AvaloniaProperty[] properties)
+            where T : class, ILayoutable
         {
             foreach (var property in properties)
             {
-                property.Changed.Subscribe(AffectsArrangeInvalidate);
+                property.Changed.Subscribe(AffectsArrangeInvalidate<T>);
             }
         }
 
@@ -636,9 +638,10 @@ namespace Avalonia.Layout
         /// Calls <see cref="InvalidateMeasure"/> on the control on which a property changed.
         /// </summary>
         /// <param name="e">The event args.</param>
-        private static void AffectsMeasureInvalidate(AvaloniaPropertyChangedEventArgs e)
+        private static void AffectsMeasureInvalidate<T>(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 <see cref="InvalidateArrange"/> on the control on which a property changed.
         /// </summary>
         /// <param name="e">The event args.</param>
-        private static void AffectsArrangeInvalidate(AvaloniaPropertyChangedEventArgs e)
+        private static void AffectsArrangeInvalidate<T>(AvaloniaPropertyChangedEventArgs e)
+            where T : class, ILayoutable
         {
-            ILayoutable control = e.Sender as ILayoutable;
+            var control = e.Sender as T;
             control?.InvalidateArrange();
         }
 

+ 7 - 5
src/Avalonia.Visuals/Visual.cs

@@ -100,7 +100,7 @@ namespace Avalonia
         /// </summary>
         static Visual()
         {
-            AffectsRender(
+            AffectsRender<Visual>(
                 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.
         /// </remarks>
-        protected static void AffectsRender(params AvaloniaProperty[] properties)
+        protected static void AffectsRender<T>(params AvaloniaProperty[] properties)
+            where T : class, IVisual
         {
             foreach (var property in properties)
             {
-                property.Changed.Subscribe(AffectsRenderInvalidate);
+                property.Changed.Subscribe(AffectsRenderInvalidate<T>);
             }
         }
 
@@ -416,9 +417,10 @@ namespace Avalonia
         /// Called when a property changes that should invalidate the visual.
         /// </summary>
         /// <param name="e">The event args.</param>
-        private static void AffectsRenderInvalidate(AvaloniaPropertyChangedEventArgs e)
+        private static void AffectsRenderInvalidate<T>(AvaloniaPropertyChangedEventArgs e)
+            where T : class, IVisual
         {
-            (e.Sender as Visual)?.InvalidateVisual();
+            (e.Sender as T)?.InvalidateVisual();
         }
 
         /// <summary>