浏览代码

Simplify redraw logic and improve output handling

Refactor redraw logic by removing `needsDrawOrLayout` checks and
the `AnySubViewsNeedDrawn` method in `ApplicationMainLoop.cs`.
Always call `App?.LayoutAndDraw(forceRedraw: false)` to simplify
layout and drawing behavior.

Add redraw logging in `ApplicationImpl.Screen.cs` to track redraw
events consistently.

Update `DriverImpl.cs` to always write the `OutputBuffer` during
`Refresh`, ensuring output is consistently handled.
Tig 1 周之前
父节点
当前提交
d7bcc8c70c

+ 2 - 0
Terminal.Gui/App/ApplicationImpl.Screen.cs

@@ -174,6 +174,8 @@ internal partial class ApplicationImpl
 
         if (Driver is { })
         {
+            Logging.Redraws.Add (1);
+
             Driver.Clip = new (Screen);
 
             View.Draw (views: tops!, neededLayout || forceRedraw);

+ 1 - 37
Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs

@@ -139,20 +139,9 @@ public class ApplicationMainLoop<TInputRecord> : IApplicationMainLoop<TInputReco
 
         if (App?.TopRunnableView != null)
         {
-            bool needsDrawOrLayout = AnySubViewsNeedDrawn (App?.Popover?.GetActivePopover () as View)
-                                     || AnySubViewsNeedDrawn (App?.TopRunnableView)
-                                     || (App?.Mouse.MouseGrabView != null && AnySubViewsNeedDrawn (App?.Mouse.MouseGrabView));
-
             SizeMonitor.Poll ();
 
-            if (needsDrawOrLayout)
-            {
-                Logging.Redraws.Add (1);
-
-                App?.LayoutAndDraw (forceRedraw: false);
-
-                Output.Write (OutputBuffer);
-            }
+            App?.LayoutAndDraw (forceRedraw: false);
 
             SetCursor ();
         }
@@ -189,31 +178,6 @@ public class ApplicationMainLoop<TInputRecord> : IApplicationMainLoop<TInputReco
         }
     }
 
-    private bool AnySubViewsNeedDrawn (View? v)
-    {
-        if (v is null)
-        {
-            return false;
-        }
-
-        if (v.NeedsDraw || v.NeedsLayout)
-        {
-            // Logging.Trace ($"{v.GetType ().Name} triggered redraw (NeedsDraw={v.NeedsDraw} NeedsLayout={v.NeedsLayout}) ");
-
-            return true;
-        }
-
-        foreach (View subview in v.SubViews)
-        {
-            if (AnySubViewsNeedDrawn (subview))
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     /// <inheritdoc/>
     public void Dispose ()
     {

+ 1 - 1
Terminal.Gui/Drivers/DriverImpl.cs

@@ -370,7 +370,7 @@ internal class DriverImpl : IDriver
     /// <inheritdoc/>
     public void Refresh ()
     {
-        // No need we will always draw when dirty
+        _output.Write (OutputBuffer);
     }
 
     /// <inheritdoc/>