diff --git a/Terminal.Gui/View/Frame.cs b/Terminal.Gui/View/Frame.cs index c6e7d43cc1..c7d90ceb4f 100644 --- a/Terminal.Gui/View/Frame.cs +++ b/Terminal.Gui/View/Frame.cs @@ -148,8 +148,8 @@ public override void Redraw (Rect bounds) var borderBounds = new Rect ( screenBounds.X + Math.Max (0, Thickness.Left - 1), screenBounds.Y + Math.Max (0, Thickness.Top - 1), - screenBounds.Width - Math.Max (0, Math.Max (0, Thickness.Left - 1) - Math.Max (0, Thickness.Right - 1)), - screenBounds.Height - Math.Max (0, Math.Max (0, Thickness.Top - 1) - Math.Max (0, Thickness.Bottom - 1))); + Math.Max (0, screenBounds.Width - Math.Max (0, Math.Max (0, Thickness.Left - 1) + Math.Max (0, Thickness.Right - 1))), + Math.Max (0, screenBounds.Height - Math.Max (0, Math.Max (0, Thickness.Top - 1) + Math.Max (0, Thickness.Bottom - 1)))); var topTitleLineY = borderBounds.Y; var titleY = borderBounds.Y; diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 502a6db07b..7b4fe73c2b 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -384,12 +384,13 @@ public virtual void Redraw (Rect bounds) } } - // Invoke DrawContentCompleteEvent - OnDrawContentComplete (bounds); Driver.Clip = prevClip; OnRenderLineCanvas (); + // Invoke DrawContentCompleteEvent + OnDrawContentComplete (bounds); + // BUGBUG: v2 - We should be able to use View.SetClip here and not have to resort to knowing Driver details. ClearLayoutNeeded (); ClearNeedsDisplay (); diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index e7640f71cd..5dc55b4e96 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -537,7 +537,6 @@ internal Attribute DetermineColorSchemeFor (MenuItem item, int index) public override void Redraw (Rect bounds) { - if (barItems.Children == null) { return; } @@ -547,6 +546,7 @@ public override void Redraw (Rect bounds) Driver.SetAttribute (GetNormalColor ()); OnDrawFrames (); + OnRenderLineCanvas (); for (int i = Bounds.Y; i < barItems.Children.Length; i++) { if (i < 0) @@ -646,7 +646,6 @@ public override void Redraw (Rect bounds) } Driver.Clip = savedClip; - OnRenderLineCanvas (); PositionCursor (); } diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index abbbdbc0ff..af2e16a838 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -904,84 +904,84 @@ public void Key_Open_And_Close_The_ContextMenu () } // BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why -// [Fact, AutoInitShutdown] -// public void Draw_A_ContextManu_Over_A_Dialog () -// { -// var top = Application.Top; -// var win = new Window (); -// top.Add (win); -// Application.Begin (top); -// ((FakeDriver)Application.Driver).SetBufferSize (20, 15); - -// Assert.Equal (new Rect (0, 0, 20, 15), win.Frame); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//└──────────────────┘", output); - -// var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 }; -// dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 }); -// var rs = Application.Begin (dialog); - -// Assert.Equal (new Rect (2, 2, 15, 4), dialog.Frame); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ ┌─────────────┐ │ -//│ │ Test │ │ -//│ │ │ │ -//│ └─────────────┘ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//└──────────────────┘", output); - -// ReflectionTools.InvokePrivate ( -// typeof (Application), -// "ProcessMouseEvent", -// new MouseEvent () { -// X = 9, -// Y = 3, -// Flags = MouseFlags.Button3Clicked -// }); - -// var firstIteration = false; -// Application.RunMainLoopIteration (ref rs, true, ref firstIteration); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ ┌─────────────┐ │ -//│ │ Test │ │ -//┌─────────────────── -//│ Select All Ctrl+ -//│ Delete All Ctrl+ -//│ Copy Ctrl+ -//│ Cut Ctrl+ -//│ Paste Ctrl+ -//│ Undo Ctrl+ -//│ Redo Ctrl+ -//└─────────────────── -//│ │ -//└──────────────────┘", output); - -// Application.End (rs); -// } + [Fact, AutoInitShutdown] + public void Draw_A_ContextManu_Over_A_Dialog () + { + var top = Application.Top; + var win = new Window (); + top.Add (win); + Application.Begin (top); + ((FakeDriver)Application.Driver).SetBufferSize (20, 15); + + Assert.Equal (new Rect (0, 0, 20, 15), win.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└──────────────────┘", output); + + var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 }; + dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 }); + var rs = Application.Begin (dialog); + + Assert.Equal (new Rect (2, 2, 15, 4), dialog.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ ┌─────────────┐ │ +│ │ Test │ │ +│ │ │ │ +│ └─────────────┘ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└──────────────────┘", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 9, + Y = 3, + Flags = MouseFlags.Button3Clicked + }); + + var firstIteration = false; + Application.RunMainLoopIteration (ref rs, true, ref firstIteration); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ ┌─────────────┐ │ +│ │ Test │ │ +┌─────────────────── +│ Select All Ctrl+ +│ Delete All Ctrl+ +│ Copy Ctrl+ +│ Cut Ctrl+ +│ Paste Ctrl+ +│ Undo Ctrl+ +│ Redo Ctrl+ +└─────────────────── +│ │ +└──────────────────┘", output); + + Application.End (rs); + } } } diff --git a/UnitTests/Views/MenuTests.cs b/UnitTests/Views/MenuTests.cs index 0f77509b92..f9bb15cd1a 100644 --- a/UnitTests/Views/MenuTests.cs +++ b/UnitTests/Views/MenuTests.cs @@ -1848,7 +1848,7 @@ public void Menu_With_Separator () File ┌────────────────────────────┐ │ Open Open a file Ctrl+O │ -│────────────────────────────│ +├────────────────────────────┤ │ Quit │ └────────────────────────────┘", output); } diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 6b0f6bb84b..2fa05c3c5c 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1033,137 +1033,137 @@ void view_LayoutStarted (object sender, LayoutEventArgs e) } // BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why - //[Fact, AutoInitShutdown] - //public void Toplevel_Inside_ScrollView_MouseGrabView () - //{ - // var scrollView = new ScrollView () { - // X = 3, - // Y = 3, - // Width = 40, - // Height = 16, - // ContentSize = new Size (200, 100) - // }; - // var win = new Window () { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) }; - // scrollView.Add (win); - // var top = Application.Top; - // top.Add (scrollView); - // Application.Begin (top); - - // Assert.Equal (new Rect (0, 0, 80, 25), top.Frame); - // Assert.Equal (new Rect (3, 3, 40, 16), scrollView.Frame); - // Assert.Equal (new Rect (0, 0, 200, 100), scrollView.Subviews [0].Frame); - // Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); - // TestHelpers.AssertDriverContentsWithFrameAre (@" - // ▲ - // ┬ - // │ - // ┌───────────────────────────────────┴ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ▼ - // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); - - // ReflectionTools.InvokePrivate ( - // typeof (Application), - // "ProcessMouseEvent", - // new MouseEvent () { - // X = 6, - // Y = 6, - // Flags = MouseFlags.Button1Pressed - // }); - // Assert.Equal (win, Application.MouseGrabView); - // Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); - - // ReflectionTools.InvokePrivate ( - // typeof (Application), - // "ProcessMouseEvent", - // new MouseEvent () { - // X = 9, - // Y = 9, - // Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition - // }); - // Assert.Equal (win, Application.MouseGrabView); - // top.SetNeedsLayout (); - // top.LayoutSubviews (); - // Assert.Equal (new Rect (6, 6, 191, 91), win.Frame); - // Application.Refresh (); - // TestHelpers.AssertDriverContentsWithFrameAre (@" - // ▲ - // ┬ - // │ - // ┴ - // ░ - // ░ - // ┌────────────────────────────────░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ▼ - // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); - - // ReflectionTools.InvokePrivate ( - // typeof (Application), - // "ProcessMouseEvent", - // new MouseEvent () { - // X = 5, - // Y = 5, - // Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition - // }); - // Assert.Equal (win, Application.MouseGrabView); - // top.SetNeedsLayout (); - // top.LayoutSubviews (); - // Assert.Equal (new Rect (2, 2, 195, 95), win.Frame); - // Application.Refresh (); - // TestHelpers.AssertDriverContentsWithFrameAre (@" - // ▲ - // ┬ - // ┌────────────────────────────────────│ - // │ ┴ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ░ - // │ ▼ - // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); - - // ReflectionTools.InvokePrivate ( - // typeof (Application), - // "ProcessMouseEvent", - // new MouseEvent () { - // X = 5, - // Y = 5, - // Flags = MouseFlags.Button1Released - // }); - // Assert.Null (Application.MouseGrabView); - - // ReflectionTools.InvokePrivate ( - // typeof (Application), - // "ProcessMouseEvent", - // new MouseEvent () { - // X = 4, - // Y = 4, - // Flags = MouseFlags.ReportMousePosition - // }); - // Assert.Equal (scrollView, Application.MouseGrabView); - //} + [Fact, AutoInitShutdown] + public void Toplevel_Inside_ScrollView_MouseGrabView () + { + var scrollView = new ScrollView () { + X = 3, + Y = 3, + Width = 40, + Height = 16, + ContentSize = new Size (200, 100) + }; + var win = new Window () { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) }; + scrollView.Add (win); + var top = Application.Top; + top.Add (scrollView); + Application.Begin (top); + + Assert.Equal (new Rect (0, 0, 80, 25), top.Frame); + Assert.Equal (new Rect (3, 3, 40, 16), scrollView.Frame); + Assert.Equal (new Rect (0, 0, 200, 100), scrollView.Subviews [0].Frame); + Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + │ + ┌───────────────────────────────────┴ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 6, + Y = 6, + Flags = MouseFlags.Button1Pressed + }); + Assert.Equal (win, Application.MouseGrabView); + Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 9, + Y = 9, + Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + }); + Assert.Equal (win, Application.MouseGrabView); + top.SetNeedsLayout (); + top.LayoutSubviews (); + Assert.Equal (new Rect (6, 6, 191, 91), win.Frame); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + │ + ┴ + ░ + ░ + ┌────────────────────────────────░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 5, + Y = 5, + Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + }); + Assert.Equal (win, Application.MouseGrabView); + top.SetNeedsLayout (); + top.LayoutSubviews (); + Assert.Equal (new Rect (2, 2, 195, 95), win.Frame); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + ┌────────────────────────────────────│ + │ ┴ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 5, + Y = 5, + Flags = MouseFlags.Button1Released + }); + Assert.Null (Application.MouseGrabView); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 4, + Y = 4, + Flags = MouseFlags.ReportMousePosition + }); + Assert.Equal (scrollView, Application.MouseGrabView); + } [Fact, AutoInitShutdown] public void Dialog_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom () @@ -1368,131 +1368,131 @@ public void Single_Smaller_Top_Will_Have_Cleaning_Trails_Chunk_On_Move () 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 () -// { -// var top = Application.Top; -// var win = new Window () ; -// top.Add (win); -// Application.Begin (top); -// ((FakeDriver)Application.Driver).SetBufferSize (20, 20); - -// Assert.Equal (new Rect (0, 0, 20, 20), win.Frame); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//│ │ -//└──────────────────┘", output); - -// var btnPopup = new Button ("Popup"); -// btnPopup.Clicked += (s, e) => { -// var viewToScreen = btnPopup.ViewToScreen (top.Frame); -// var view = new View () { -// X = 1, -// Y = viewToScreen.Y + 1, -// Width = 18, -// Height = 5, -// BorderStyle = LineStyle.Single -// }; -// Application.Current.DrawContentComplete += Current_DrawContentComplete; -// top.Add (view); - -// void Current_DrawContentComplete (object sender, DrawEventArgs e) -// { -// Assert.Equal (new Rect (1, 14, 18, 5), view.Frame); - -// var savedClip = Application.Driver.Clip; -// Application.Driver.Clip = top.Frame; -// view.Redraw (view.Bounds); -// top.Move (2, 15); -// View.Driver.AddStr ("One"); -// top.Move (2, 16); -// View.Driver.AddStr ("Two"); -// top.Move (2, 17); -// View.Driver.AddStr ("Three"); -// Application.Driver.Clip = savedClip; - -// Application.Current.DrawContentComplete -= Current_DrawContentComplete; -// } -// }; -// var dialog = new Dialog (btnPopup) { Width = 15, Height = 10 }; -// var rs = Application.Begin (dialog); - -// Assert.Equal (new Rect (2, 5, 15, 10), dialog.Frame); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ │ -//│ │ -//│ │ -//│ ┌─────────────┐ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ [ Popup ] │ │ -//│ └─────────────┘ │ -//│ │ -//│ │ -//│ │ -//│ │ -//└──────────────────┘", output); - -// ReflectionTools.InvokePrivate ( -// typeof (Application), -// "ProcessMouseEvent", -// new MouseEvent () { -// X = 9, -// Y = 13, -// Flags = MouseFlags.Button1Clicked -// }); - -// var firstIteration = false; -// Application.RunMainLoopIteration (ref rs, true, ref firstIteration); -// TestHelpers.AssertDriverContentsWithFrameAre (@" -//┌──────────────────┐ -//│ │ -//│ │ -//│ │ -//│ │ -//│ ┌─────────────┐ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ │ │ -//│ │ [ Popup ] │ │ -//│┌────────────────┐│ -//││One ││ -//││Two ││ -//││Three ││ -//│└────────────────┘│ -//└──────────────────┘", output); - -// Application.End (rs); -// } + [Fact, AutoInitShutdown] + public void Draw_A_Top_Subview_On_A_Dialog () + { + var top = Application.Top; + var win = new Window (); + top.Add (win); + Application.Begin (top); + ((FakeDriver)Application.Driver).SetBufferSize (20, 20); + + Assert.Equal (new Rect (0, 0, 20, 20), win.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└──────────────────┘", output); + + var btnPopup = new Button ("Popup"); + btnPopup.Clicked += (s, e) => { + var viewToScreen = btnPopup.ViewToScreen (top.Frame); + var view = new View () { + X = 1, + Y = viewToScreen.Y + 1, + Width = 18, + Height = 5, + BorderStyle = LineStyle.Single + }; + Application.Current.DrawContentComplete += Current_DrawContentComplete; + top.Add (view); + + void Current_DrawContentComplete (object sender, DrawEventArgs e) + { + Assert.Equal (new Rect (1, 14, 18, 5), view.Frame); + + var savedClip = Application.Driver.Clip; + Application.Driver.Clip = top.Frame; + view.Redraw (view.Bounds); + top.Move (2, 15); + View.Driver.AddStr ("One"); + top.Move (2, 16); + View.Driver.AddStr ("Two"); + top.Move (2, 17); + View.Driver.AddStr ("Three"); + Application.Driver.Clip = savedClip; + + Application.Current.DrawContentComplete -= Current_DrawContentComplete; + } + }; + var dialog = new Dialog (btnPopup) { Width = 15, Height = 10 }; + var rs = Application.Begin (dialog); + + Assert.Equal (new Rect (2, 5, 15, 10), dialog.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ │ +│ │ +│ │ +│ ┌─────────────┐ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ [ Popup ] │ │ +│ └─────────────┘ │ +│ │ +│ │ +│ │ +│ │ +└──────────────────┘", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 9, + Y = 13, + Flags = MouseFlags.Button1Clicked + }); + + var firstIteration = false; + Application.RunMainLoopIteration (ref rs, true, ref firstIteration); + TestHelpers.AssertDriverContentsWithFrameAre (@" +┌──────────────────┐ +│ │ +│ │ +│ │ +│ │ +│ ┌─────────────┐ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ [ Popup ] │ │ +│┌────────────────┐│ +││One ││ +││Two ││ +││Three ││ +│└────────────────┘│ +└──────────────────┘", output); + + Application.End (rs); + } } } \ No newline at end of file