diff --git a/Terminal.Gui/View/ViewLayout.cs b/Terminal.Gui/View/ViewLayout.cs index bba4d126b..d328df83a 100644 --- a/Terminal.Gui/View/ViewLayout.cs +++ b/Terminal.Gui/View/ViewLayout.cs @@ -280,7 +280,7 @@ namespace Terminal.Gui { var height = Math.Max (0, Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); return new Rect (Point.Empty, new Size (width, height)); } - + Pos _x, _y; /// @@ -334,8 +334,11 @@ namespace Terminal.Gui { public Dim Width { get => VerifyIsInitialized (_width); set { - if (ValidatePosDim && LayoutStyle == LayoutStyle.Computed) { - CheckAbsolute (nameof (Width), _width, value); + if (ValidatePosDim) { + CheckDimAuto (); + if (LayoutStyle == LayoutStyle.Computed) { + CheckAbsolute (nameof (Width), _width, value); + } } _width = value; @@ -360,9 +363,7 @@ namespace Terminal.Gui { get => VerifyIsInitialized (_height); set { if (ValidatePosDim) { - if (value is Dim.DimAuto) { - CheckDimAuto (); - } + CheckDimAuto (); if (LayoutStyle == LayoutStyle.Computed) { CheckAbsolute (nameof (Height), _height, value); } @@ -420,10 +421,10 @@ namespace Terminal.Gui { /// void CheckDimAuto () { - if (!ValidatePosDim) { + if (!ValidatePosDim || (Width is not Dim.DimAuto && Height is not Dim.DimAuto)) { return; } - + void ThrowInvalid (View view, object checkPosDim, string name) { object bad = null; @@ -435,16 +436,16 @@ namespace Terminal.Gui { bad = dim; break; } - + if (bad != null) { - throw new InvalidOperationException (@$"{view.GetType().Name}.{name} = {bad.GetType ().Name} which depends on the SuperView's dimensions and the SuperView uses Dim.Auto."); + throw new InvalidOperationException (@$"{view.GetType ().Name}.{name} = {bad.GetType ().Name} which depends on the SuperView's dimensions and the SuperView uses Dim.Auto."); } } // Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions. foreach (var view in Subviews) { - ThrowInvalid (view, view.Width, nameof(view.Width)); - ThrowInvalid (view, view.Height, nameof(view.Height)); + ThrowInvalid (view, view.Width, nameof (view.Width)); + ThrowInvalid (view, view.Height, nameof (view.Height)); ThrowInvalid (view, view.X, nameof (view.X)); ThrowInvalid (view, view.Y, nameof (view.Y)); } @@ -774,10 +775,10 @@ namespace Terminal.Gui { case Dim.DimAuto: var thickness = GetFramesThickness (); if (width) { - var furthestRight = Subviews.Max (v => v.Frame.X + v.Frame.Width); + var furthestRight = Subviews.Count == 0 ? 0 : Subviews.Max (v => v.Frame.X + v.Frame.Width); newDimension = furthestRight + thickness.Left + thickness.Right; } else { - var furthestBottom = Subviews.Max (v => v.Frame.Y + v.Frame.Height); + var furthestBottom = Subviews.Count == 0 ? 0 : Subviews.Max (v => v.Frame.Y + v.Frame.Height); newDimension = furthestBottom + thickness.Top + thickness.Bottom; } break; diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 90dce7339..0129740fc 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -61,8 +61,8 @@ public class Dialog : Window { //Y = Pos.Center (); ValidatePosDim = true; - Width = Dim.Auto ();//Percent (85); - Height = Dim.Auto ();//Percent (85); + Width = Dim.Percent (85); + Height = Dim.Percent (85); ColorScheme = Colors.Dialog; diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 3c101a0bb..3fa25cc4c 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -420,11 +420,13 @@ public class ApplicationTests { Assert.Equal (3, count); } + // TODO: All Toplevel layout tests should be moved to ToplevelTests.cs [Fact] public void Run_Toplevel_With_Modal_View_Does_Not_Refresh_If_Not_Dirty () { Init (); var count = 0; + // Don't use Dialog here as it has more layout logic. Use Window instead. Dialog d = null; var top = Application.Top; top.DrawContent += (s, a) => count++; @@ -432,6 +434,7 @@ public class ApplicationTests { Application.Iteration += (s, a) => { iteration++; if (iteration == 0) { + // TODO: Don't use Dialog here as it has more layout logic. Use Window instead. d = new Dialog (); d.DrawContent += (s, a) => count++; Application.Run (d); @@ -453,44 +456,42 @@ public class ApplicationTests { Assert.Equal (3, count); } + // TODO: All Toplevel layout tests should be moved to ToplevelTests.cs [Fact] public void Run_A_Modal_Toplevel_Refresh_Background_On_Moving () { Init (); - var d = new Dialog () { Width = 5, Height = 5 }; + // Don't use Dialog here as it has more layout logic. Use Window instead. + var w = new Window () { Width = 5, Height = 5 }; ((FakeDriver)Application.Driver).SetBufferSize (10, 10); - var rs = Application.Begin (d); + var rs = Application.Begin (w); TestHelpers.AssertDriverContentsWithFrameAre (@" - ┌───┐ - │ │ - │ │ - │ │ - └───┘", _output); +┌───┐ +│ │ +│ │ +│ │ +└───┘", _output); var attributes = new Attribute [] { // 0 new Attribute (ColorName.White, ColorName.Black), // 1 - Colors.Dialog.Normal + Colors.Base.Normal }; TestHelpers.AssertDriverColorsAre (@" -0000000000 -0000000000 -0011111000 -0011111000 -0011111000 -0011111000 -0011111000 -0000000000 -0000000000 -0000000000 +1111100000 +1111100000 +1111100000 +1111100000 +1111100000 ", null, attributes); // TODO: In PR #2920 this breaks because the mouse is not grabbed anymore. // TODO: Move the mouse grap/drag mode from Toplevel to Border. - Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { X = 2, Y = 2, Flags = MouseFlags.Button1Pressed })); - Assert.Equal (d, Application.MouseGrabView); + Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed })); + Assert.Equal (w, Application.MouseGrabView); + // Move down and to the right. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { X = 1, Y = 1, Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition })); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" @@ -504,7 +505,7 @@ public class ApplicationTests { // 0 new Attribute (ColorName.White, ColorName.Black), // 1 - Colors.Dialog.Normal + Colors.Base.Normal }; TestHelpers.AssertDriverColorsAre (@" 0000000000 @@ -513,10 +514,6 @@ public class ApplicationTests { 0111110000 0111110000 0111110000 -0000000000 -0000000000 -0000000000 -0000000000 ", null, attributes); Application.End (rs); @@ -578,6 +575,7 @@ public class ApplicationTests { var t1 = new Toplevel (); var t2 = new Toplevel (); var t3 = new Toplevel (); + // Don't use Dialog here as it has more layout logic. Use Window instead. var d = new Dialog (); var t4 = new Toplevel (); diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index e745cf1d1..c988d5500 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -935,7 +935,8 @@ namespace Terminal.Gui.ViewsTests { │ │ └──────────────────┘", output); - var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 }; + // Don't use Dialog here as it has more layout logic. Use Window instead. + var dialog = new Window () { X = 2, Y = 2, Width = 15, Height = 4 }; dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 }); var rs = Application.Begin (dialog); @@ -992,8 +993,9 @@ namespace Terminal.Gui.ViewsTests { Assert.Equal (new Rect (0, 0, 20, 15), Application.Driver.Clip); TestHelpers.AssertDriverContentsWithFrameAre ("", output); - - var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 }; + + // Don't use Dialog here as it has more layout logic. Use Window instead. + var dialog = new Window () { X = 2, Y = 2, Width = 15, Height = 4 }; dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 }); var rs = Application.Begin (dialog); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index d7d9ca6dd..bad9a326d 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -2,7 +2,7 @@ using Xunit; using Xunit.Abstractions; -namespace Terminal.Gui.ViewsTests; +namespace Terminal.Gui.ViewsTests; public class ToplevelTests { readonly ITestOutputHelper output; @@ -700,126 +700,115 @@ public class ToplevelTests { Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void Mouse_Drag_On_Top_With_Superview_Null () { var win = new Window (); var top = Application.Top; top.Add (win); int iterations = -1; + Window testWindow; Application.Iteration += (s, a) => { iterations++; if (iterations == 0) { - ((FakeDriver)Application.Driver).SetBufferSize (40, 15); - MessageBox.Query ("", "Hello Word", "Ok"); + ((FakeDriver)Application.Driver).SetBufferSize (15, 7); + // Don't use MessageBox here; it's too complicated for this unit test; just use Window + testWindow = new Window () { + Text = "Hello", + X = 2, + Y = 2, + Width = 10, + Height = 3 + }; + Application.Run (testWindow); } else if (iterations == 1) { TestHelpers.AssertDriverContentsWithFrameAre (@$" -┌──────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ ┌──────────────────────┐ │ -│ │ Hello Word │ │ -│ │ │ │ -│ │ {CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Ok {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket} │ │ -│ └──────────────────────┘ │ -│ │ -│ │ -│ │ -│ │ -└──────────────────────────────────────┘ +┌─────────────┐ +│ │ +│ ┌────────┐ │ +│ │Hello │ │ +│ └────────┘ │ +│ │ +└─────────────┘ ", output); } else if (iterations == 2) { Assert.Null (Application.MouseGrabView); // Grab the mouse Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 8, - Y = 5, + X = 3, + Y = 2, Flags = MouseFlags.Button1Pressed })); Assert.Equal (Application.Current, Application.MouseGrabView); - Assert.Equal (new Rect (8, 5, 24, 5), Application.MouseGrabView.Frame); + Assert.Equal (new Rect (2, 2, 10, 3), Application.MouseGrabView.Frame); } else if (iterations == 3) { Assert.Equal (Application.Current, Application.MouseGrabView); // Drag to left Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 7, - Y = 5, + X = 2, + Y = 2, Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition })); + Application.Refresh (); Assert.Equal (Application.Current, Application.MouseGrabView); - Assert.Equal (new Rect (7, 5, 24, 5), Application.MouseGrabView.Frame); + Assert.Equal (new Rect (1, 2, 10, 3), Application.MouseGrabView.Frame); } else if (iterations == 4) { Assert.Equal (Application.Current, Application.MouseGrabView); TestHelpers.AssertDriverContentsWithFrameAre (@$" -┌──────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ ┌──────────────────────┐ │ -│ │ Hello Word │ │ -│ │ │ │ -│ │ {CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Ok {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket} │ │ -│ └──────────────────────┘ │ -│ │ -│ │ -│ │ -│ │ -└──────────────────────────────────────┘", output); +┌─────────────┐ +│ │ +│┌────────┐ │ +││Hello │ │ +│└────────┘ │ +│ │ +└─────────────┘", output); Assert.Equal (Application.Current, Application.MouseGrabView); } else if (iterations == 5) { Assert.Equal (Application.Current, Application.MouseGrabView); // Drag up Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 7, - Y = 4, + X = 2, + Y = 1, Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition })); + Application.Refresh (); Assert.Equal (Application.Current, Application.MouseGrabView); - Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame); + Assert.Equal (new Rect (1, 1, 10, 3), Application.MouseGrabView.Frame); } else if (iterations == 6) { Assert.Equal (Application.Current, Application.MouseGrabView); TestHelpers.AssertDriverContentsWithFrameAre (@$" -┌──────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ ┌──────────────────────┐ │ -│ │ Hello Word │ │ -│ │ │ │ -│ │ {CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Ok {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket} │ │ -│ └──────────────────────┘ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└──────────────────────────────────────┘", output); +┌─────────────┐ +│┌────────┐ │ +││Hello │ │ +│└────────┘ │ +│ │ +│ │ +└─────────────┘", output); Assert.Equal (Application.Current, Application.MouseGrabView); - Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame); + Assert.Equal (new Rect (1, 1, 10, 3), Application.MouseGrabView.Frame); } else if (iterations == 7) { Assert.Equal (Application.Current, Application.MouseGrabView); // Ungrab the mouse Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 7, - Y = 4, + X = 2, + Y = 1, Flags = MouseFlags.Button1Released })); + Application.Refresh (); Assert.Null (Application.MouseGrabView); @@ -833,7 +822,8 @@ public class ToplevelTests { Application.Run (); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void Mouse_Drag_On_Top_With_Superview_Not_Null () { var win = new Window () { @@ -928,7 +918,8 @@ public class ToplevelTests { Application.Run (); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void GetLocationThatFits_With_Border_Null_Not_Throws () { var top = new Toplevel (); @@ -941,7 +932,8 @@ public class ToplevelTests { Assert.Null (exception); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void OnEnter_OnLeave_Triggered_On_Application_Begin_End () { bool isEnter = false; @@ -979,7 +971,8 @@ public class ToplevelTests { Assert.True (v.HasFocus); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void OnEnter_OnLeave_Triggered_On_Application_Begin_End_With_More_Toplevels () { int iterations = 0; @@ -1069,7 +1062,8 @@ public class ToplevelTests { Assert.Equal (5, steps [^1]); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void PositionCursor_SetCursorVisibility_To_Invisible_If_Focused_Is_Null () { var tf = new TextField ("test") { Width = 5 }; @@ -1089,7 +1083,8 @@ public class ToplevelTests { Assert.Equal (CursorVisibility.Invisible, cursor); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void IsLoaded_Application_Begin () { var top = Application.Top; @@ -1099,7 +1094,8 @@ public class ToplevelTests { Assert.True (top.IsLoaded); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void IsLoaded_With_Sub_Toplevel_Application_Begin_NeedDisplay () { var top = Application.Top; @@ -1137,7 +1133,8 @@ public class ToplevelTests { } // BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void Toplevel_Inside_ScrollView_MouseGrabView () { var scrollView = new ScrollView () { @@ -1254,32 +1251,33 @@ public class ToplevelTests { Assert.Equal (scrollView, Application.MouseGrabView); } - [Fact] [AutoInitShutdown] - public void Dialog_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom () + [Fact] + [AutoInitShutdown] + public void Window_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom () { var top = Application.Top; - var dialog = new Dialog (new Button ("Ok")) { Width = 20, Height = 3 }; + var window = new Window () { Width = 20, Height = 3 }; Application.Begin (top); ((FakeDriver)Application.Driver).SetBufferSize (40, 10); - Application.Begin (dialog); + Application.Begin (window); Application.Refresh (); Assert.Equal (new Rect (0, 0, 40, 10), top.Frame); - Assert.Equal (new Rect (10, 3, 20, 3), dialog.Frame); + Assert.Equal (new Rect (0, 0, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@$" - ┌──────────────────┐ - │ {CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket} │ - └──────────────────┘ +┌──────────────────┐ +│ │ +└──────────────────┘ ", output); Assert.Null (Application.MouseGrabView); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 10, - Y = 3, + X = 0, + Y = 0, Flags = MouseFlags.Button1Pressed })); - Assert.Equal (dialog, Application.MouseGrabView); + Assert.Equal (window, Application.MouseGrabView); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { X = -11, @@ -1289,10 +1287,10 @@ public class ToplevelTests { Application.Refresh (); Assert.Equal (new Rect (0, 0, 40, 10), top.Frame); - Assert.Equal (new Rect (0, 0, 20, 3), dialog.Frame); + Assert.Equal (new Rect (0, 0, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@$" ┌──────────────────┐ -│ {CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket} │ +│ │ └──────────────────┘ ", output); @@ -1306,10 +1304,10 @@ public class ToplevelTests { Application.Refresh (); Assert.Equal (new Rect (0, 0, 20, 3), top.Frame); - Assert.Equal (new Rect (0, 0, 20, 3), dialog.Frame); + Assert.Equal (new Rect (0, 0, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@$" ┌──────────────────┐ -│ {CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket} │ +│ │ └──────────────────┘ ", output); @@ -1323,10 +1321,10 @@ public class ToplevelTests { Application.Refresh (); Assert.Equal (new Rect (0, 0, 19, 2), top.Frame); - Assert.Equal (new Rect (-1, 0, 20, 3), dialog.Frame); + Assert.Equal (new Rect (-1, 0, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@$" ──────────────────┐ - {CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket} │ + │ ", output); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { @@ -1337,7 +1335,7 @@ public class ToplevelTests { Application.Refresh (); Assert.Equal (new Rect (0, 0, 19, 2), top.Frame); - Assert.Equal (new Rect (18, 1, 20, 3), dialog.Frame); + Assert.Equal (new Rect (18, 1, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@" ┌", output); @@ -1350,17 +1348,18 @@ public class ToplevelTests { Application.Refresh (); Assert.Equal (new Rect (0, 0, 19, 2), top.Frame); - Assert.Equal (new Rect (19, 2, 20, 3), dialog.Frame); + Assert.Equal (new Rect (19, 2, 20, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@"", output); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void Modal_As_Top_Will_Drag_Cleanly () { - var dialog = new Dialog () { Width = 30, Height = 10 }; - dialog.Add (new Label ( - "How should I've to react. Cleaning all chunk trails or setting the 'Cols' and 'Rows' to this dialog length?\n" + - "Cleaning is more easy to fix this.") { + // Don't use Dialog as a Top, use a Window instead - dialog has complex layout behavior that is not needed here. + var window = new Window () { Width = 10, Height = 3}; + window.Add (new Label ( + "Test") { X = Pos.Center (), Y = Pos.Center (), Width = Dim.Fill (), @@ -1370,73 +1369,53 @@ public class ToplevelTests { AutoSize = false }); - var rs = Application.Begin (dialog); + var rs = Application.Begin (window); Assert.Null (Application.MouseGrabView); - Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame); + Assert.Equal (new Rect (0, 0, 10, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@" - ┌────────────────────────────┐ - │ How should I've to react. │ - │Cleaning all chunk trails or│ - │ setting the 'Cols' and │ - │ 'Rows' to this dialog │ - │ length? │ - │Cleaning is more easy to fix│ - │ this. │ - │ │ - └────────────────────────────┘", output); +┌────────┐ +│ Test │ +└────────┘", output); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 25, - Y = 7, + X = 0, + Y = 0, Flags = MouseFlags.Button1Pressed })); bool firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); - Assert.Equal (dialog, Application.MouseGrabView); + Assert.Equal (window, Application.MouseGrabView); - Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame); + Assert.Equal (new Rect (0, 0, 10, 3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@" - ┌────────────────────────────┐ - │ How should I've to react. │ - │Cleaning all chunk trails or│ - │ setting the 'Cols' and │ - │ 'Rows' to this dialog │ - │ length? │ - │Cleaning is more easy to fix│ - │ this. │ - │ │ - └────────────────────────────┘", output); +┌────────┐ +│ Test │ +└────────┘", output); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 20, - Y = 10, + X = 1, + Y = 1, Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition })); firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); - Assert.Equal (dialog, Application.MouseGrabView); - Assert.Equal (new Rect (20, 10, 30, 10), dialog.Frame); + Assert.Equal (window, Application.MouseGrabView); + Assert.Equal (new Rect (1, 1, 10,3), window.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@" - ┌────────────────────────────┐ - │ How should I've to react. │ - │Cleaning all chunk trails or│ - │ setting the 'Cols' and │ - │ 'Rows' to this dialog │ - │ length? │ - │Cleaning is more easy to fix│ - │ this. │ - │ │ - └────────────────────────────┘", output); + ┌────────┐ + │ Test │ + └────────┘", output); Application.End (rs); } - // BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why - [Fact] [AutoInitShutdown] - public void Draw_A_Top_Subview_On_A_Dialog () + // Don't use Dialog as a Top, use a Window instead - dialog has complex layout behavior that is not needed here. + [Fact] + [AutoInitShutdown] + public void Draw_A_Top_Subview_On_A_Window () { var top = Application.Top; var win = new Window (); @@ -1468,25 +1447,29 @@ public class ToplevelTests { └──────────────────┘", output); var btnPopup = new Button ("Popup"); + var testWindow = new Window () { X = 2, Y = 1, Width = 15, Height = 10 }; + testWindow.Add (btnPopup); btnPopup.Clicked += (s, e) => { var viewToScreen = btnPopup.BoundsToScreen (top.Frame); - var view = new View () { + var viewAddedToTop = new View () { + Text = "viewAddedToTop", X = 1, Y = viewToScreen.Y + 1, Width = 18, - Height = 5, + Height = 16, BorderStyle = LineStyle.Single }; - Application.Current.DrawContentComplete += Current_DrawContentComplete; - top.Add (view); + Assert.Equal (testWindow, Application.Current); + Application.Current.DrawContentComplete += testWindow_DrawContentComplete; + top.Add (viewAddedToTop); - void Current_DrawContentComplete (object sender, DrawEventArgs e) + void testWindow_DrawContentComplete (object sender, DrawEventArgs e) { - Assert.Equal (new Rect (1, 14, 18, 5), view.Frame); + Assert.Equal (new Rect (1, 3, 18, 16), viewAddedToTop.Frame); var savedClip = Application.Driver.Clip; Application.Driver.Clip = top.Frame; - view.Draw (); + viewAddedToTop.Draw (); top.Move (2, 15); View.Driver.AddStr ("One"); top.Move (2, 16); @@ -1495,20 +1478,16 @@ public class ToplevelTests { View.Driver.AddStr ("Three"); Application.Driver.Clip = savedClip; - Application.Current.DrawContentComplete -= Current_DrawContentComplete; + Application.Current.DrawContentComplete -= testWindow_DrawContentComplete; } }; - var dialog = new Dialog (btnPopup) { Width = 15, Height = 10 }; - var rs = Application.Begin (dialog); + var rs = Application.Begin (testWindow); - Assert.Equal (new Rect (2, 5, 15, 10), dialog.Frame); + Assert.Equal (new Rect (2, 1, 15, 10), testWindow.Frame); TestHelpers.AssertDriverContentsWithFrameAre (@$" ┌──────────────────┐ -│ │ -│ │ -│ │ -│ │ │ ┌─────────────┐ │ +│ │{CM.Glyphs.LeftBracket} Popup {CM.Glyphs.RightBracket} │ │ │ │ │ │ │ │ │ │ │ │ │ │ @@ -1516,38 +1495,42 @@ public class ToplevelTests { │ │ │ │ │ │ │ │ │ │ │ │ -│ │ {CM.Glyphs.LeftBracket} Popup {CM.Glyphs.RightBracket} │ │ │ └─────────────┘ │ │ │ │ │ │ │ │ │ +│ │ +│ │ +│ │ +│ │ └──────────────────┘", output); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () { - X = 9, - Y = 13, + X = 5, + Y = 2, Flags = MouseFlags.Button1Clicked })); + Application.Top.Draw (); bool firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); TestHelpers.AssertDriverContentsWithFrameAre (@$" ┌──────────────────┐ -│ │ -│ │ -│ │ -│ │ │ ┌─────────────┐ │ -│ │ │ │ -│ │ │ │ -│ │ │ │ -│ │ │ │ -│ │ │ │ -│ │ │ │ -│ │ │ │ -│ │ {CM.Glyphs.LeftBracket} Popup {CM.Glyphs.RightBracket} │ │ +│ │{CM.Glyphs.LeftBracket} Popup {CM.Glyphs.RightBracket} │ │ │┌────────────────┐│ +││viewAddedToTop ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ +││ ││ ││One ││ ││Two ││ ││Three ││ @@ -1557,7 +1540,8 @@ public class ToplevelTests { Application.End (rs); } - [Fact] [AutoInitShutdown] + [Fact] + [AutoInitShutdown] public void Activating_MenuBar_By_Alt_Key_Does_Not_Throw () { var menu = new MenuBar (new MenuBarItem [] { @@ -1575,7 +1559,8 @@ public class ToplevelTests { } - [Fact] [TestRespondersDisposed] + [Fact] + [TestRespondersDisposed] public void Multi_Thread_Toplevels () { Application.Init (new FakeDriver ()); @@ -1621,12 +1606,12 @@ public class ToplevelTests { return true; }); - t.Ready += FirstDialogToplevel; + t.Ready += FirstWindow; - void FirstDialogToplevel (object sender, EventArgs args) + void FirstWindow (object sender, EventArgs args) { - var od = new OpenDialog (); - od.Ready += SecondDialogToplevel; + var firstWindow = new Window (); + firstWindow.Ready += SecondWindow; Application.AddTimeout (TimeSpan.FromMilliseconds (100), () => { count1++; @@ -1644,12 +1629,12 @@ public class ToplevelTests { return true; }); - Application.Run (od); + Application.Run (firstWindow); } - void SecondDialogToplevel (object sender, EventArgs args) + void SecondWindow (object sender, EventArgs args) { - var d = new Dialog (); + var testWindow = new Window (); Application.AddTimeout (TimeSpan.FromMilliseconds (100), () => { count2++; @@ -1664,7 +1649,7 @@ public class ToplevelTests { return true; }); - Application.Run (d); + Application.Run (testWindow); } Application.Run ();