瀏覽代碼

Merge branch 'v2_develop' into v2_3767_restoring-drivers-and-fixes

Tig 8 月之前
父節點
當前提交
e8e8c5916a

+ 1 - 0
CommunityToolkitExample/LoginView.cs

@@ -59,6 +59,7 @@ internal partial class LoginView : IRecipient<Message<LoginActions>>
                 }
                 }
         }
         }
         SetText();
         SetText();
+        // BUGBUG: This should not be needed:
         Application.LayoutAndDraw ();
         Application.LayoutAndDraw ();
     }
     }
 
 

+ 1 - 1
Terminal.Gui/Application/Application.Keyboard.cs

@@ -205,7 +205,7 @@ public static partial class Application // Keyboard handling
                     Command.Refresh,
                     Command.Refresh,
                     static () =>
                     static () =>
                     {
                     {
-                        LayoutAndDraw ();
+                        LayoutAndDraw (true);
 
 
                         return true;
                         return true;
                     }
                     }

+ 6 - 1
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);
         bool neededLayout = View.Layout (TopLevels.Reverse (), Screen.Size);
 
 
+        if (ClearScreenNextIteration)
+        {
+            forceDraw = true;
+            ClearScreenNextIteration = false;
+        }
         if (forceDraw)
         if (forceDraw)
         {
         {
             Driver?.ClearContents ();
             Driver?.ClearContents ();
@@ -688,6 +693,6 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         runState.Toplevel = null;
         runState.Toplevel = null;
         runState.Dispose ();
         runState.Dispose ();
 
 
-        LayoutAndDraw ();
+        LayoutAndDraw (true);
     }
     }
 }
 }

+ 10 - 1
Terminal.Gui/Application/Application.Screen.cs

@@ -63,8 +63,17 @@ public static partial class Application // Screen related stuff
             t.SetNeedsLayout ();
             t.SetNeedsLayout ();
         }
         }
 
 
-        LayoutAndDraw ();
+        LayoutAndDraw (true);
 
 
         return true;
         return true;
     }
     }
+
+    /// <summary>
+    ///     Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
+    /// </summary>
+    /// <remarks>
+    ///     This is typicall set to true when a View's <see cref="View.Frame"/> changes and that view has no
+    ///     SuperView (e.g. when <see cref="Application.Top"/> is moved or resized.
+    /// </remarks>
+    public static bool ClearScreenNextIteration { get; set; }
 }
 }

+ 2 - 0
Terminal.Gui/Application/Application.cs

@@ -215,6 +215,8 @@ public static partial class Application
 
 
         Navigation = null;
         Navigation = null;
 
 
+        ClearScreenNextIteration = false;
+
         AddApplicationKeyBindings ();
         AddApplicationKeyBindings ();
 
 
         // Reset synchronization context to allow the user to run async/await,
         // Reset synchronization context to allow the user to run async/await,

+ 8 - 1
Terminal.Gui/View/View.Layout.cs

@@ -557,7 +557,14 @@ public partial class View // Layout APIs
                 SetTitleTextFormatterSize ();
                 SetTitleTextFormatterSize ();
             }
             }
 
 
-            SuperView?.SetNeedsDraw ();
+            if (SuperView is { })
+            {
+                SuperView?.SetNeedsDraw ();
+            }
+            else
+            {
+                Application.ClearScreenNextIteration = true;
+            }
         }
         }
 
 
         if (TextFormatter.ConstrainToWidth is null)
         if (TextFormatter.ConstrainToWidth is null)

+ 8 - 1
Terminal.Gui/View/View.cs

@@ -369,7 +369,14 @@ public partial class View : IDisposable, ISupportInitializeNotification
             SetNeedsLayout ();
             SetNeedsLayout ();
             SuperView?.SetNeedsLayout ();
             SuperView?.SetNeedsLayout ();
             SetNeedsDraw ();
             SetNeedsDraw ();
-            SuperView?.SetNeedsDraw ();
+            if (SuperView is { })
+            {
+                SuperView?.SetNeedsDraw ();
+            }
+            else
+            {
+                Application.ClearScreenNextIteration = true;
+            }
         }
         }
     }
     }
 
 

+ 1 - 2
Terminal.Gui/Views/Menu/Menu.cs

@@ -608,8 +608,7 @@ internal sealed class Menu : View
 
 
         Application.UngrabMouse ();
         Application.UngrabMouse ();
         _host.CloseAllMenus ();
         _host.CloseAllMenus ();
-        Application.Driver!.ClearContents ();
-        Application.LayoutAndDraw ();
+        Application.LayoutAndDraw (true);
 
 
         _host.Run (action);
         _host.Run (action);
     }
     }

+ 1 - 1
Terminal.Gui/Views/Menu/MenuBar.cs

@@ -1117,7 +1117,7 @@ public class MenuBar : View, IDesignable
 
 
         Application.UngrabMouse ();
         Application.UngrabMouse ();
         CloseAllMenus ();
         CloseAllMenus ();
