From 79ff5f48c1a336547a7b7cd84286551f6d90fe6f Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 25 May 2020 14:25:16 +0200 Subject: [PATCH] Apply global clip to adorner element. Previously, the adorner clip was not taking into account the clip inherited from ancestor controls, resulting in #3984. Fix this by appling the clip from `TransformedBounds.Clip` by translating it to local coordinates first. Note that this doesn't work well for controls with a render transform applied, but at least it fixes the issue in the common case. Fixes #3984 --- src/Avalonia.Controls/Primitives/AdornerLayer.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/AdornerLayer.cs b/src/Avalonia.Controls/Primitives/AdornerLayer.cs index 87ab6cf450..9834bf3d3b 100644 --- a/src/Avalonia.Controls/Primitives/AdornerLayer.cs +++ b/src/Avalonia.Controls/Primitives/AdornerLayer.cs @@ -3,6 +3,7 @@ using System.Collections.Specialized; using System.Linq; using Avalonia.Media; using Avalonia.Rendering; +using Avalonia.Utilities; using Avalonia.VisualTree; namespace Avalonia.Controls.Primitives @@ -78,15 +79,20 @@ namespace Avalonia.Controls.Primitives private void UpdateClip(IControl control, TransformedBounds bounds) { - var clip = control.Clip as RectangleGeometry; - - if (clip == null) + if (!(control.Clip is RectangleGeometry clip)) { - clip = new RectangleGeometry { Transform = new MatrixTransform() }; + clip = new RectangleGeometry(); control.Clip = clip; } - clip.Rect = bounds.Bounds; + var clipBounds = bounds.Bounds; + + if (bounds.Transform.HasInverse) + { + clipBounds = bounds.Clip.TransformToAABB(bounds.Transform.Invert()); + } + + clip.Rect = clipBounds; } private void ChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)