From d0e74b7dbd1d6692fbf78251fc468cf230c3f0c2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 24 Jun 2020 18:11:33 +0200 Subject: [PATCH] Include transforms in effective bounds. --- src/Avalonia.Layout/LayoutManager.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Layout/LayoutManager.cs b/src/Avalonia.Layout/LayoutManager.cs index e7551d8e87..8a1a9fc2fb 100644 --- a/src/Avalonia.Layout/LayoutManager.cs +++ b/src/Avalonia.Layout/LayoutManager.cs @@ -349,15 +349,15 @@ namespace Avalonia.Layout private Rect CalculateEffectiveViewport(IVisual control) { var viewport = new Rect(0, 0, double.PositiveInfinity, double.PositiveInfinity); - CalculateEffectiveViewport(control, ref viewport); + CalculateEffectiveViewport(control, control, ref viewport); return viewport; } - private void CalculateEffectiveViewport(IVisual control, ref Rect viewport) + private void CalculateEffectiveViewport(IVisual target, IVisual control, ref Rect viewport) { if (control.VisualParent is object) { - CalculateEffectiveViewport(control.VisualParent, ref viewport); + CalculateEffectiveViewport(target, control.VisualParent, ref viewport); } if (control.ClipToBounds || control.VisualParent is null) @@ -368,6 +368,14 @@ namespace Avalonia.Layout { viewport = viewport.Translate(-control.Bounds.Position); } + + if (control != target && control.RenderTransform is object) + { + var origin = control.RenderTransformOrigin.ToPixels(control.Bounds.Size); + var offset = Matrix.CreateTranslation(origin); + var renderTransform = (-offset) * control.RenderTransform.Value.Invert() * (offset); + viewport = viewport.TransformToAABB(renderTransform); + } } private readonly struct EffectiveViewportChangedListener