From 36dd50e6458f9fe97872bb108913d595f04219ea Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Thu, 12 Dec 2019 14:46:34 +0200 Subject: [PATCH 1/3] fix immediate rendering hit testing for AdornerLayer --- src/Avalonia.Controls/Primitives/AdornerLayer.cs | 5 +---- .../Rendering/ICustomSimpleHitTest.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/AdornerLayer.cs b/src/Avalonia.Controls/Primitives/AdornerLayer.cs index ebe5e0a93e..9a2f0310d7 100644 --- a/src/Avalonia.Controls/Primitives/AdornerLayer.cs +++ b/src/Avalonia.Controls/Primitives/AdornerLayer.cs @@ -138,10 +138,7 @@ namespace Avalonia.Controls.Primitives } } - public bool HitTest(Point point) - { - return Children.Any(ctrl => ctrl.TransformedBounds?.Contains(point) == true); - } + public bool HitTest(Point point) => Children.HitTestCustom(point); private class AdornedElementInfo { diff --git a/src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs b/src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs index 7199053b08..4c15de0312 100644 --- a/src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs +++ b/src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs @@ -1,3 +1,7 @@ +using System.Collections.Generic; +using System.Linq; +using Avalonia.VisualTree; + namespace Avalonia.Rendering { /// @@ -9,4 +13,13 @@ namespace Avalonia.Rendering { bool HitTest(Point point); } + + public static class CustomSimpleHitTestExtensions + { + public static bool HitTestCustom(this IVisual visual, Point point) + => (visual as ICustomSimpleHitTest)?.HitTest(point) ?? visual.TransformedBounds?.Contains(point) == true; + + public static bool HitTestCustom(this IEnumerable children, Point point) + => children.Any(ctrl => ctrl.HitTestCustom(point)); + } } From fc44379173d3e2ecf74f4789b55a9002855f6968 Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Thu, 12 Dec 2019 14:59:17 +0200 Subject: [PATCH 2/3] fix immediaterenderer custom hittesting for WindowNotificationManager fixes #3356 --- .../Notifications/WindowNotificationManager.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs index 1a9347e317..f27bb5fac6 100644 --- a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reactive.Linq; using System.Threading.Tasks; using Avalonia.Controls.Primitives; +using Avalonia.Rendering; using Avalonia.VisualTree; namespace Avalonia.Controls.Notifications @@ -14,7 +15,7 @@ namespace Avalonia.Controls.Notifications /// /// An that displays notifications in a . /// - public class WindowNotificationManager : TemplatedControl, IManagedNotificationManager + public class WindowNotificationManager : TemplatedControl, IManagedNotificationManager, ICustomSimpleHitTest { private IList _items; @@ -153,5 +154,7 @@ namespace Avalonia.Controls.Notifications adornerLayer?.Children.Add(this); } + + public bool HitTest(Point point) => VisualChildren.HitTestCustom(point); } } From 3439a371d940fe9b76adfa679393b170f9b499a3 Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Thu, 12 Dec 2019 15:01:10 +0200 Subject: [PATCH 3/3] sync custom hittesting also to overlaylayer --- src/Avalonia.Controls/Primitives/OverlayLayer.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/OverlayLayer.cs b/src/Avalonia.Controls/Primitives/OverlayLayer.cs index 487a5e91e4..5150033a53 100644 --- a/src/Avalonia.Controls/Primitives/OverlayLayer.cs +++ b/src/Avalonia.Controls/Primitives/OverlayLayer.cs @@ -21,11 +21,8 @@ namespace Avalonia.Controls.Primitives return null; } - - public bool HitTest(Point point) - { - return Children.Any(ctrl => ctrl.TransformedBounds?.Contains(point) == true); - } + + public bool HitTest(Point point) => Children.HitTestCustom(point); protected override Size ArrangeOverride(Size finalSize) {