From 64174f37af5b0d738935b46abdb7d2c2ee7db18c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 24 Jun 2020 23:13:05 +0200 Subject: [PATCH] Tweak effective viewport calculation. This logic isn't in the UWP version as it only clips to scrollports. --- src/Avalonia.Layout/LayoutManager.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Layout/LayoutManager.cs b/src/Avalonia.Layout/LayoutManager.cs index 8a1a9fc2fb..4a2c95db5b 100644 --- a/src/Avalonia.Layout/LayoutManager.cs +++ b/src/Avalonia.Layout/LayoutManager.cs @@ -355,20 +355,27 @@ namespace Avalonia.Layout private void CalculateEffectiveViewport(IVisual target, IVisual control, ref Rect viewport) { + // Recurse until the top level control. if (control.VisualParent is object) { CalculateEffectiveViewport(target, control.VisualParent, ref viewport); } - - if (control.ClipToBounds || control.VisualParent is null) + else { - viewport = control.Bounds; + viewport = new Rect(control.Bounds.Size); } - else + + // Apply the control clip bounds if it's not the target control. We don't apply it to + // the target control because it may itself be clipped to bounds and if so the viewport + // we calculate would be of no use. + if (control != target && control.ClipToBounds) { - viewport = viewport.Translate(-control.Bounds.Position); + viewport = control.Bounds.Intersect(viewport); } + // Translate the viewport into this control's coordinate space. + viewport = viewport.Translate(-control.Bounds.Position); + if (control != target && control.RenderTransform is object) { var origin = control.RenderTransformOrigin.ToPixels(control.Bounds.Size);