diff --git a/Examples/UICatalog/Scenarios/CombiningMarks.cs b/Examples/UICatalog/Scenarios/CombiningMarks.cs index 6e0467ce0..7d8437a23 100644 --- a/Examples/UICatalog/Scenarios/CombiningMarks.cs +++ b/Examples/UICatalog/Scenarios/CombiningMarks.cs @@ -13,7 +13,7 @@ public class CombiningMarks : Scenario top.DrawComplete += (s, e) => { // Forces reset _lineColsOffset because we're dealing with direct draw - Application.ClearScreenNextIteration = true; + Application.Top!.SetNeedsDraw (); var i = -1; top.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616."); diff --git a/Terminal.Gui/App/Application.Screen.cs b/Terminal.Gui/App/Application.Screen.cs index cc9dcb0b6..1ceed1d7c 100644 --- a/Terminal.Gui/App/Application.Screen.cs +++ b/Terminal.Gui/App/Application.Screen.cs @@ -82,8 +82,8 @@ public static partial class Application // Screen related stuff /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration. /// /// - /// This is typicall set to true when a View's changes and that view has no + /// This is typical set to true when a View's changes and that view has no /// SuperView (e.g. when is moved or resized. /// - public static bool ClearScreenNextIteration { get; set; } + internal static bool ClearScreenNextIteration { get; set; } } diff --git a/Terminal.Gui/ViewBase/View.Layout.cs b/Terminal.Gui/ViewBase/View.Layout.cs index 8f28cdba2..b22260fc1 100644 --- a/Terminal.Gui/ViewBase/View.Layout.cs +++ b/Terminal.Gui/ViewBase/View.Layout.cs @@ -239,6 +239,8 @@ public partial class View // Layout APIs _x = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (X)} cannot be null"); PosDimSet (); + + NeedsClearScreenNextIteration (); } } @@ -281,6 +283,8 @@ public partial class View // Layout APIs _y = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Y)} cannot be null"); PosDimSet (); + + NeedsClearScreenNextIteration (); } } @@ -339,6 +343,8 @@ public partial class View // Layout APIs OnHeightChanged, HeightChanged, out Dim _); + + NeedsClearScreenNextIteration (); } } @@ -425,6 +431,16 @@ public partial class View // Layout APIs OnWidthChanged, WidthChanged, out Dim _); + + NeedsClearScreenNextIteration (); + } + } + + private void NeedsClearScreenNextIteration () + { + if (Application.Top is { } && Application.Top == this && Application.TopLevels.Count == 1) + { + Application.ClearScreenNextIteration = true; } } @@ -656,7 +672,7 @@ public partial class View // Layout APIs else if (Application.TopLevels.Count == 1) { // If this is the only TopLevel, we need to redraw the screen - Application.ClearScreenNextIteration = true; + Application.Top!.SetNeedsDraw (); } } diff --git a/Terminal.Gui/ViewBase/View.cs b/Terminal.Gui/ViewBase/View.cs index 3edf1e768..0bef6fbd1 100644 --- a/Terminal.Gui/ViewBase/View.cs +++ b/Terminal.Gui/ViewBase/View.cs @@ -376,9 +376,9 @@ public partial class View : IDisposable, ISupportInitializeNotification { SuperView?.SetNeedsDraw (); } - else + else if (Application.Top is { }) { - Application.ClearScreenNextIteration = true; + Application.Top!.SetNeedsDraw (); } } } diff --git a/Tests/UnitTests/Application/ApplicationScreenTests.cs b/Tests/UnitTests/Application/ApplicationScreenTests.cs index 0086cb01b..675b683ad 100644 --- a/Tests/UnitTests/Application/ApplicationScreenTests.cs +++ b/Tests/UnitTests/Application/ApplicationScreenTests.cs @@ -47,7 +47,7 @@ public class ApplicationScreenTests Assert.Equal (0, clearedContentsRaised); // Act - Application.Top.SetNeedsLayout (); + Application.Top!.SetNeedsLayout (); Application.LayoutAndDraw (); // Assert @@ -67,6 +67,20 @@ public class ApplicationScreenTests // Assert Assert.Equal (2, clearedContentsRaised); + // Act + Application.Top.Y = 1; + Application.LayoutAndDraw (); + + // Assert + Assert.Equal (3, clearedContentsRaised); + + // Act + Application.Top.Height = 10; + Application.LayoutAndDraw (); + + // Assert + Assert.Equal (4, clearedContentsRaised); + Application.End (rs); return;