From b6ed3bdbae40259f742861b63ee38304718cd826 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 30 Nov 2019 15:29:29 +0100 Subject: [PATCH] Move invalidation function to LayoutHelper. --- src/Avalonia.Controls/TopLevel.cs | 2 +- src/Avalonia.Layout/LayoutHelper.cs | 27 +++++++++++++++++++++++++++ src/Avalonia.Layout/Layoutable.cs | 28 +--------------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 533f743f0b..5a8711a21c 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -299,7 +299,7 @@ namespace Avalonia.Controls /// The window scaling. protected virtual void HandleScalingChanged(double scaling) { - InvalidateSelfAndDescendantsMeasure(); + LayoutHelper.InvalidateSelfAndChildrenMeasure(this); } /// diff --git a/src/Avalonia.Layout/LayoutHelper.cs b/src/Avalonia.Layout/LayoutHelper.cs index cfb4b14b1c..6ca4647c24 100644 --- a/src/Avalonia.Layout/LayoutHelper.cs +++ b/src/Avalonia.Layout/LayoutHelper.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using Avalonia.VisualTree; namespace Avalonia.Layout { @@ -61,5 +62,31 @@ namespace Avalonia.Layout return availableSize; } + + /// + /// Invalidates measure for this instance and all visual children recursively. + /// + public static void InvalidateSelfAndChildrenMeasure(ILayoutable control) + { + void InnerInvalidateMeasure(IVisual target) + { + if (target is ILayoutable targetLayoutable) + { + targetLayoutable.InvalidateMeasure(); + } + + var visualChildren = target.VisualChildren; + var visualChildrenCount = visualChildren.Count; + + for (int i = 0; i < visualChildrenCount; i++) + { + IVisual child = visualChildren[i]; + + InnerInvalidateMeasure(child); + } + } + + InnerInvalidateMeasure(control); + } } } diff --git a/src/Avalonia.Layout/Layoutable.cs b/src/Avalonia.Layout/Layoutable.cs index f9e438cbeb..9d0a5c57ee 100644 --- a/src/Avalonia.Layout/Layoutable.cs +++ b/src/Avalonia.Layout/Layoutable.cs @@ -692,36 +692,10 @@ namespace Avalonia.Layout return finalSize; } - /// - /// Invalidates measure for this instance and all visual children. - /// - protected void InvalidateSelfAndDescendantsMeasure() - { - void InnerInvalidateMeasure(IVisual target) - { - if (target is ILayoutable layoutable) - { - layoutable.InvalidateMeasure(); - } - - var visualChildren = target.VisualChildren; - var visualChildrenCount = visualChildren.Count; - - for (int i = 0; i < visualChildrenCount; i++) - { - IVisual child = visualChildren[i]; - - InnerInvalidateMeasure(child); - } - } - - InnerInvalidateMeasure(this); - } - /// protected sealed override void OnVisualParentChanged(IVisual oldParent, IVisual newParent) { - InvalidateSelfAndDescendantsMeasure(); + LayoutHelper.InvalidateSelfAndChildrenMeasure(this); base.OnVisualParentChanged(oldParent, newParent); }