From 3bc2909d73ade02c2d435d0644ebc1bc2e822a7b Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Tue, 27 Feb 2024 08:21:01 -0700 Subject: [PATCH] WIP (broken) - support adornmnts --- Terminal.Gui/View/Layout/ViewLayout.cs | 19 ++++++++++++- UnitTests/View/FindDeepestViewTests.cs | 38 ++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 6cbf946aa..126754896 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -570,6 +570,23 @@ public partial class View return null; } + if (findAdornments) + { + if (start.Margin.Thickness.Contains (start.Frame, x, y)) + { + return start.Margin; + } + if (start.Border.Thickness.Contains (start.Frame, x, y)) + { + return start.Border; + } + if (start.Padding.Thickness.Contains (start.Frame, x, y)) + { + return start.Padding; + } + + } + if (start.InternalSubviews is { Count: > 0 }) { Point boundsOffset = start.GetBoundsOffset (); @@ -582,7 +599,7 @@ public partial class View if (v.Visible && v.Frame.Contains (rx, ry)) { - View? deep = FindDeepestView (v, rx, ry); + View? deep = FindDeepestView (v, rx, ry, findAdornments); return deep ?? v; } } diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index ddf19198c..e6e2a704b 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -143,8 +143,7 @@ public class FindDeepestViewTests (ITestOutputHelper output) Assert.Equal (expectedSubViewFound, found == subview); } - - + // Test that FindDeepestView works if the start view has positive Adornments [Theory] [InlineData (0, 0, false)] @@ -173,11 +172,44 @@ public class FindDeepestViewTests (ITestOutputHelper output) }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, testX, testY, true); Assert.Equal (expectedSubViewFound, found == subview); } + [Theory] + [InlineData (0, 0, typeof(Margin))] + [InlineData (9, 9, typeof (Margin))] + + [InlineData (1, 1, typeof (Border))] + [InlineData (8, 8, typeof (Border))] + + [InlineData (1, 1, typeof (Padding))] + [InlineData (7, 7, typeof (Padding))] + + [InlineData (5, 5, typeof (View))] + public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Type expectedAdornmentType) + { + var start = new View () + { + Width = 10, Height = 10, + }; + start.Margin.Thickness = new Thickness (1); + start.Border.Thickness = new Thickness (1); + start.Padding.Thickness = new Thickness (1); + + var subview = new View () + { + X = 1, Y = 1, + Width = 1, Height = 1, + }; + start.Add (subview); + + var found = View.FindDeepestView (start, testX, testY, true); + Assert.Equal(expectedAdornmentType, found.GetType()); + + } + // Test that FindDeepestView works if the subview has positive Adornments [Theory] [InlineData (0, 0, false)]