Browse Source

Move invalidation function to LayoutHelper.

pull/3253/head
Dariusz Komosinski 7 years ago
parent
commit
b6ed3bdbae
  1. 2
      src/Avalonia.Controls/TopLevel.cs
  2. 27
      src/Avalonia.Layout/LayoutHelper.cs
  3. 28
      src/Avalonia.Layout/Layoutable.cs

2
src/Avalonia.Controls/TopLevel.cs

@ -299,7 +299,7 @@ namespace Avalonia.Controls
/// <param name="scaling">The window scaling.</param>
protected virtual void HandleScalingChanged(double scaling)
{
InvalidateSelfAndDescendantsMeasure();
LayoutHelper.InvalidateSelfAndChildrenMeasure(this);
}
/// <inheritdoc/>

27
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;
}
/// <summary>
/// Invalidates measure for this instance and all visual children recursively.
/// </summary>
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);
}
}
}

28
src/Avalonia.Layout/Layoutable.cs

@ -692,36 +692,10 @@ namespace Avalonia.Layout
return finalSize;
}
/// <summary>
/// Invalidates measure for this instance and all visual children.
/// </summary>
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);
}
/// <inheritdoc/>
protected sealed override void OnVisualParentChanged(IVisual oldParent, IVisual newParent)
{
InvalidateSelfAndDescendantsMeasure();
LayoutHelper.InvalidateSelfAndChildrenMeasure(this);
base.OnVisualParentChanged(oldParent, newParent);
}

Loading…
Cancel
Save