-        Application.LayoutAndDraw ();
+        Application.LayoutAndDraw (true);
         _openedByAltKey = true;
         _openedByAltKey = true;
 
 
         return Run (item.Action);
         return Run (item.Action);

+ 68 - 0
UnitTests/Application/ApplicationScreenTests.cs

@@ -0,0 +1,68 @@
+using Xunit.Abstractions;
+
+namespace Terminal.Gui.ApplicationTests;
+
+public class ApplicationScreenTests (ITestOutputHelper output)
+{
+    [Fact]
+    public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
+    {
+        // Arrange
+        Application.Init ();
+
+        // Act
+        Application.ClearScreenNextIteration = true;
+        Application.LayoutAndDraw ();
+
+        // Assert
+        Assert.False (Application.ClearScreenNextIteration);
+
+        // Cleanup
+        Application.ResetState (true);
+    }
+
+    [Fact]
+    public void ClearContents_Called_When_Top_Frame_Changes ()
+    {
+        // Arrange
+        Application.Init (new FakeDriver ());
+        Application.Top = new Toplevel ();
+        Application.TopLevels.Push (Application.Top);
+
+        int clearedContentsRaised = 0;
+
+        Application.Driver!.ClearedContents += (e, a) => clearedContentsRaised++;
+
+        // Act
+        Application.LayoutAndDraw ();
+
+        // Assert
+        Assert.Equal (1, clearedContentsRaised);
+
+        // Act
+        Application.Top.SetNeedsLayout ();
+        Application.LayoutAndDraw ();
+
+        // Assert
+        Assert.Equal (1, clearedContentsRaised);
+
+        // Act
+        Application.Top.X = 1;
+        Application.LayoutAndDraw ();
+
+        // Assert
+        Assert.Equal (2, clearedContentsRaised);
+
+        // Act
+        Application.Top.Width = 10;
+        Application.LayoutAndDraw ();
+
+        // Assert
+        Assert.Equal (3, clearedContentsRaised);
+
+        // Cleanup
+        Application.Top.Dispose ();
+        Application.Top = null;
+        Application.Shutdown ();
+    }
+}

+ 2 - 0
UnitTests/Configuration/ConfigPropertyTests.cs

@@ -5,6 +5,8 @@ using System.Text.Json.Serialization;
 using Terminal.Gui;
 using Terminal.Gui;
 using Xunit;
 using Xunit;
 
 
+namespace Terminal.Gui.ConfigurationTests;
+
 public class ConfigPropertyTests
 public class ConfigPropertyTests
 {
 {
     [Fact]
     [Fact]

+ 1 - 1
UnitTests/Drawing/SixelEncoderTests.cs

@@ -1,6 +1,6 @@
 using Color = Terminal.Gui.Color;
 using Color = Terminal.Gui.Color;
 
 
-namespace UnitTests.Drawing;
+namespace Terminal.Gui.DrawingTests;
 
 
 public class SixelEncoderTests
 public class SixelEncoderTests
 {
 {

+ 2 - 1
UnitTests/LocalPackagesTests.cs

@@ -1,4 +1,5 @@
-namespace Terminal.Gui;
+
+namespace Terminal.Gui.BuildAndDeployTests;
 
 
 public class LocalPackagesTests
 public class LocalPackagesTests
 {
 {

+ 0 - 52
bench.json

@@ -1,52 +0,0 @@
-[
-  {
-    "Scenario": "Adornments Demo",
-    "Duration": "00:00:00.1805368",
-    "IterationCount": 501,
-    "ClearedContentCount": 0,
-    "RefreshedCount": 503,
-    "UpdatedCount": 1,
-    "DrawCompleteCount": 82,
-    "LaidOutCount": 82
-  },
-  {
-    "Scenario": "All Views Tester",
-    "Duration": "00:00:00.1070009",
-    "IterationCount": 501,
-    "ClearedContentCount": 0,
-    "RefreshedCount": 503,
-    "UpdatedCount": 1,
-    "DrawCompleteCount": 103,
-    "LaidOutCount": 182
-  },
-  {
-    "Scenario": "Animation",
-    "Duration": "00:00:00.0675802",
-    "IterationCount": 501,
-    "ClearedContentCount": 0,
-    "RefreshedCount": 503,
-    "UpdatedCount": 1,
-    "DrawCompleteCount": 4,
-    "LaidOutCount": 4
-  },
-  {
-    "Scenario": "Arrangement",
-    "Duration": "00:00:00.1284709",
-    "IterationCount": 501,
-    "ClearedContentCount": 0,
-    "RefreshedCount": 503,
-    "UpdatedCount": 1,
-    "DrawCompleteCount": 123,
-    "LaidOutCount": 123
-  },
-  {
-    "Scenario": "ASCIICustomButtonTest",
-    "Duration": "00:00:01.0613372",
-    "IterationCount": 30,
-    "ClearedContentCount": 0,
-    "RefreshedCount": 32,
-    "UpdatedCount": 31,
-    "DrawCompleteCount": 4185,
-    "LaidOutCount": 2852
-  }
-]