diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 59b51c612..7ff587062 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1556,7 +1556,7 @@ public static partial class Application return; } - var view = View.FindDeepestView (Current, mouseEvent.X, mouseEvent.Y); + var view = View.FindDeepestView (Current, new (mouseEvent.X, mouseEvent.Y)); if (view is { }) { @@ -1619,7 +1619,7 @@ public static partial class Application // This occurs when there are multiple overlapped "tops" // E.g. "Mdi" - in the Background Worker Scenario View? top = FindDeepestTop (Top, mouseEvent.X, mouseEvent.Y); - view = View.FindDeepestView (top, mouseEvent.X, mouseEvent.Y); + view = View.FindDeepestView (top, new (mouseEvent.X, mouseEvent.Y)); if (view is { } && view != OverlappedTop && top != Current) { diff --git a/Terminal.Gui/Drawing/Thickness.cs b/Terminal.Gui/Drawing/Thickness.cs index 40a30d590..d26d10a6c 100644 --- a/Terminal.Gui/Drawing/Thickness.cs +++ b/Terminal.Gui/Drawing/Thickness.cs @@ -90,14 +90,13 @@ public class Thickness : IEquatable /// the rectangle described by . /// /// Describes the location and size of the rectangle that contains the thickness. - /// The x coord to check. - /// The y coord to check. + /// The coordinate to check. /// if the specified coordinate is within the thickness; otherwise. - public bool Contains (Rectangle outside, int x, int y) + public bool Contains (in Rectangle outside, in Point location) { Rectangle inside = GetInside (outside); - return outside.Contains (x, y) && !inside.Contains (x, y); + return outside.Contains (location) && !inside.Contains (location); } /// diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index f7e75d5a1..611b06d9c 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -209,12 +209,11 @@ public class Adornment : View /// Indicates whether the specified Parent's SuperView-relative coordinates are within the Adornment's Thickness. /// /// - /// The and are relative to the PARENT's SuperView. + /// The is relative to the PARENT's SuperView. /// - /// - /// + /// /// if the specified Parent's SuperView-relative coordinates are within the Adornment's Thickness. - public override bool Contains (int x, int y) + public override bool Contains (in Point location) { if (Parent is null) { @@ -224,7 +223,7 @@ public class Adornment : View Rectangle frame = Frame; frame.Offset (Parent.Frame.Location); - return Thickness.Contains (frame, x, y); + return Thickness.Contains (frame, location); } /// diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 60d789c51..f8079d444 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -273,7 +273,7 @@ public class Border : Adornment // Only start grabbing if the user clicks in the Thickness area // Adornment.Contains takes Parent SuperView=relative coords. - if (Contains (mouseEvent.X + Parent.Frame.X + Frame.X, mouseEvent.Y + Parent.Frame.Y + Frame.Y)) + if (Contains (new (mouseEvent.X + Parent.Frame.X + Frame.X, mouseEvent.Y + Parent.Frame.Y + Frame.Y))) { // Set the start grab point to the Frame coords _startGrabPoint = new (mouseEvent.X + Frame.X, mouseEvent.Y + Frame.Y); diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 9af05e4c4..ee8555553 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using Microsoft.CodeAnalysis; namespace Terminal.Gui; @@ -392,10 +393,9 @@ public partial class View /// /// Indicates whether the specified SuperView-relative coordinates are within the View's . /// - /// SuperView-relative X coordinate. - /// SuperView-relative Y coordinate. + /// SuperView-relative coordinate /// if the specified SuperView-relative coordinates are within the View. - public virtual bool Contains (int x, int y) { return Frame.Contains (x, y); } + public virtual bool Contains (in Point location) { return Frame.Contains (location); } #nullable enable /// Finds the first Subview of that is visible at the provided location. @@ -405,29 +405,29 @@ public partial class View /// /// /// The view to scope the search by. - /// .SuperView-relative X coordinate. - /// .SuperView-relative Y coordinate. + /// .SuperView-relative coordinate. /// - /// The view that was found at the and coordinates. + /// The view that was found at the coordinate. /// if no view was found. /// // CONCURRENCY: This method is not thread-safe. Undefined behavior and likely program crashes are exposed by unsynchronized access to InternalSubviews. - internal static View? FindDeepestView (View? start, int x, int y) + internal static View? FindDeepestView (View? start, in Point location) { - while (start is { Visible: true } && start.Contains (x, y)) + Point currentLocation = location; + while (start is { Visible: true } && start.Contains (currentLocation)) { Adornment? found = null; - if (start.Margin.Contains (x, y)) + if (start.Margin.Contains (currentLocation)) { found = start.Margin; } - else if (start.Border.Contains (x, y)) + else if (start.Border.Contains (currentLocation)) { found = start.Border; } - else if (start.Padding.Contains (x, y)) + else if (start.Padding.Contains (currentLocation)) { found = start.Padding; } @@ -440,19 +440,19 @@ public partial class View viewportOffset = found.Parent.Frame.Location; } - int startOffsetX = x - (start.Frame.X + viewportOffset.X); - int startOffsetY = y - (start.Frame.Y + viewportOffset.Y); + int startOffsetX = currentLocation.X - (start.Frame.X + viewportOffset.X); + int startOffsetY = currentLocation.Y - (start.Frame.Y + viewportOffset.Y); View? subview = null; for (int i = start.InternalSubviews.Count - 1; i >= 0; i--) { if (start.InternalSubviews [i].Visible - && start.InternalSubviews [i].Contains (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)) + && start.InternalSubviews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y))) { subview = start.InternalSubviews [i]; - x = startOffsetX + start.Viewport.X; - y = startOffsetY + start.Viewport.Y; + currentLocation.X = startOffsetX + start.Viewport.X; + currentLocation.Y = startOffsetY + start.Viewport.Y; // start is the deepest subview under the mouse; stop searching the subviews break; diff --git a/UnitTests/Drawing/ThicknessTests.cs b/UnitTests/Drawing/ThicknessTests.cs index a6cf839ef..76a1ab205 100644 --- a/UnitTests/Drawing/ThicknessTests.cs +++ b/UnitTests/Drawing/ThicknessTests.cs @@ -663,7 +663,7 @@ public class ThicknessTests { var rect = new Rectangle (x, y, width, height); var thickness = new Thickness (1, 1, 1, 1); // Uniform thickness for simplicity - bool result = thickness.Contains (rect, pointX, pointY); + bool result = thickness.Contains (rect, new (pointX, pointY)); Assert.Equal (expected, result); } @@ -702,7 +702,7 @@ public class ThicknessTests { var rect = new Rectangle (x, y, width, height); var thickness = new Thickness (2, 2, 2, 2); // Uniform thickness for simplicity - bool result = thickness.Contains (rect, pointX, pointY); + bool result = thickness.Contains (rect, new (pointX, pointY)); Assert.Equal (expected, result); } @@ -737,7 +737,7 @@ public class ThicknessTests { var rect = new Rectangle (x, y, width, height); var thickness = new Thickness (0, 0, 0, 0); // Uniform thickness for simplicity - bool result = thickness.Contains (rect, pointX, pointY); + bool result = thickness.Contains (rect, new (pointX, pointY)); Assert.Equal (expected, result); } diff --git a/UnitTests/View/Adornment/AdornmentSubViewTests.cs b/UnitTests/View/Adornment/AdornmentSubViewTests.cs index 271d0433a..188706a17 100644 --- a/UnitTests/View/Adornment/AdornmentSubViewTests.cs +++ b/UnitTests/View/Adornment/AdornmentSubViewTests.cs @@ -31,7 +31,7 @@ public class AdornmentSubViewTests (ITestOutputHelper output) subView.Margin.Thickness = new Thickness (subViewMargin); view.Margin.Add (subView); - var foundView = View.FindDeepestView (view, 0, 0); + var foundView = View.FindDeepestView (view, new (0, 0)); bool found = foundView == subView || foundView == subView.Margin; Assert.Equal (expectedFound, found); @@ -58,7 +58,7 @@ public class AdornmentSubViewTests (ITestOutputHelper output) }; view.Padding.Add (subView); - Assert.Equal (view.Padding, View.FindDeepestView (view, 0, 0)); + Assert.Equal (view.Padding, View.FindDeepestView (view, new (0, 0))); } [Fact] diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index 67687702d..58d59e8d4 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -80,22 +80,22 @@ public class FindDeepestViewTests () view.Padding.Thickness = new Thickness (paddingThickness); Type? containedType = null; - if (view.Contains (testX, testY)) + if (view.Contains (new (testX, testY))) { containedType = view.GetType (); } - if (view.Margin.Contains (testX, testY)) + if (view.Margin.Contains (new (testX, testY))) { containedType = view.Margin.GetType (); } - if (view.Border.Contains (testX, testY)) + if (view.Border.Contains (new (testX, testY))) { containedType = view.Border.GetType (); } - if (view.Padding.Contains (testX, testY)) + if (view.Padding.Contains (new (testX, testY))) { containedType = view.Padding.GetType (); } @@ -115,7 +115,7 @@ public class FindDeepestViewTests () Width = 10, Height = 10, }; - Assert.Same (start, View.FindDeepestView (start, testX, testY)); + Assert.Same (start, View.FindDeepestView (start, new (testX, testY))); } // Test that FindDeepestView returns null if the start view has no subviews and coords are outside the view @@ -131,7 +131,7 @@ public class FindDeepestViewTests () Width = 10, Height = 10, }; - Assert.Null (View.FindDeepestView (start, testX, testY)); + Assert.Null (View.FindDeepestView (start, new (testX, testY))); } [Theory] @@ -147,7 +147,7 @@ public class FindDeepestViewTests () Visible = false, }; - Assert.Null (View.FindDeepestView (start, testX, testY)); + Assert.Null (View.FindDeepestView (start, new (testX, testY))); } // Test that FindDeepestView returns the correct view if the start view has subviews @@ -174,7 +174,7 @@ public class FindDeepestViewTests () }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -202,7 +202,7 @@ public class FindDeepestViewTests () }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -233,7 +233,7 @@ public class FindDeepestViewTests () subview.Visible = true; Assert.True (subview.Visible); Assert.False (start.Visible); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -265,7 +265,7 @@ public class FindDeepestViewTests () }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -296,7 +296,7 @@ public class FindDeepestViewTests () }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -328,7 +328,7 @@ public class FindDeepestViewTests () start.BeginInit(); start.EndInit(); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -362,7 +362,7 @@ public class FindDeepestViewTests () }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedAdornmentType, found!.GetType ()); } @@ -393,7 +393,7 @@ public class FindDeepestViewTests () subview.Margin.Thickness = new Thickness (1); start.Add (subview); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == subview); } @@ -438,7 +438,7 @@ public class FindDeepestViewTests () start.BeginInit(); start.EndInit(); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == paddingSubview); } @@ -487,7 +487,7 @@ public class FindDeepestViewTests () start.BeginInit (); start.EndInit (); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, found == paddingSubview); } @@ -529,7 +529,7 @@ public class FindDeepestViewTests () start.Add (subviews [0]); - var found = View.FindDeepestView (start, testX, testY); + var found = View.FindDeepestView (start, new (testX, testY)); Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!)); } } diff --git a/UnitTests/View/Layout/Pos.Tests.cs b/UnitTests/View/Layout/Pos.Tests.cs index bf82c4c0e..3ff679d02 100644 --- a/UnitTests/View/Layout/Pos.Tests.cs +++ b/UnitTests/View/Layout/Pos.Tests.cs @@ -906,7 +906,7 @@ public class PosTests (ITestOutputHelper output) Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame); Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame); Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame); - var foundView = View.FindDeepestView (top, 9, 4); + var foundView = View.FindDeepestView (top, new (9, 4)); Assert.Equal (foundView, view2); } diff --git a/UnitTests/View/NavigationTests.cs b/UnitTests/View/NavigationTests.cs index 533bc41bd..dc41edda1 100644 --- a/UnitTests/View/NavigationTests.cs +++ b/UnitTests/View/NavigationTests.cs @@ -867,7 +867,7 @@ public class NavigationTests screen = top.ViewportToScreen (new (-1, -1, 0, 0)); Assert.Equal (0, screen.X); Assert.Equal (0, screen.Y); - var found = View.FindDeepestView (top, 0, 0); + var found = View.FindDeepestView (top, new (0, 0)); Assert.Equal (top.Border, found); Assert.Equal (0, found.Frame.X); @@ -876,11 +876,11 @@ public class NavigationTests screen = top.ViewportToScreen (new (3, 2, 0, 0)); Assert.Equal (4, screen.X); Assert.Equal (3, screen.Y); - found = View.FindDeepestView (top, screen.X, screen.Y); + found = View.FindDeepestView (top, new (screen.X, screen.Y)); Assert.Equal (view, found); //Assert.Equal (0, found.FrameToScreen ().X); //Assert.Equal (0, found.FrameToScreen ().Y); - found = View.FindDeepestView (top, 3, 2); + found = View.FindDeepestView (top, new (3, 2)); Assert.Equal (top, found); //Assert.Equal (3, found.FrameToScreen ().X); //Assert.Equal (2, found.FrameToScreen ().Y); @@ -888,14 +888,14 @@ public class NavigationTests screen = top.ViewportToScreen (new (12, 2, 0, 0)); Assert.Equal (13, screen.X); Assert.Equal (3, screen.Y); - found = View.FindDeepestView (top, screen.X, screen.Y); + found = View.FindDeepestView (top, new (screen.X, screen.Y)); Assert.Equal (view, found); //Assert.Equal (9, found.FrameToScreen ().X); //Assert.Equal (0, found.FrameToScreen ().Y); screen = top.ViewportToScreen (new (13, 2, 0, 0)); Assert.Equal (14, screen.X); Assert.Equal (3, screen.Y); - found = View.FindDeepestView (top, 13, 2); + found = View.FindDeepestView (top, new (13, 2)); Assert.Equal (top, found); //Assert.Equal (13, found.FrameToScreen ().X); //Assert.Equal (2, found.FrameToScreen ().Y); @@ -903,7 +903,7 @@ public class NavigationTests screen = top.ViewportToScreen (new (14, 3, 0, 0)); Assert.Equal (15, screen.X); Assert.Equal (4, screen.Y); - found = View.FindDeepestView (top, 14, 3); + found = View.FindDeepestView (top, new (14, 3)); Assert.Equal (top, found); //Assert.Equal (14, found.FrameToScreen ().X); //Assert.Equal (3, found.FrameToScreen ().Y); @@ -925,28 +925,28 @@ public class NavigationTests screen = view.ViewportToScreen (new (-4, -3, 0, 0)); Assert.Equal (0, screen.X); Assert.Equal (0, screen.Y); - found = View.FindDeepestView (top, 0, 0); + found = View.FindDeepestView (top, new (0, 0)); Assert.Equal (top.Border, found); Assert.Equal (new Point (-1, -1), view.ScreenToFrame (new (3, 2))); screen = view.ViewportToScreen (new (0, 0, 0, 0)); Assert.Equal (4, screen.X); Assert.Equal (3, screen.Y); - found = View.FindDeepestView (top, 4, 3); + found = View.FindDeepestView (top, new (4, 3)); Assert.Equal (view, found); Assert.Equal (new Point (9, -1), view.ScreenToFrame (new (13, 2))); screen = view.ViewportToScreen (new (10, 0, 0, 0)); Assert.Equal (14, screen.X); Assert.Equal (3, screen.Y); - found = View.FindDeepestView (top, 14, 3); + found = View.FindDeepestView (top, new (14, 3)); Assert.Equal (top, found); Assert.Equal (new Point (10, 0), view.ScreenToFrame (new (14, 3))); screen = view.ViewportToScreen (new (11, 1, 0, 0)); Assert.Equal (15, screen.X); Assert.Equal (4, screen.Y); - found = View.FindDeepestView (top, 15, 4); + found = View.FindDeepestView (top, new (15, 4)); Assert.Equal (top, found); } @@ -1021,27 +1021,27 @@ public class NavigationTests screen = top.ViewportToScreen (new (-4, -3, 0, 0)); Assert.Equal (0, screen.X); Assert.Equal (0, screen.Y); - var found = View.FindDeepestView (top, -4, -3); + var found = View.FindDeepestView (top, new (-4, -3)); Assert.Null (found); Assert.Equal (Point.Empty, top.ScreenToFrame (new (3, 2))); screen = top.ViewportToScreen (new (0, 0, 0, 0)); Assert.Equal (4, screen.X); Assert.Equal (3, screen.Y); - Assert.Equal (top.Border, View.FindDeepestView (top, 3, 2)); + Assert.Equal (top.Border, View.FindDeepestView (top, new (3, 2))); //Assert.Equal (0, found.FrameToScreen ().X); //Assert.Equal (0, found.FrameToScreen ().Y); Assert.Equal (new Point (10, 0), top.ScreenToFrame (new (13, 2))); screen = top.ViewportToScreen (new (10, 0, 0, 0)); Assert.Equal (14, screen.X); Assert.Equal (3, screen.Y); - Assert.Equal (top.Border, View.FindDeepestView (top, 13, 2)); + Assert.Equal (top.Border, View.FindDeepestView (top, new (13, 2))); //Assert.Equal (10, found.FrameToScreen ().X); //Assert.Equal (0, found.FrameToScreen ().Y); Assert.Equal (new Point (11, 1), top.ScreenToFrame (new (14, 3))); screen = top.ViewportToScreen (new (11, 1, 0, 0)); Assert.Equal (15, screen.X); Assert.Equal (4, screen.Y); - Assert.Equal (top, View.FindDeepestView (top, 14, 3)); + Assert.Equal (top, View.FindDeepestView (top, new (14, 3))); // view Assert.Equal (new Point (-7, -5), view.ScreenToFrame (new (0, 0))); @@ -1057,32 +1057,32 @@ public class NavigationTests screen = view.ViewportToScreen (new (-6, -4, 0, 0)); Assert.Equal (1, screen.X); Assert.Equal (1, screen.Y); - Assert.Null (View.FindDeepestView (top, 1, 1)); + Assert.Null (View.FindDeepestView (top, new (1, 1))); Assert.Equal (new Point (-4, -3), view.ScreenToFrame (new (3, 2))); screen = view.ViewportToScreen (new (-3, -2, 0, 0)); Assert.Equal (4, screen.X); Assert.Equal (3, screen.Y); - Assert.Equal (top, View.FindDeepestView (top, 4, 3)); + Assert.Equal (top, View.FindDeepestView (top, new (4, 3))); Assert.Equal (new Point (-1, -1), view.ScreenToFrame (new (6, 4))); screen = view.ViewportToScreen (new (0, 0, 0, 0)); Assert.Equal (7, screen.X); Assert.Equal (5, screen.Y); - Assert.Equal (view, View.FindDeepestView (top, 7, 5)); + Assert.Equal (view, View.FindDeepestView (top, new (7, 5))); Assert.Equal (new Point (6, -1), view.ScreenToFrame (new (13, 4))); screen = view.ViewportToScreen (new (7, 0, 0, 0)); Assert.Equal (14, screen.X); Assert.Equal (5, screen.Y); - Assert.Equal (view, View.FindDeepestView (top, 14, 5)); + Assert.Equal (view, View.FindDeepestView (top, new (14, 5))); Assert.Equal (new Point (7, -2), view.ScreenToFrame (new (14, 3))); screen = view.ViewportToScreen (new (8, -1, 0, 0)); Assert.Equal (15, screen.X); Assert.Equal (4, screen.Y); - Assert.Equal (top, View.FindDeepestView (top, 15, 4)); + Assert.Equal (top, View.FindDeepestView (top, new (15, 4))); Assert.Equal (new Point (16, -2), view.ScreenToFrame (new (23, 3))); screen = view.ViewportToScreen (new (17, -1, 0, 0)); Assert.Equal (24, screen.X); Assert.Equal (4, screen.Y); - Assert.Null (View.FindDeepestView (top, 24, 4)); + Assert.Null (View.FindDeepestView (top, new (24, 4))); } [Fact]