diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 03bc864ef..6a78147dc 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -642,8 +642,8 @@ public partial class View if (nextStart.Visible && nextStart.Contains (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)) { start = nextStart; - x = startOffsetX + start.Viewport.X; - y = startOffsetY + start.Viewport.Y; + x = startOffsetX; + y = startOffsetY; break; } diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 0b02656e6..cd932b06c 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -1,4 +1,4 @@ -#define OTHER_CONTROLS +//#define OTHER_CONTROLS using System; using System.Collections.Generic; diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index e97be486b..fe056a096 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -271,6 +271,40 @@ public class FindDeepestViewTests (ITestOutputHelper output) Assert.Equal (expectedSubViewFound, found == subview); } + [Theory] + [InlineData (0, 0, false)] + [InlineData (1, 1, false)] + [InlineData (9, 9, true)] + [InlineData (10, 10, false)] + [InlineData (7, 8, false)] + [InlineData (1, 2, false)] + [InlineData (2, 3, false)] + [InlineData (5, 6, false)] + [InlineData (2, 3, false)] + [InlineData (6, 7, false)] + public void Returns_Correct_If_Start_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + { + var start = new View () + { + Width = 10, Height = 10, + }; + start.Padding.Thickness = new Thickness (1); + + var subview = new View () + { + X = Pos.AnchorEnd(1), Y = Pos.AnchorEnd(1), + Width = 1, Height = 1, + }; + start.Padding.Add (subview); + start.BeginInit(); + start.EndInit(); + + var found = View.FindDeepestView (start, testX, testY); + + Assert.Equal (expectedSubViewFound, found == subview); + } + + [Theory] [InlineData (0, 0, typeof (Margin))] [InlineData (9, 9, typeof (Margin))] @@ -336,6 +370,99 @@ public class FindDeepestViewTests (ITestOutputHelper output) Assert.Equal (expectedSubViewFound, found == subview); } + [Theory] + [InlineData (0, 0, false)] + [InlineData (1, 1, false)] + [InlineData (9, 9, false)] + [InlineData (10, 10, false)] + [InlineData (7, 8, false)] + [InlineData (6, 7, false)] + [InlineData (1, 2, false)] + [InlineData (5, 6, false)] + [InlineData (6, 5, false)] + [InlineData (5, 5, true)] + public void Returns_Correct_If_SubView_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + { + var start = new View () + { + Width = 10, Height = 10, + }; + + // A subview with + Padding + var subview = new View () + { + X = 1, Y = 1, + Width = 5, Height = 5, + }; + subview.Padding.Thickness = new (1); + + // This subview will be at the bottom-right-corner of subview + // So screen-relative location will be X + Width - 1 = 5 + var paddingSubview = new View () + { + X = Pos.AnchorEnd (1), + Y = Pos.AnchorEnd (1), + Width = 1, + Height = 1, + }; + subview.Padding.Add (paddingSubview); + start.Add (subview); + start.BeginInit(); + start.EndInit(); + + var found = View.FindDeepestView (start, testX, testY); + + Assert.Equal (expectedSubViewFound, found == paddingSubview); + } + + [Theory] + [InlineData (0, 0, false)] + [InlineData (1, 1, false)] + [InlineData (9, 9, false)] + [InlineData (10, 10, false)] + [InlineData (7, 8, false)] + [InlineData (6, 7, false)] + [InlineData (1, 2, false)] + [InlineData (5, 6, false)] + [InlineData (6, 5, false)] + [InlineData (5, 5, true)] + public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubview (int testX, int testY, bool expectedSubViewFound) + { + var start = new View () + { + Width = 10, Height = 10, + }; + + // A subview with + Padding + var subview = new View () + { + X = 1, Y = 1, + Width = 5, Height = 5, + }; + subview.Padding.Thickness = new (1); + + // Scroll the subview + subview.ContentSize = new Size (10, 10); + subview.Viewport = subview.Viewport with { Location = new (1, 1) }; + + // This subview will be at the bottom-right-corner of subview + // So screen-relative location will be X + Width - 1 = 5 + var paddingSubview = new View () + { + X = Pos.AnchorEnd (1), + Y = Pos.AnchorEnd (1), + Width = 1, + Height = 1, + }; + subview.Padding.Add (paddingSubview); + start.Add (subview); + start.BeginInit (); + start.EndInit (); + + var found = View.FindDeepestView (start, testX, testY); + + Assert.Equal (expectedSubViewFound, found == paddingSubview); + } // Test that FindDeepestView works with nested subviews [Theory] [InlineData (0, 0, -1)]