From 82a654a1de3a6f95ce782e0c19f0c108af839393 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 23 Oct 2020 11:19:48 +0100 Subject: [PATCH 1/5] perform a real hit test on devtools ctrl + shift --- src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 10861538ae..5afcebe8f7 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -76,8 +76,8 @@ namespace Avalonia.Diagnostics.Views if (e.Modifiers == modifiers) { var point = (Root as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default; - var control = Root.GetVisualsAt(point, x => (!(x is AdornerLayer) && x.IsVisible)) - .FirstOrDefault(); + + var control = Root.Renderer.HitTestFirst(point, Root, x => !(x is IInputElement ie && !ie.IsHitTestVisible)); if (control != null) { From 794554f74da369f36d5d000fa29bcfeeea10c99e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 23 Oct 2020 11:25:09 +0100 Subject: [PATCH 2/5] simplify logic. --- src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 5afcebe8f7..11b2e8a11e 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -77,7 +77,7 @@ namespace Avalonia.Diagnostics.Views { var point = (Root as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default; - var control = Root.Renderer.HitTestFirst(point, Root, x => !(x is IInputElement ie && !ie.IsHitTestVisible)); + var control = Root.Renderer.HitTestFirst(point, Root, x => !(x is IInputElement ie) || ie.IsHitTestVisible); if (control != null) { From a412570262c4d6edd0d47787274bc9cd369c003c Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 23 Oct 2020 13:11:05 +0100 Subject: [PATCH 3/5] dont return elements with IsHitTestVisible = false; --- .../Diagnostics/Views/MainWindow.xaml.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 11b2e8a11e..bf19278831 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -76,8 +76,9 @@ namespace Avalonia.Diagnostics.Views if (e.Modifiers == modifiers) { var point = (Root as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default; - - var control = Root.Renderer.HitTestFirst(point, Root, x => !(x is IInputElement ie) || ie.IsHitTestVisible); + + var control = Root.GetVisualsAt(point, x => !(x is AdornerLayer) && x.IsVisible && (!(x is IInputElement ie) || ie.IsHitTestVisible)) + .FirstOrDefault(); if (control != null) { From ba990ad9596762eb1d24462456ce985b4470129f Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 23 Oct 2020 13:15:37 +0100 Subject: [PATCH 4/5] breakup long statement --- .../Diagnostics/Views/MainWindow.xaml.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index bf19278831..3e5b56edb0 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -77,7 +77,11 @@ namespace Avalonia.Diagnostics.Views { var point = (Root as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default; - var control = Root.GetVisualsAt(point, x => !(x is AdornerLayer) && x.IsVisible && (!(x is IInputElement ie) || ie.IsHitTestVisible)) + var control = Root.GetVisualsAt(point, x => + { + return !(x is AdornerLayer) && x.IsVisible && + (!(x is IInputElement ie) || ie.IsHitTestVisible); + }) .FirstOrDefault(); if (control != null) From 528a45c93e7cdba4c99d6cb3fdc1794a9f2b4a81 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 25 Oct 2020 12:59:14 +0000 Subject: [PATCH 5/5] make logic easier to understand for dev tools ctrl + shift hit test. --- .../Diagnostics/Views/MainWindow.xaml.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 3e5b56edb0..c4f9185728 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -79,8 +79,9 @@ namespace Avalonia.Diagnostics.Views var control = Root.GetVisualsAt(point, x => { - return !(x is AdornerLayer) && x.IsVisible && - (!(x is IInputElement ie) || ie.IsHitTestVisible); + if (x is AdornerLayer || !x.IsVisible) return false; + if (!(x is IInputElement ie)) return true; + return ie.IsHitTestVisible; }) .FirstOrDefault();