Browse Source

Change LayoutAndDraw in v2 applications to simply set draw/layout flags instead of force a buffer refresh (#3943)

Thomas Nind 4 months ago
parent
commit
af9c6d7846

+ 5 - 0
Terminal.Gui/Application/Application.Run.cs

@@ -411,6 +411,11 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     /// </summary>
     /// </summary>
     /// <param name="forceDraw">If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and should only be overriden for testing.</param>
     /// <param name="forceDraw">If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and should only be overriden for testing.</param>
     public static void LayoutAndDraw (bool forceDraw = false)
     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);
         bool neededLayout = View.Layout (TopLevels.Reverse (), Screen.Size);
 
 

+ 6 - 0
Terminal.Gui/Application/ApplicationImpl.cs

@@ -294,4 +294,10 @@ public class ApplicationImpl : IApplication
     { 
     { 
         return Application.MainLoop?.TimedEvents.RemoveTimeout (token) ?? false;
         return Application.MainLoop?.TimedEvents.RemoveTimeout (token) ?? false;
     }
     }
+
+    /// <inheritdoc />
+    public virtual void LayoutAndDraw (bool forceDraw)
+    {
+        Application.LayoutAndDrawImpl (forceDraw);
+    }
 }
 }

+ 7 - 0
Terminal.Gui/Application/IApplication.cs

@@ -182,4 +182,11 @@ public interface IApplication
     /// <see langword="false"/>
     /// <see langword="false"/>
     /// if the timeout is not found.</returns>
     /// if the timeout is not found.</returns>
     bool RemoveTimeout (object token);
     bool RemoveTimeout (object token);
+
+    /// <summary>
+    /// 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 <see cref="View.NeedsLayout"/>) will be laid out.
+    /// Only Views that need to be drawn (see <see cref="View.NeedsDraw"/>) will be drawn.
+    /// </summary>
+    /// <param name="forceDraw">If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and should only be overriden for testing.</param>
+    void LayoutAndDraw (bool forceDraw);
 }
 }

+ 8 - 0
Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs

@@ -232,4 +232,12 @@ public class ApplicationV2 : ApplicationImpl
 
 
     /// <inheritdoc/>
     /// <inheritdoc/>
     public override bool RemoveTimeout (object token) { return _timedEvents.RemoveTimeout (token); }
     public override bool RemoveTimeout (object token) { return _timedEvents.RemoveTimeout (token); }
+
+    /// <inheritdoc />
+    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 ();
+    }
 }
 }

+ 1 - 2
Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

@@ -130,8 +130,7 @@ public class MainLoop<T> : IMainLoop<T>
             {
             {
                 Logging.Redraws.Add (1);
                 Logging.Redraws.Add (1);
 
 
-                // TODO: Test only
-                Application.LayoutAndDraw (true);
+                Application.LayoutAndDrawImpl (true);
 
 
                 Out.Write (OutputBuffer);
                 Out.Write (OutputBuffer);