| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840 |
- #nullable enable
- namespace UnitTests.ViewMouseTests;
- [Trait ("Category", "Input")]
- public class GetViewsUnderLocationTests
- {
- [Theory]
- [InlineData (0, 0, 0, 0, 0, -1, -1, new string [] { })]
- [InlineData (0, 0, 0, 0, 0, 0, 0, new [] { "Top" })]
- [InlineData (0, 0, 0, 0, 0, 1, 1, new [] { "Top" })]
- [InlineData (0, 0, 0, 0, 0, 4, 4, new [] { "Top" })]
- [InlineData (0, 0, 0, 0, 0, 9, 9, new [] { "Top" })]
- [InlineData (0, 0, 0, 0, 0, 10, 10, new string [] { })]
- [InlineData (1, 1, 0, 0, 0, -1, -1, new string [] { })]
- [InlineData (1, 1, 0, 0, 0, 0, 0, new string [] { })]
- [InlineData (1, 1, 0, 0, 0, 1, 1, new [] { "Top" })]
- [InlineData (1, 1, 0, 0, 0, 4, 4, new [] { "Top" })]
- [InlineData (1, 1, 0, 0, 0, 9, 9, new [] { "Top" })]
- [InlineData (1, 1, 0, 0, 0, 10, 10, new [] { "Top" })]
- [InlineData (0, 0, 1, 0, 0, -1, -1, new string [] { })]
- [InlineData (0, 0, 1, 0, 0, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 0, 0, 1, 1, new [] { "Top" })]
- [InlineData (0, 0, 1, 0, 0, 4, 4, new [] { "Top" })]
- [InlineData (0, 0, 1, 0, 0, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 0, 0, 10, 10, new string [] { })]
- [InlineData (0, 0, 1, 1, 0, -1, -1, new string [] { })]
- [InlineData (0, 0, 1, 1, 0, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 1, 0, 1, 1, new [] { "Top", "Border" })]
- [InlineData (0, 0, 1, 1, 0, 4, 4, new [] { "Top" })]
- [InlineData (0, 0, 1, 1, 0, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 1, 0, 10, 10, new string [] { })]
- [InlineData (0, 0, 1, 1, 1, -1, -1, new string [] { })]
- [InlineData (0, 0, 1, 1, 1, 0, 0, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 1, 1, 1, 1, new [] { "Top", "Border" })]
- [InlineData (0, 0, 1, 1, 1, 2, 2, new [] { "Top", "Padding" })]
- [InlineData (0, 0, 1, 1, 1, 4, 4, new [] { "Top" })]
- [InlineData (0, 0, 1, 1, 1, 9, 9, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (0, 0, 1, 1, 1, 10, 10, new string [] { })]
- [InlineData (1, 1, 1, 0, 0, -1, -1, new string [] { })]
- [InlineData (1, 1, 1, 0, 0, 0, 0, new string [] { })]
- [InlineData (1, 1, 1, 0, 0, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (1, 1, 1, 0, 0, 4, 4, new [] { "Top" })]
- [InlineData (1, 1, 1, 0, 0, 9, 9, new [] { "Top" })]
- [InlineData (1, 1, 1, 0, 0, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (1, 1, 1, 1, 0, -1, -1, new string [] { })]
- [InlineData (1, 1, 1, 1, 0, 0, 0, new string [] { })]
- [InlineData (1, 1, 1, 1, 0, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (1, 1, 1, 1, 0, 4, 4, new [] { "Top" })]
- [InlineData (1, 1, 1, 1, 0, 9, 9, new [] { "Top", "Border" })]
- [InlineData (1, 1, 1, 1, 0, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (1, 1, 1, 1, 1, -1, -1, new string [] { })]
- [InlineData (1, 1, 1, 1, 1, 0, 0, new string [] { })]
- [InlineData (1, 1, 1, 1, 1, 1, 1, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- [InlineData (1, 1, 1, 1, 1, 2, 2, new [] { "Top", "Border" })]
- [InlineData (1, 1, 1, 1, 1, 3, 3, new [] { "Top", "Padding" })]
- [InlineData (1, 1, 1, 1, 1, 4, 4, new [] { "Top" })]
- [InlineData (1, 1, 1, 1, 1, 8, 8, new [] { "Top", "Padding" })]
- [InlineData (1, 1, 1, 1, 1, 9, 9, new [] { "Top", "Border" })]
- [InlineData (1, 1, 1, 1, 1, 10, 10, new string [] { })] //margin is ViewportSettings.TransparentToMouse
- public void Top_Adornments_Returns_Correct_View (
- int frameX,
- int frameY,
- int marginThickness,
- int borderThickness,
- int paddingThickness,
- int testX,
- int testY,
- string [] expectedViewsFound
- )
- {
- // Arrange
- Application.TopRunnable = new ()
- {
- Id = "Top",
- Frame = new (frameX, frameY, 10, 10)
- };
- Application.TopRunnable.Margin!.Thickness = new (marginThickness);
- Application.TopRunnable.Margin!.Id = "Margin";
- Application.TopRunnable.Border!.Thickness = new (borderThickness);
- Application.TopRunnable.Border!.Id = "Border";
- Application.TopRunnable.Padding!.Thickness = new (paddingThickness);
- Application.TopRunnable.Padding.Id = "Padding";
- var location = new Point (testX, testY);
- // Act
- List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
- // Assert
- if (expectedViewsFound.Length == 0)
- {
- Assert.Empty (viewsUnderMouse);
- }
- else
- {
- string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
- Assert.Equal (expectedViewsFound, foundIds);
- }
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (2, 2)]
- public void Returns_Top_If_No_SubViews (int testX, int testY)
- {
- // Arrange
- Application.TopRunnable = new ()
- {
- Frame = new (0, 0, 10, 10)
- };
- var location = new Point (testX, testY);
- // Act
- List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
- // Assert
- Assert.Contains (viewsUnderMouse, v => v == Application.TopRunnable);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation returns the correct view if the start view has no subviews
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (2, 2)]
- public void Returns_Start_If_No_SubViews (int testX, int testY)
- {
- Application.ResetState (true);
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- Assert.Same (Application.TopRunnable, Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ());
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation returns the correct view if the start view has subviews
- [Theory]
- [InlineData (0, 0, false)]
- [InlineData (1, 1, false)]
- [InlineData (9, 9, false)]
- [InlineData (10, 10, false)]
- [InlineData (6, 7, false)]
- [InlineData (1, 2, true)]
- [InlineData (5, 6, true)]
- public void Returns_Correct_If_SubViews (int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- var subview = new View
- {
- X = 1, Y = 2,
- Width = 5, Height = 5
- };
- Application.TopRunnable.Add (subview);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0, false)]
- [InlineData (1, 1, false)]
- [InlineData (9, 9, false)]
- [InlineData (10, 10, false)]
- [InlineData (6, 7, false)]
- [InlineData (1, 2, false)]
- [InlineData (5, 6, false)]
- public void Returns_Null_If_SubView_NotVisible (int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- var subview = new View
- {
- X = 1, Y = 2,
- Width = 5, Height = 5,
- Visible = false
- };
- Application.TopRunnable.Add (subview);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0, false)]
- [InlineData (1, 1, false)]
- [InlineData (9, 9, false)]
- [InlineData (10, 10, false)]
- [InlineData (6, 7, false)]
- [InlineData (1, 2, false)]
- [InlineData (5, 6, false)]
- public void Returns_Null_If_Not_Visible_And_SubView_Visible (int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10,
- Visible = false
- };
- var subview = new View
- {
- X = 1, Y = 2,
- Width = 5, Height = 5
- };
- Application.TopRunnable.Add (subview);
- subview.Visible = true;
- Assert.True (subview.Visible);
- Assert.False (Application.TopRunnable.Visible);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation works if the start view has positive Adornments
- [Theory]
- [InlineData (0, 0, false)]
- [InlineData (1, 1, false)]
- [InlineData (9, 9, false)]
- [InlineData (10, 10, false)]
- [InlineData (7, 8, false)]
- [InlineData (1, 2, false)]
- [InlineData (2, 3, true)]
- [InlineData (5, 6, true)]
- [InlineData (6, 7, true)]
- public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- Application.TopRunnable.Margin!.Thickness = new (1);
- var subview = new View
- {
- X = 1, Y = 2,
- Width = 5, Height = 5
- };
- Application.TopRunnable.Add (subview);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation works if the start view has offset Viewport location
- [Theory]
- [InlineData (1, 0, 0, true)]
- [InlineData (1, 1, 1, true)]
- [InlineData (1, 2, 2, false)]
- [InlineData (-1, 3, 3, true)]
- [InlineData (-1, 2, 2, true)]
- [InlineData (-1, 1, 1, false)]
- [InlineData (-1, 0, 0, false)]
- public void Returns_Correct_If_Start_Has_Offset_Viewport (int offset, int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10,
- ViewportSettings = ViewportSettingsFlags.AllowNegativeLocation
- };
- Application.TopRunnable.Viewport = new (offset, offset, 10, 10);
- var subview = new View
- {
- X = 1, Y = 1,
- Width = 2, Height = 2
- };
- Application.TopRunnable.Add (subview);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (9, 9, true)]
- [InlineData (0, 0, false)]
- [InlineData (1, 1, false)]
- [InlineData (10, 10, false)]
- [InlineData (7, 8, false)]
- [InlineData (1, 2, false)]
- [InlineData (2, 3, false)]
- [InlineData (5, 6, false)]
- [InlineData (6, 7, false)]
- public void Returns_Correct_If_Start_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- Application.TopRunnable.Padding!.Thickness = new (1);
- var subview = new View
- {
- X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1),
- Width = 1, Height = 1
- };
- Application.TopRunnable.Padding.Add (subview);
- Application.TopRunnable.BeginInit ();
- Application.TopRunnable.EndInit ();
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == subview);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0, new string [] { })]
- [InlineData (9, 9, new string [] { })]
- [InlineData (1, 1, new [] { "Top", "Border" })]
- [InlineData (8, 8, new [] { "Top", "Border" })]
- [InlineData (2, 2, new [] { "Top", "Padding" })]
- [InlineData (7, 7, new [] { "Top", "Padding" })]
- [InlineData (5, 5, new [] { "Top" })]
- public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, string [] expectedViewsFound)
- {
- Application.ResetState (true);
- Application.TopRunnable = new ()
- {
- Id = "Top",
- Width = 10, Height = 10
- };
- Application.TopRunnable.Margin!.Thickness = new (1);
- Application.TopRunnable.Margin!.Id = "Margin";
- Application.TopRunnable.Border!.Thickness = new (1);
- Application.TopRunnable.Border!.Id = "Border";
- Application.TopRunnable.Padding!.Thickness = new (1);
- Application.TopRunnable.Padding.Id = "Padding";
- var subview = new View
- {
- Id = "SubView",
- X = 1, Y = 1,
- Width = 1, Height = 1
- };
- Application.TopRunnable.Add (subview);
- List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
- string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
- Assert.Equal (expectedViewsFound, foundIds);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation works if the subview has positive Adornments
- [Theory]
- [InlineData (0, 0, new [] { "Top" })]
- [InlineData (1, 1, new [] { "Top" })]
- [InlineData (9, 9, new [] { "Top" })]
- [InlineData (10, 10, new string [] { })]
- [InlineData (7, 8, new [] { "Top" })]
- [InlineData (6, 7, new [] { "Top" })]
- [InlineData (1, 2, new [] { "Top", "subview", "border" })]
- [InlineData (5, 6, new [] { "Top", "subview", "border" })]
- [InlineData (2, 3, new [] { "Top", "subview" })]
- public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, string [] expectedViewsFound)
- {
- Application.TopRunnable = new ()
- {
- Id = "Top",
- Width = 10, Height = 10
- };
- var subview = new View
- {
- Id = "subview",
- X = 1, Y = 2,
- Width = 5, Height = 5
- };
- subview.Border!.Thickness = new (1);
- subview.Border!.Id = "border";
- Application.TopRunnable.Add (subview);
- List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
- string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
- Assert.Equal (expectedViewsFound, foundIds);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation works if the subview has positive Adornments
- [Theory]
- [InlineData (0, 0, new [] { "Top" })]
- [InlineData (1, 1, new [] { "Top" })]
- [InlineData (9, 9, new [] { "Top" })]
- [InlineData (10, 10, new string [] { })]
- [InlineData (7, 8, new [] { "Top" })]
- [InlineData (6, 7, new [] { "Top" })]
- [InlineData (1, 2, new [] { "Top" })]
- [InlineData (5, 6, new [] { "Top" })]
- [InlineData (2, 3, new [] { "Top", "subview" })]
- public void Returns_Correct_If_SubView_Has_Adornments_With_TransparentMouse (int testX, int testY, string [] expectedViewsFound)
- {
- Application.TopRunnable = new ()
- {
- Id = "Top",
- Width = 10, Height = 10
- };
- var subview = new View
- {
- Id = "subview",
- X = 1, Y = 2,
- Width = 5, Height = 5
- };
- subview.Border!.Thickness = new (1);
- subview.Border!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
- subview.Border!.Id = "border";
- Application.TopRunnable.Add (subview);
- List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
- string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
- Assert.Equal (expectedViewsFound, foundIds);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [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)
- {
- Application.TopRunnable = new ()
- {
- 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);
- Application.TopRunnable.Add (subview);
- Application.TopRunnable.BeginInit ();
- Application.TopRunnable.EndInit ();
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == paddingSubView);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [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)
- {
- Application.TopRunnable = new ()
- {
- 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.SetContentSize (new (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);
- Application.TopRunnable.Add (subview);
- Application.TopRunnable.BeginInit ();
- Application.TopRunnable.EndInit ();
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, found == paddingSubView);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- // Test that GetViewsUnderLocation works with nested subviews
- [Theory]
- [InlineData (0, 0, -1)]
- [InlineData (9, 9, -1)]
- [InlineData (10, 10, -1)]
- [InlineData (1, 1, 0)]
- [InlineData (1, 2, 0)]
- [InlineData (2, 2, 1)]
- [InlineData (3, 3, 2)]
- [InlineData (5, 5, 2)]
- public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expectedSubViewFound)
- {
- Application.TopRunnable = new ()
- {
- Width = 10, Height = 10
- };
- var numSubViews = 3;
- List<View> subviews = new ();
- for (var i = 0; i < numSubViews; i++)
- {
- var subview = new View
- {
- X = 1, Y = 1,
- Width = 5, Height = 5
- };
- subviews.Add (subview);
- if (i > 0)
- {
- subviews [i - 1].Add (subview);
- }
- }
- Application.TopRunnable.Add (subviews [0]);
- View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
- Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!));
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0, new [] { "top" })]
- [InlineData (9, 9, new [] { "top" })]
- [InlineData (10, 10, new string [] { })]
- [InlineData (1, 1, new [] { "top", "view" })]
- [InlineData (1, 2, new [] { "top", "view" })]
- [InlineData (2, 1, new [] { "top", "view" })]
- [InlineData (2, 2, new [] { "top", "view", "subView" })]
- [InlineData (3, 3, new [] { "top" })] // clipped
- [InlineData (2, 3, new [] { "top" })] // clipped
- public void Tiled_SubViews (int mouseX, int mouseY, string [] viewIdStrings)
- {
- // Arrange
- Application.TopRunnable = new ()
- {
- Frame = new (0, 0, 10, 10),
- Id = "top"
- };
- var view = new View
- {
- Id = "view",
- X = 1,
- Y = 1,
- Width = 2,
- Height = 2,
- Arrangement = ViewArrangement.Overlapped
- }; // at 1,1 to 3,2 (screen)
- var subView = new View
- {
- Id = "subView",
- X = 1,
- Y = 1,
- Width = 2,
- Height = 2,
- Arrangement = ViewArrangement.Overlapped
- }; // at 2,2 to 4,3 (screen)
- view.Add (subView);
- Application.TopRunnable.Add (view);
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
- string [] foundIds = found.Select (v => v!.Id).ToArray ();
- Assert.Equal (viewIdStrings, foundIds);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Theory]
- [InlineData (0, 0, new [] { "top" })]
- [InlineData (9, 9, new [] { "top" })]
- [InlineData (10, 10, new string [] { })]
- [InlineData (-1, -1, new string [] { })]
- [InlineData (1, 1, new [] { "top", "view" })]
- [InlineData (1, 2, new [] { "top", "view" })]
- [InlineData (2, 1, new [] { "top", "view" })]
- [InlineData (2, 2, new [] { "top", "view", "popover" })]
- [InlineData (3, 3, new [] { "top" })] // clipped
- [InlineData (2, 3, new [] { "top" })] // clipped
- public void Popover (int mouseX, int mouseY, string [] viewIdStrings)
- {
- // Arrange
- Application.TopRunnable = new ()
- {
- Frame = new (0, 0, 10, 10),
- Id = "top"
- };
- var view = new View
- {
- Id = "view",
- X = 1,
- Y = 1,
- Width = 2,
- Height = 2,
- Arrangement = ViewArrangement.Overlapped
- }; // at 1,1 to 3,2 (screen)
- var popOver = new View
- {
- Id = "popover",
- X = 1,
- Y = 1,
- Width = 2,
- Height = 2,
- Arrangement = ViewArrangement.Overlapped
- }; // at 2,2 to 4,3 (screen)
- view.Add (popOver);
- Application.TopRunnable.Add (view);
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
- string [] foundIds = found.Select (v => v!.Id).ToArray ();
- Assert.Equal (viewIdStrings, foundIds);
- Application.TopRunnable.Dispose ();
- Application.ResetState (true);
- }
- [Fact]
- public void Returns_TopToplevel_When_Point_Inside_Only_TopToplevel ()
- {
- Application.ResetState (true);
- Toplevel topToplevel = new ()
- {
- Id = "topToplevel",
- Frame = new (0, 0, 20, 20)
- };
- Toplevel secondaryToplevel = new ()
- {
- Id = "secondaryToplevel",
- Frame = new (5, 5, 10, 10)
- };
- secondaryToplevel.Margin!.Thickness = new (1);
- secondaryToplevel.Layout ();
- Application.SessionStack.Clear ();
- Application.SessionStack.Push (topToplevel);
- Application.SessionStack.Push (secondaryToplevel);
- Application.TopRunnable = secondaryToplevel;
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse);
- Assert.Contains (found, v => v?.Id == topToplevel.Id);
- Assert.Contains (found, v => v == topToplevel);
- topToplevel.Dispose ();
- secondaryToplevel.Dispose ();
- Application.SessionStack.Clear ();
- Application.ResetState (true);
- }
- [Fact]
- public void Returns_SecondaryToplevel_When_Point_Inside_Only_SecondaryToplevel ()
- {
- Application.ResetState (true);
- Toplevel topToplevel = new ()
- {
- Id = "topToplevel",
- Frame = new (0, 0, 20, 20)
- };
- Toplevel secondaryToplevel = new ()
- {
- Id = "secondaryToplevel",
- Frame = new (5, 5, 10, 10)
- };
- secondaryToplevel.Margin!.Thickness = new (1);
- secondaryToplevel.Layout ();
- Application.SessionStack.Clear ();
- Application.SessionStack.Push (topToplevel);
- Application.SessionStack.Push (secondaryToplevel);
- Application.TopRunnable = secondaryToplevel;
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse);
- Assert.Contains (found, v => v?.Id == secondaryToplevel.Id);
- Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id);
- topToplevel.Dispose ();
- secondaryToplevel.Dispose ();
- Application.SessionStack.Clear ();
- Application.ResetState (true);
- }
- [Fact]
- public void Returns_Depends_On_Margin_ViewportSettings_When_Point_In_Margin_Of_SecondaryToplevel ()
- {
- Application.ResetState (true);
- Toplevel topToplevel = new ()
- {
- Id = "topToplevel",
- Frame = new (0, 0, 20, 20)
- };
- Toplevel secondaryToplevel = new ()
- {
- Id = "secondaryToplevel",
- Frame = new (5, 5, 10, 10)
- };
- secondaryToplevel.Margin!.Thickness = new (1);
- Application.SessionStack.Clear ();
- Application.SessionStack.Push (topToplevel);
- Application.SessionStack.Push (secondaryToplevel);
- Application.TopRunnable = secondaryToplevel;
- secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.None;
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
- Assert.Contains (found, v => v == secondaryToplevel);
- Assert.Contains (found, v => v == secondaryToplevel.Margin);
- Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id);
- secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
- found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
- Assert.DoesNotContain (found, v => v == secondaryToplevel);
- Assert.DoesNotContain (found, v => v == secondaryToplevel.Margin);
- Assert.Contains (found, v => v?.Id == topToplevel.Id);
- topToplevel.Dispose ();
- secondaryToplevel.Dispose ();
- Application.SessionStack.Clear ();
- Application.ResetState (true);
- }
- [Fact]
- public void Returns_Empty_When_Point_Outside_All_Toplevels ()
- {
- Application.ResetState (true);
- Toplevel topToplevel = new ()
- {
- Id = "topToplevel",
- Frame = new (0, 0, 20, 20)
- };
- Toplevel secondaryToplevel = new ()
- {
- Id = "secondaryToplevel",
- Frame = new (5, 5, 10, 10)
- };
- secondaryToplevel.Margin!.Thickness = new (1);
- secondaryToplevel.Layout ();
- Application.SessionStack.Clear ();
- Application.SessionStack.Push (topToplevel);
- Application.SessionStack.Push (secondaryToplevel);
- Application.TopRunnable = secondaryToplevel;
- List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse);
- Assert.Empty (found);
- topToplevel.Dispose ();
- secondaryToplevel.Dispose ();
- Application.SessionStack.Clear ();
- Application.ResetState (true);
- }
- }
|