Debugging Pos.Center + x in SetRelativeLayout - WIP

This commit is contained in:
Tig Kindel
2023-12-22 09:53:11 -07:00
parent eb037b528c
commit bb04a629ff
6 changed files with 94 additions and 68 deletions

View File

@@ -504,6 +504,7 @@ namespace Terminal.Gui.ViewTests {
var runState = Application.Begin (top);
// BUGBUG: This is a SetRelativeLayout test. It should be moved to SetRelativeLayoutTests.cs
view.Width = Dim.Fill ();
view.Height = Dim.Fill ();
Assert.Equal (10, view.Bounds.Width);
@@ -519,6 +520,7 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (79, view.Bounds.Width);
Assert.Equal (24, view.Bounds.Height);
// BUGBUG: This is a SetRelativeLayout test. It should be moved to SetRelativeLayoutTests.cs
view.X = 0;
view.Y = 0;
Assert.Equal ("Absolute(0)", view.X.ToString ());
@@ -532,6 +534,8 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (0, view.Bounds.Y);
Assert.Equal (80, view.Bounds.Width);
Assert.Equal (25, view.Bounds.Height);
// BUGBUG: This is a layout test. It should be moved to LayoutTests.cs
bool layoutStarted = false;
view.LayoutStarted += (s, e) => layoutStarted = true;
view.OnLayoutStarted (null);
@@ -539,14 +543,18 @@ namespace Terminal.Gui.ViewTests {
view.LayoutComplete += (s, e) => layoutStarted = false;
view.OnLayoutComplete (null);
Assert.False (layoutStarted);
view.X = Pos.Center () - 41;
view.Y = Pos.Center () - 13;
view.SetRelativeLayout (top.Bounds);
top.LayoutSubviews (); // BUGBUG: v2 - ??
view.BoundsToScreen (0, 0, out rcol, out rrow);
Assert.Equal (-41, rcol);
Assert.Equal (-13, rrow);
// This test has been moved to SetRlativeLayoutTests because it is testing
// SetRelativeLayout. In addition, the old test was bogus because it was testing the wrong thing (and
// because in v1 Pos.Center was broken in this regard!
//view.X = Pos.Center () - 41;
//view.Y = Pos.Center () - 13;
//view.SetRelativeLayout (top.Bounds);
//top.LayoutSubviews (); // BUGBUG: v2 - ??
//view.BoundsToScreen (0, 0, out rcol, out rrow);
//Assert.Equal (-41, rcol);
//Assert.Equal (-13, rrow);
Application.End (runState);
}
@@ -1340,16 +1348,15 @@ At 0,0
var frame = new FrameView ();
var label = new Label ("This should be the first line.") {
TextAlignment = Terminal.Gui.TextAlignment.Centered,
ColorScheme = Colors.Menu,
Width = Dim.Fill (),
X = Pos.Center (),
Y = Pos.Center () - 2 // center minus 2 minus two lines top and bottom borders equal to zero (4-2-2=0)
X = 0, // don't overcomplicate unit tests
Y = 0
};
var button = new Button ("Press me!") {
X = Pos.Center (),
Y = Pos.Center ()
X = 0, // don't overcomplicate unit tests
Y = 1
};
frame.Add (label, button);
@@ -1388,19 +1395,7 @@ At 0,0
frame.Frame.Left, frame.Frame.Top,
frame.Frame.Right, frame.Frame.Bottom));
Assert.Equal (new Rect (0, 0, 38, 1), label.Frame);
Assert.Equal (new Rect (12, 2, 13, 1), button.Frame);
var expected = @$"
┌──────────────────────────────────────┐
│ This should be the first line. │
│ │
│ {CM.Glyphs.LeftBracket} Press me! {CM.Glyphs.RightBracket} │
│ │
│ │
│ │
└──────────────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 13, 1), button.Frame); // this proves frame was set
Application.End (runState);
}