From d39a940955e065ef298ca73a730c1f021419505e Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 25 Nov 2024 20:17:04 -0700 Subject: [PATCH] Added Applicaton.ClearScreenNextIteration --- Terminal.Gui/Application/Application.Run.cs | 5 +++++ Terminal.Gui/Application/Application.Screen.cs | 9 +++++++++ Terminal.Gui/Application/Application.cs | 2 ++ Terminal.Gui/View/View.Layout.cs | 9 ++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index 7511f8216..ebba96404 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -505,6 +505,11 @@ public static partial class Application // Run (Begin, Run, End, Stop) { bool neededLayout = View.Layout (TopLevels.Reverse (), Screen.Size); + if (ClearScreenNextIteration) + { + forceDraw = true; + ClearScreenNextIteration = false; + } if (forceDraw) { Driver?.ClearContents (); diff --git a/Terminal.Gui/Application/Application.Screen.cs b/Terminal.Gui/Application/Application.Screen.cs index c5bf6d6fd..9edd29313 100644 --- a/Terminal.Gui/Application/Application.Screen.cs +++ b/Terminal.Gui/Application/Application.Screen.cs @@ -67,4 +67,13 @@ public static partial class Application // Screen related stuff return true; } + + /// + /// 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 + /// SuperView (e.g. when is moved or resized. + /// + public static bool ClearScreenNextIteratio { get; set; } } diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index d9e6c68d9..85a234cef 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -215,6 +215,8 @@ public static partial class Application Navigation = null; + ClearScreenNextIteration = false; + AddApplicationKeyBindings (); // Reset synchronization context to allow the user to run async/await, diff --git a/Terminal.Gui/View/View.Layout.cs b/Terminal.Gui/View/View.Layout.cs index 1b37f9725..833d5bdb2 100644 --- a/Terminal.Gui/View/View.Layout.cs +++ b/Terminal.Gui/View/View.Layout.cs @@ -557,7 +557,14 @@ public partial class View // Layout APIs SetTitleTextFormatterSize (); } - SuperView?.SetNeedsDraw (); + if (SuperView is { }) + { + SuperView?.SetNeedsDraw (); + } + else + { + // Application.ClearScreenNextIteration = true; + } } if (TextFormatter.ConstrainToWidth is null)