Found and fixed bug in non-recursive FindDeepestView; added reltaed unit test

This commit is contained in:
Tig
2024-04-10 11:18:17 -04:00
parent d654c9c281
commit e8640e9d92
3 changed files with 130 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
#define OTHER_CONTROLS
//#define OTHER_CONTROLS
using System;
using System.Collections.Generic;

View File

@@ -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)]