From 8f7fc8129b526a10269525a1da6e2241e8e3d5df Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 15 Mar 2023 19:14:26 +0000 Subject: [PATCH 1/4] Fixes #2416. Single smaller top level leaves chunk trails on move. --- Terminal.Gui/Core/Application.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index a646cbddb..e70570d9f 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -1241,6 +1241,14 @@ namespace Terminal.Gui { } state.Toplevel.SetNeedsDisplay (state.Toplevel.Bounds); } + if (toplevels.Count == 1 && state.Toplevel == Top + && (Driver.Cols != state.Toplevel.Frame.Width || Driver.Rows != state.Toplevel.Frame.Height) + && (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.ChildNeedsDisplay || state.Toplevel.LayoutNeeded)) { + + Driver.SetAttribute (Colors.TopLevel.Normal); + state.Toplevel.Clear (new Rect (0, 0, Driver.Cols, Driver.Rows)); + + } if (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.ChildNeedsDisplay || state.Toplevel.LayoutNeeded || MdiChildNeedsDisplay ()) { state.Toplevel.Redraw (state.Toplevel.Bounds); From ae6c95836a73b793586e289ac9950b9785b26371 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 15 Mar 2023 20:10:42 +0000 Subject: [PATCH 2/4] Adding a unit test to ensure this doesn't happens again. --- UnitTests/TopLevels/ToplevelTests.cs | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index a6f803af0..3df27386b 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -1081,5 +1081,88 @@ namespace Terminal.Gui.TopLevelTests { Assert.Equal (new Rect (1, 3, 10, 5), view.Frame); Assert.Equal (new Rect (0, 0, 10, 5), view.NeedDisplay); } + + [Fact, AutoInitShutdown] + public void Single_Smaller_Top_Will_Have_Cleaning_Trails_Chunk_On_Move () + { + var dialog = new Dialog ("Single smaller 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.") { + X = Pos.Center (), + Y = Pos.Center (), + Width = Dim.Fill (), + Height = Dim.Fill (), + TextAlignment = TextAlignment.Centered, + VerticalTextAlignment = VerticalTextAlignment.Middle, + AutoSize = false + }); + + var rs = Application.Begin (dialog); + + Assert.Null (Application.MouseGrabView); + Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ┌ Single smaller Dialog ─────┐ + │ 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); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 25, + Y = 7, + Flags = MouseFlags.Button1Pressed + }); + + var firstIteration = false; + Application.RunMainLoopIteration (ref rs, true, ref firstIteration); Assert.Equal (dialog, Application.MouseGrabView); + + Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ┌ Single smaller Dialog ─────┐ + │ 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); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 20, + Y = 10, + Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + }); + + firstIteration = false; + Application.RunMainLoopIteration (ref rs, true, ref firstIteration); + Assert.Equal (dialog, Application.MouseGrabView); + Assert.Equal (new Rect (20, 10, 30, 10), dialog.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ┌ Single smaller Dialog ─────┐ + │ 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); + } } } \ No newline at end of file From 8715af2a42e9c4f74b6aec1a60498060aeac8dbf Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 15 Mar 2023 21:30:24 +0000 Subject: [PATCH 3/4] Fix unit test error not disposing static variables. --- Terminal.Gui/Core/Application.cs | 1 + Terminal.Gui/Core/Toplevel.cs | 7 +++++++ UnitTests/TopLevels/ToplevelTests.cs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index e70570d9f..7784dd791 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -1134,6 +1134,7 @@ namespace Terminal.Gui { _initialized = false; mouseGrabView = null; _enableConsoleScrolling = false; + lastMouseOwnerView = null; // Reset synchronization context to allow the user to run async/await, // as the main loop has been ended, the synchronization context from diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 08952f48b..23dc882ed 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -984,6 +984,13 @@ namespace Terminal.Gui { { return MostFocused?.OnLeave (view) ?? base.OnLeave (view); } + + /// + protected override void Dispose (bool disposing) + { + dragPosition = null; + base.Dispose (disposing); + } } /// diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 3df27386b..6e1f2a877 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -1163,6 +1163,8 @@ namespace Terminal.Gui.TopLevelTests { │ this. │ │ │ └────────────────────────────┘", output); + + Application.End (rs); } } } \ No newline at end of file From ca8455fd96bcc1d9a1dd496a1252e1ff81be0f35 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 15 Mar 2023 22:46:36 +0000 Subject: [PATCH 4/4] Fixes #2420. BackgroundWorkerCollection scenario is badly clearing invisible button. --- UICatalog/Scenarios/BackgroundWorkerCollection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index de83d5759..fe8bd4685 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -327,7 +327,7 @@ namespace UICatalog.Scenarios { }; Add (listView); - start = new Button ("Start") { IsDefault = true }; + start = new Button ("Start") { IsDefault = true, ClearOnVisibleFalse = false }; start.Clicked += () => { Staging = new Staging (DateTime.Now); RequestStop ();