From af9c6d7846067f90029ba189b01ab7682a29ea00 Mon Sep 17 00:00:00 2001
From: Thomas Nind <31306100+tznind@users.noreply.github.com>
Date: Sat, 1 Mar 2025 16:36:13 +0000
Subject: [PATCH] Change LayoutAndDraw in v2 applications to simply set
draw/layout flags instead of force a buffer refresh (#3943)
---
Terminal.Gui/Application/Application.Run.cs | 5 +++++
Terminal.Gui/Application/ApplicationImpl.cs | 6 ++++++
Terminal.Gui/Application/IApplication.cs | 7 +++++++
Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs | 8 ++++++++
Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs | 3 +--
5 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs
index fc6819aed..6906efd90 100644
--- a/Terminal.Gui/Application/Application.Run.cs
+++ b/Terminal.Gui/Application/Application.Run.cs
@@ -411,6 +411,11 @@ public static partial class Application // Run (Begin, Run, End, Stop)
///
/// If the entire View hierarchy will be redrawn. The default is and should only be overriden for testing.
public static void LayoutAndDraw (bool forceDraw = false)
+ {
+ ApplicationImpl.Instance.LayoutAndDraw (forceDraw);
+ }
+
+ internal static void LayoutAndDrawImpl (bool forceDraw = false)
{
bool neededLayout = View.Layout (TopLevels.Reverse (), Screen.Size);
diff --git a/Terminal.Gui/Application/ApplicationImpl.cs b/Terminal.Gui/Application/ApplicationImpl.cs
index bf40f381b..49e1d4b52 100644
--- a/Terminal.Gui/Application/ApplicationImpl.cs
+++ b/Terminal.Gui/Application/ApplicationImpl.cs
@@ -294,4 +294,10 @@ public class ApplicationImpl : IApplication
{
return Application.MainLoop?.TimedEvents.RemoveTimeout (token) ?? false;
}
+
+ ///
+ public virtual void LayoutAndDraw (bool forceDraw)
+ {
+ Application.LayoutAndDrawImpl (forceDraw);
+ }
}
diff --git a/Terminal.Gui/Application/IApplication.cs b/Terminal.Gui/Application/IApplication.cs
index bdd51046f..a6362b09e 100644
--- a/Terminal.Gui/Application/IApplication.cs
+++ b/Terminal.Gui/Application/IApplication.cs
@@ -182,4 +182,11 @@ public interface IApplication
///
/// if the timeout is not found.
bool RemoveTimeout (object token);
+
+ ///
+ /// Causes any Toplevels that need layout to be laid out. Then draws any Toplevels that need display. Only Views that need to be laid out (see ) will be laid out.
+ /// Only Views that need to be drawn (see ) will be drawn.
+ ///
+ /// If the entire View hierarchy will be redrawn. The default is and should only be overriden for testing.
+ void LayoutAndDraw (bool forceDraw);
}
\ No newline at end of file
diff --git a/Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs b/Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs
index 5679f1913..36cd6a62c 100644
--- a/Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs
+++ b/Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs
@@ -232,4 +232,12 @@ public class ApplicationV2 : ApplicationImpl
///
public override bool RemoveTimeout (object token) { return _timedEvents.RemoveTimeout (token); }
+
+ ///
+ public override void LayoutAndDraw (bool forceDraw)
+ {
+ // No more ad-hoc drawing, you must wait for iteration to do it
+ Application.Top?.SetNeedsDraw();
+ Application.Top?.SetNeedsLayout ();
+ }
}
diff --git a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs
index 8c830aaa3..08575a1ba 100644
--- a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs
+++ b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs
@@ -130,8 +130,7 @@ public class MainLoop : IMainLoop
{
Logging.Redraws.Add (1);
- // TODO: Test only
- Application.LayoutAndDraw (true);
+ Application.LayoutAndDrawImpl (true);
Out.Write (OutputBuffer);