Parcourir la source

Renamed Refresh. COde Cleanup

Tig il y a 9 mois
Parent
commit
87486b1969

+ 1 - 1
CommunityToolkitExample/LoginView.cs

@@ -59,7 +59,7 @@ internal partial class LoginView : IRecipient<Message<LoginActions>>
                 }
         }
         SetText();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 
     private void SetText ()

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

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

+ 26 - 57
Terminal.Gui/Application/Application.Run.cs

@@ -207,7 +207,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         NotifyNewRunState?.Invoke (toplevel, new (rs));
 
         // Force an Idle event so that an Iteration (and Refresh) happen.
-        Application.Invoke(() => {});
+        Application.Invoke (() => { });
 
         return rs;
     }
@@ -496,33 +496,29 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     public static void Wakeup () { MainLoop?.Wakeup (); }
 
     /// <summary>
-    /// Refreshes layout and the display. Only Views that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out.
+    /// Causes any Toplevels that need layout to be laid out. Then draws any Toplevels that need dispplay. 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.NeedsDisplay"/>) will be drawn.
     /// </summary>
-    /// <param name="forceRedraw">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 Refresh (bool forceRedraw = false, object context = null)
+    /// <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 LayoutAndDrawToplevels (bool forceDraw = false)
     {
-        //WindowsConsole.InputRecord rec = new WindowsConsole.InputRecord();
-        //if (context is WindowsConsole.InputRecord record)
-        //{
-        //    rec = record;
-        //    if (record is { EventType: WindowsConsole.EventType.Focus })
-        //    {
-        //        return;
-        //    }
-
-        //    if (record is { EventType: WindowsConsole.EventType.Key })
-        //    {
-        //        var key = (WindowsConsole.KeyEventRecord)record.KeyEvent;
-        //        if (key is { dwControlKeyState: WindowsConsole.ControlKeyState.LeftAltPressed })
-        //        {
-        //            return;
-        //        }
-        //    }
+        bool neededLayout = false;
+        neededLayout = LayoutToplevels ();
+
+        if (forceDraw)
+        {
+            Driver?.ClearContents ();
+        }
 
-        //}
+        DrawToplevels (neededLayout || forceDraw);
 
+        Driver?.Refresh ();
+    }
+
+    private static bool LayoutToplevels ()
+    {
         bool neededLayout = false;
+
         foreach (Toplevel tl in TopLevels.Reverse ())
         {
             if (tl.NeedsLayout)
@@ -532,48 +528,23 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             }
         }
 
-        if (forceRedraw)
-        {
-           Driver?.ClearContents ();
-        }
+        return neededLayout;
+    }
 
+    private static void DrawToplevels (bool forceDraw)
+    {
         foreach (Toplevel tl in TopLevels.Reverse ())
         {
-            if (neededLayout)
+            if (forceDraw)
             {
                 tl.SetNeedsDisplay ();
             }
 
             tl.Draw ();
         }
-
-        // Stack<Toplevel> redrawStack = new (TopLevels);
-
-        //// Debug.WriteLine ($"{DateTime.Now}.{DateTime.Now.Millisecond} - Refresh {rec} = {redrawStack.Count}");
-        // while (redrawStack.Count > 0)
-        // {
-        //     Toplevel? tlToDraw = redrawStack.Pop ();
-
-        //     if (forceRedraw)
-        //     {
-        //         tlToDraw.SetNeedsDisplay ();
-        //     }
-
-        //     if (View.CanBeVisible (tlToDraw))
-        //     {
-        //         bool needs =  tlToDraw.NeedsDisplay || tlToDraw.SubViewNeedsDisplay;
-        //         tlToDraw.Draw ();
-
-        //         if (needs && redrawStack.TryPeek (out var nexToplevel))
-        //         {
-        //             nexToplevel.SetNeedsDisplay ();
-        //         }
-        //     }
-        // }
-
-        Driver?.Refresh ();
     }
 
+
     /// <summary>This event is raised on each iteration of the main loop.</summary>
     /// <remarks>See also <see cref="Timeout"/></remarks>
     public static event EventHandler<IterationEventArgs>? Iteration;
@@ -633,9 +604,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
                 state.Toplevel.OnReady ();
             }
 
-            object ctx = state.Context;
             MainLoop.RunIteration ();
-            state.Context = ctx;
 
             Iteration?.Invoke (null, new ());
         }
@@ -647,7 +616,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             return firstIteration;
         }
 
-        Refresh (context: state.Context);
+        LayoutAndDrawToplevels ();
 
         if (PositionCursor ())
         {
@@ -747,6 +716,6 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         runState.Toplevel = null;
         runState.Dispose ();
 
-        Refresh (context: "End");
+        LayoutAndDrawToplevels ();
     }
 }

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

@@ -63,7 +63,7 @@ public static partial class Application // Screen related stuff
             t.SetNeedsLayout ();
         }
 
-        Refresh ();
+        LayoutAndDrawToplevels ();
 
         return true;
     }

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

@@ -10,8 +10,6 @@ public class RunState : IDisposable
     /// <summary>The <see cref="Toplevel"/> belonging to this <see cref="RunState"/>.</summary>
     public Toplevel Toplevel { get; internal set; }
 
-    public object Context { get; internal set; }
-
     /// <summary>Releases all resource used by the <see cref="RunState"/> object.</summary>
     /// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="RunState"/>.</remarks>
     /// <remarks>

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

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

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

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

+ 1 - 1
UICatalog/Scenarios/GraphViewExample.cs

@@ -214,7 +214,7 @@ public class GraphViewExample : Scenario
                                ? ViewDiagnosticFlags.Thickness
                                  | ViewDiagnosticFlags.Ruler
                                : ViewDiagnosticFlags.Off;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 
     private void Margin (bool left, bool increase)

+ 1 - 1
UICatalog/Scenarios/Images.cs

@@ -100,7 +100,7 @@ public class Images : Scenario
                                    }
 
                                    imageView.SetImage (img);
-                                   Application.Refresh ();
+                                   Application.LayoutAndDrawToplevels ();
                                };
 
         Application.Run (win);

+ 1 - 1
UICatalog/Scenarios/Localization.cs

@@ -38,7 +38,7 @@ public class Localization : Scenario
 
         CurrentCulture = culture;
         Thread.CurrentThread.CurrentUICulture = culture;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 
     public override void Main ()

+ 3 - 3
UICatalog/Scenarios/RuneWidthGreaterThanOne.cs

@@ -115,7 +115,7 @@ public class RuneWidthGreaterThanOne : Scenario
         _labelV.Text = "This is a test text 你";
         _win.Title = "HACC Demo 你";
         _lastRunesUsed = "Mixed";
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 
     private void NarrowMessage (object sender, EventArgs e) { MessageBox.Query ("Say Hello", $"Hello {_text.Text}", "Ok"); }
@@ -135,7 +135,7 @@ public class RuneWidthGreaterThanOne : Scenario
         _labelV.Text = "This is a test text";
         _win.Title = "HACC Demo";
         _lastRunesUsed = "Narrow";
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 
     private void UnsetClickedEvent ()
@@ -174,6 +174,6 @@ public class RuneWidthGreaterThanOne : Scenario
         _labelV.Text = "あなたの名前を入力してください";
         _win.Title = "デモエムポンズ";
         _lastRunesUsed = "Wide";
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/SingleBackgroundWorker.cs

@@ -176,7 +176,7 @@ public class SingleBackgroundWorker : Scenario
                                                             $"Worker {_startStaging}.{_startStaging:fff} was completed at {DateTime.Now}."
                                                            );
                                                   _listLog.SetNeedsDisplay ();
-                                                  Application.Refresh ();
+                                                  Application.LayoutAndDrawToplevels ();
 
                                                   var builderUI =
                                                       new StagingUIController (_startStaging, e.Result as ObservableCollection<string>);

+ 2 - 2
UICatalog/UICatalog.cs

@@ -754,7 +754,7 @@ public class UICatalogApp
                                                               {
                                                                   Application.Force16Colors = args.NewValue == CheckState.Checked;
                                                                   MiForce16Colors!.Checked = Application.Force16Colors;
-                                                                  Application.Refresh ();
+                                                                  Application.LayoutAndDrawToplevels ();
                                                               };
 
             _statusBar.Add (
@@ -1266,7 +1266,7 @@ public class UICatalogApp
 
                                           ((CheckBox)ShForce16Colors!.CommandView!).CheckedState =
                                               Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
-                                          Application.Refresh ();
+                                          Application.LayoutAndDrawToplevels ();
                                       };
             menuItems.Add (MiForce16Colors);
 

+ 6 - 6
UnitTests/Dialogs/DialogTests.cs

@@ -933,7 +933,7 @@ public class DialogTests
 
                           dlg.Loaded += (s, a) =>
                                         {
-                                            Refresh ();
+                                            LayoutAndDrawToplevels ();
 
                                             var expected = @$"
 ┌──────────────────┐
@@ -1038,7 +1038,7 @@ public class DialogTests
                          }
                          else if (iterations == 1)
                          {
-                             Refresh ();
+                             LayoutAndDrawToplevels ();
 
                              // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)?? No
                              _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
@@ -1110,7 +1110,7 @@ public class DialogTests
                              case 0:
                                  Top.SetNeedsLayout();
                                  Top.SetNeedsDisplay();
-                                 Refresh ();
+                                 LayoutAndDrawToplevels ();
 
                                  break;
 
@@ -1119,7 +1119,7 @@ public class DialogTests
 
                                  break;
                              case 2:
-                                 Refresh ();
+                                 LayoutAndDrawToplevels ();
 
                                  expected = @$"
   ┌───────────────────────┐
@@ -1136,7 +1136,7 @@ public class DialogTests
 
                                  break;
                              case 3:
-                                 Refresh ();
+                                 LayoutAndDrawToplevels ();
 
                                  TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                @$"
@@ -1155,7 +1155,7 @@ public class DialogTests
 
                                  break;
                              case 4:
-                                 Refresh ();
+                                 LayoutAndDrawToplevels ();
 
                                  TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
 

+ 8 - 8
UnitTests/Dialogs/MessageBoxTests.cs

@@ -219,7 +219,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                        @"
@@ -236,7 +236,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 2)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                        @"
@@ -291,7 +291,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                        @"
@@ -311,7 +311,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 2)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                        @$"
@@ -361,7 +361,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.IsType<Dialog> (Application.Top);
                                          Assert.Equal (new (height, width), Application.Top.Frame.Size);
@@ -398,7 +398,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.IsType<Dialog> (Application.Top);
                                          Assert.Equal (new (height, width), Application.Top.Frame.Size);
@@ -431,7 +431,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.IsType<Dialog> (Application.Top);
                                          Assert.Equal (new (height, width), Application.Top.Frame.Size);
@@ -471,7 +471,7 @@ public class MessageBoxTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          string expectedText = """
                                                                ┌────────────────────────────────────────────────────────────────────┐

+ 8 - 8
UnitTests/Drawing/RulerTests.cs

@@ -68,7 +68,7 @@ public class RulerTests
 
         // Postive offset
         top.SetNeedsDisplay ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Draw (new (1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -83,7 +83,7 @@ public class RulerTests
 
         // Negative offset
         top.SetNeedsDisplay ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Draw (new (-1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -98,7 +98,7 @@ public class RulerTests
 
         // Clip
         top.SetNeedsDisplay ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Draw (new (10, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -144,7 +144,7 @@ public class RulerTests
                                                      );
 
         f.SetNeedsDisplay();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Length = len;
         r.Draw (new (1, 0), 1);
 
@@ -207,7 +207,7 @@ public class RulerTests
 
         // Postive offset
         f.SetNeedsDisplay ();
-        Application.Refresh (true);
+        Application.LayoutAndDrawToplevels (true);
         r.Draw (new (1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -237,7 +237,7 @@ public class RulerTests
 
         // Negative offset
         f.SetNeedsDisplay ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Draw (new (1, -1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -268,7 +268,7 @@ public class RulerTests
         // Clip
         f.SetNeedsDisplay ();
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         r.Draw (new (1, 10));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -343,7 +343,7 @@ public class RulerTests
                                                       _output
                                                      );
         f.SetNeedsDisplay ();
-        Application.Refresh (true);
+        Application.LayoutAndDrawToplevels (true);
         r.Length = len;
         r.Draw (new (0, 1), 1);
 

+ 20 - 20
UnitTests/View/Draw/DrawTests.cs

@@ -590,7 +590,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.X = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -605,12 +605,12 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.X = -2;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
 
         content.X = 0;
         content.Y = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -625,7 +625,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -6;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -640,7 +640,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -19;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -651,12 +651,12 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -20;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
 
         content.X = -2;
         content.Y = 0;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
         top.Dispose ();
     }
@@ -696,7 +696,7 @@ public class DrawTests (ITestOutputHelper _output)
         top.SubviewsLaidOut += Top_LayoutComplete;
         Application.Begin (top);
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
                                                       
@@ -707,7 +707,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.X = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -719,7 +719,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -730,12 +730,12 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -2;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
 
         content.X = -20;
         content.Y = 0;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
         top.Dispose ();
 
@@ -783,7 +783,7 @@ public class DrawTests (ITestOutputHelper _output)
         top.Add (container);
         Application.Begin (top);
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
                                                       
@@ -797,7 +797,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.X = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -812,12 +812,12 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.X = -2;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
 
         content.X = 0;
         content.Y = -1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -832,7 +832,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -6;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -847,7 +847,7 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -19;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       """
@@ -858,12 +858,12 @@ public class DrawTests (ITestOutputHelper _output)
                                                      );
 
         content.Y = -20;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
 
         content.X = -2;
         content.Y = 0;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
         top.Dispose ();
     }

+ 4 - 4
UnitTests/View/SubviewTests.cs

@@ -145,7 +145,7 @@ public class SubviewTests
                                Assert.False (v2AddedToWin.CanFocus);
                                Assert.False (svAddedTov1.CanFocus);
 
-                               Application.Refresh ();
+                               Application.LayoutAndDrawToplevels ();
                            };
 
         winAddedToTop.Initialized += (s, e) =>
@@ -201,7 +201,7 @@ public class SubviewTests
 
         Application.Iteration += (s, a) =>
                                  {
-                                     Application.Refresh ();
+                                     Application.LayoutAndDrawToplevels ();
                                      top.Running = false;
                                  };
 
@@ -253,7 +253,7 @@ public class SubviewTests
                              Assert.False (v1.CanFocus);
                              Assert.False (v2.CanFocus);
 
-                             Application.Refresh ();
+                             Application.LayoutAndDrawToplevels ();
                          };
 
         w.Initialized += (s, e) =>
@@ -297,7 +297,7 @@ public class SubviewTests
 
                                      v1.Add (sv1);
 
-                                     Application.Refresh ();
+                                     Application.LayoutAndDrawToplevels ();
                                      t.Running = false;
                                  };
 

+ 1 - 1
UnitTests/View/ViewTests.cs

@@ -212,7 +212,7 @@ cccccccccccccccccccc",
             Assert.True (v.HasFocus);
             v.SetFocus ();
             Assert.True (v.HasFocus);
-            Application.Refresh ();
+            Application.LayoutAndDrawToplevels ();
 
             TestHelpers.AssertDriverAttributesAre (
                                                    @"

+ 4 - 4
UnitTests/Views/CheckBoxTests.cs

@@ -359,7 +359,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.CheckedState = CheckState.Checked;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
@@ -429,7 +429,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         Application.RunIteration (ref rs);
         Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
         Assert.Equal (_size25x1, checkBox2.TextFormatter.ConstrainToSize);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
@@ -480,7 +480,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.CheckedState = CheckState.Checked;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
@@ -531,7 +531,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.CheckedState = CheckState.Checked;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐

+ 16 - 16
UnitTests/Views/ContextMenuTests.cs

@@ -138,7 +138,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         var top = new Toplevel { X = 2, Y = 2, Width = 15, Height = 4 };
         top.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" });
         RunState rs = Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new Rectangle (2, 2, 15, 4), top.Frame);
         Assert.Equal (top, Application.Top);
@@ -209,7 +209,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         var testWindow = new Window { X = 2, Y = 2, Width = 15, Height = 4 };
         testWindow.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" });
         RunState rsDialog = Application.Begin (testWindow);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new Rectangle (2, 2, 15, 4), testWindow.Frame);
 
@@ -275,7 +275,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         var dialog = new Window { X = 2, Y = 2, Width = 15, Height = 4 };
         dialog.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" });
         RunState rs = Application.Begin (dialog);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new Rectangle (2, 2, 15, 4), dialog.Frame);
         Assert.Equal (dialog, Application.Top);
@@ -336,7 +336,7 @@ public class ContextMenuTests (ITestOutputHelper output)
 
         cm.Show (menuItems);
         Assert.Equal (new Point (-1, -2), cm.Position);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ┌──────┐
@@ -351,7 +351,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         cm.ForceMinimumPosToZero = false;
         cm.Show (menuItems);
         Assert.Equal (new Point (-1, -2), cm.Position);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
  One  │
@@ -443,7 +443,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Toplevel top = new ();
         Application.Begin (top);
         cm.Show (menuItems);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
           ┌──────┐
@@ -463,7 +463,7 @@ public class ContextMenuTests (ITestOutputHelper output)
                                     );
 
         cm.Show (menuItems);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
           ┌─────────┐
@@ -801,7 +801,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Toplevel top = new ();
         Application.Begin (top);
         cm.Show (menuItems);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
           ┌──────┐
@@ -815,7 +815,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         cm.Position = new Point (5, 10);
 
         cm.Show (menuItems);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
      ┌──────┐
@@ -936,7 +936,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Application.Begin (top);
         cm.Show (menuItems);
         Assert.Equal (Point.Empty, cm.Position);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ┌──────┐
@@ -974,7 +974,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Application.Begin (top);
         cm.Show (menuItems);
         Assert.Equal (Point.Empty, cm.Position);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ┌────
@@ -1085,7 +1085,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Application.Begin (top);
         cm.Show (menuItems);
         Assert.Equal (new Point (80, 25), cm.Position);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
                                                                         ┌──────┐
@@ -1170,7 +1170,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Application.Begin (top);
         cm.Show (menuItems);
         Assert.True (ContextMenu.IsShow);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
           ┌──────┐
@@ -1184,7 +1184,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         cm.Hide ();
         Assert.False (ContextMenu.IsShow);
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = "";
 
@@ -1224,7 +1224,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         RunState rs = Application.Begin (top);
         cm.Show (menuItems);
         Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top!.Subviews [0].Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -1317,7 +1317,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         cm.Show (menuItems);
 
         Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

+ 4 - 4
UnitTests/Views/FrameViewTests.cs

@@ -50,7 +50,7 @@ public class FrameViewTests (ITestOutputHelper output)
         fv.Height = 5;
         fv.Width = 5;
         Assert.Equal (new (0, 0, 5, 5), fv.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -65,7 +65,7 @@ public class FrameViewTests (ITestOutputHelper output)
         fv.X = 1;
         fv.Y = 2;
         Assert.Equal (new (1, 2, 5, 5), fv.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -80,7 +80,7 @@ public class FrameViewTests (ITestOutputHelper output)
         fv.X = -1;
         fv.Y = -2;
         Assert.Equal (new (-1, -2, 5, 5), fv.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -93,7 +93,7 @@ public class FrameViewTests (ITestOutputHelper output)
         fv.X = 7;
         fv.Y = 8;
         Assert.Equal (new (7, 8, 5, 5), fv.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

+ 9 - 9
UnitTests/Views/LabelTests.cs

@@ -111,7 +111,7 @@ public class LabelTests (ITestOutputHelper output)
 
         label.Text = "Say Hello 你 changed";
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
 ┌────────────────────────────┐
@@ -151,7 +151,7 @@ public class LabelTests (ITestOutputHelper output)
 
         label.Text = "Say Hello 你 changed";
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
 ┌────────────────────────────┐
@@ -244,7 +244,7 @@ This TextFormatter (tf2) is rewritten.                                 ",
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (0, 0, 16, 1), label.Frame);
 
@@ -265,7 +265,7 @@ Demo Simple Rune
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.NotNull (label.Width);
         Assert.NotNull (label.Height);
 
@@ -301,7 +301,7 @@ e
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
@@ -472,7 +472,7 @@ e
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (0, 0, 6, 3), label.Frame);
         Assert.Equal (new (0, 0, 4, 1), label.Viewport);
@@ -496,7 +496,7 @@ e
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 6, 2), label.Frame);
         Assert.Equal (new (0, 0, 4, 1), label.Viewport);
         Application.Begin (top);
@@ -1224,7 +1224,7 @@ e
         Assert.Equal (10, text.Length);
 
         //label.Width = Dim.Fill () - text.Length;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (0, 0, 5, 1), label.Frame);
         Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);
@@ -1283,7 +1283,7 @@ e
         Assert.Equal (10, text.Length);
 
         //label.Width = Dim.Fill () - text.Length;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (0, 0, 5, 1), label.Frame);
         Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);

+ 7 - 7
UnitTests/Views/ListViewTests.cs

@@ -56,7 +56,7 @@ public class ListViewTests (ITestOutputHelper output)
         top.Add (win);
         Application.Begin (top);
         ((FakeDriver)Application.Driver!).SetBufferSize (12, 12);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (-1, lv.SelectedItem);
 
@@ -305,7 +305,7 @@ public class ListViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (lv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -319,7 +319,7 @@ Item 4",
 
         // EnsureSelectedItemVisible is auto enabled on the OnSelectedChanged
         lv.SelectedItem = 6;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -343,7 +343,7 @@ Item 6",
         var top = new Toplevel ();
         top.Add (lv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal ("Second ", GetContents (0));
         Assert.Equal (new (' ', 7), GetContents (1));
@@ -725,7 +725,7 @@ Item 6",
         var top = new Toplevel ();
         top.Add (lv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (1), lv.Border.Thickness);
         Assert.Equal (-1, lv.SelectedItem);
@@ -799,7 +799,7 @@ Item 6",
         var top = new Toplevel ();
         top.Add (lv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -812,7 +812,7 @@ Item 6",
 
         lv.LeftItem = 1;
         lv.TopItem = 1;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

+ 17 - 17
UnitTests/Views/MenuBarTests.cs

@@ -100,7 +100,7 @@ public class MenuBarTests (ITestOutputHelper output)
                                          new () { Position = new (0, 0), Flags = MouseFlags.Button1Pressed, View = menu }
                                         )
                     );
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @$"
@@ -880,7 +880,7 @@ public class MenuBarTests (ITestOutputHelper output)
         Toplevel top = new ();
         Application.Begin (top);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ──────┐
@@ -895,7 +895,7 @@ public class MenuBarTests (ITestOutputHelper output)
         menu.CloseAllMenus ();
         menu.Frame = new (-1, -2, menu.Frame.Width, menu.Frame.Height);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
  One  │
@@ -910,7 +910,7 @@ public class MenuBarTests (ITestOutputHelper output)
         menu.Frame = new (0, 0, menu.Frame.Width, menu.Frame.Height);
         ((FakeDriver)Application.Driver!).SetBufferSize (7, 5);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
 ┌──────
@@ -926,7 +926,7 @@ public class MenuBarTests (ITestOutputHelper output)
         menu.Frame = new (0, 0, menu.Frame.Width, menu.Frame.Height);
         ((FakeDriver)Application.Driver!).SetBufferSize (7, 3);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
 ┌──────
@@ -960,7 +960,7 @@ public class MenuBarTests (ITestOutputHelper output)
         Toplevel top = new ();
         Application.Begin (top);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ne
@@ -972,7 +972,7 @@ wo
         menu.CloseAllMenus ();
         menu.Frame = new (-2, -2, menu.Frame.Width, menu.Frame.Height);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
 wo
@@ -984,7 +984,7 @@ wo
         menu.Frame = new (0, 0, menu.Frame.Width, menu.Frame.Height);
         ((FakeDriver)Application.Driver!).SetBufferSize (3, 2);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
  On
@@ -997,7 +997,7 @@ wo
         menu.Frame = new (0, 0, menu.Frame.Width, menu.Frame.Height);
         ((FakeDriver)Application.Driver!).SetBufferSize (3, 1);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expected = @"
  On
@@ -1024,7 +1024,7 @@ wo
         Toplevel top = new ();
         Application.Begin (top);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ┌──────┐
@@ -1056,7 +1056,7 @@ wo
         Toplevel top = new ();
         Application.Begin (top);
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
  One
@@ -1479,7 +1479,7 @@ wo
         Application.Begin (top);
 
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -1527,7 +1527,7 @@ wo
         Application.Begin (top);
 
         menu.OpenMenu ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -1660,7 +1660,7 @@ wo
                                                      );
 
         Assert.True (menu.NewKeyDownEvent (Key.CursorRight));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -1771,7 +1771,7 @@ wo
                                                                                   );
 
                                      Assert.True (menu.NewKeyDownEvent (Key.CursorRight));
-                                     Application.Refresh ();
+                                     Application.LayoutAndDrawToplevels ();
 
                                      TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                    @"
@@ -1942,7 +1942,7 @@ wo
         Application.Iteration += (s, a) =>
                                  {
                                      Toplevel top = Application.Top;
-                                     Application.Refresh();
+                                     Application.LayoutAndDrawToplevels();
 
                                      TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                    @"
@@ -1974,7 +1974,7 @@ wo
                                                                                   );
 
                                      Assert.True (top.Subviews [0].NewKeyDownEvent (Key.CursorRight));
-                                     Application.Refresh ();
+                                     Application.LayoutAndDrawToplevels ();
 
                                      TestHelpers.AssertDriverContentsWithFrameAre (
                                                                                    @"

+ 2 - 2
UnitTests/Views/RadioGroupTests.cs

@@ -549,7 +549,7 @@ public class RadioGroupTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         rg.Orientation = Orientation.Horizontal;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (Orientation.Horizontal, rg.Orientation);
         Assert.Equal (2, rg.HorizontalSpace);
@@ -570,7 +570,7 @@ public class RadioGroupTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         rg.HorizontalSpace = 4;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (Orientation.Horizontal, rg.Orientation);
         Assert.Equal (4, rg.HorizontalSpace);

+ 12 - 12
UnitTests/Views/ScrollBarViewTests.cs

@@ -178,7 +178,7 @@ public class ScrollBarViewTests
 
         Application.Begin (top);
         ((FakeDriver)Application.Driver!).SetBufferSize (width, height);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
 ┌─┐
@@ -231,7 +231,7 @@ public class ScrollBarViewTests
     {
         _scrollBar = new ScrollBarView (_hostView, true);
         Application.Begin (_hostView.SuperView as Toplevel);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         AddHandlers ();
 
@@ -252,7 +252,7 @@ public class ScrollBarViewTests
     {
         _scrollBar = new ScrollBarView (_hostView, true);
         Application.Begin (_hostView.SuperView as Toplevel);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         AddHandlers ();
 
@@ -288,7 +288,7 @@ public class ScrollBarViewTests
     {
         _scrollBar = new ScrollBarView (_hostView, true);
         Application.Begin (_hostView.SuperView as Toplevel);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         AddHandlers ();
 
@@ -312,7 +312,7 @@ public class ScrollBarViewTests
 
         var sbv = new ScrollBarView (label, true, false) { Size = 100 };
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.True (sbv.Visible);
 
@@ -430,7 +430,7 @@ This is a test
 
                                                                                       Assert.Equal (newScrollBarView.Position, listView.LeftItem);
                                                                                       listView.SetNeedsDisplay ();
-                                                                                      Application.Refresh ();
+                                                                                      Application.LayoutAndDrawToplevels ();
 
                                                                                   };
 
@@ -511,7 +511,7 @@ This is a test
 
                                                                                             Assert.Equal (newScrollBarView.Position, listView.TopItem);
                                                                                             listView.SetNeedsDisplay ();
-                                                                                            Application.Refresh ();
+                                                                                            Application.LayoutAndDrawToplevels ();
 
                                                                                         };
 
@@ -562,7 +562,7 @@ This is a test
         var sbv = new ScrollBarView (label, true) { Size = 100 };
         sbv.OtherScrollBarView.Size = 100;
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (100, sbv.Size);
         Assert.Equal (100, sbv.OtherScrollBarView.Size);
@@ -646,7 +646,7 @@ This is a tes▼
 
         var sbv = new ScrollBarView (label, true, false) { Size = 100 };
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (100, sbv.Size);
         Assert.Null (sbv.OtherScrollBarView);
@@ -691,7 +691,7 @@ This is a test
     {
         _scrollBar = new ScrollBarView (_hostView, true);
         Application.Begin (_hostView.SuperView as Toplevel);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         AddHandlers ();
 
@@ -1168,7 +1168,7 @@ This is a test
 
         var sbv = new ScrollBarView (label, true, false) { Size = 5 };
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (5, sbv.Size);
         Assert.Null (sbv.OtherScrollBarView);
@@ -1196,7 +1196,7 @@ This is a test             ",
         Assert.Equal (5, sbv.Size);
         Assert.False (sbv.ShowScrollIndicator);
         Assert.True (sbv.Visible);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.False (sbv.Visible);
 
         TestHelpers.AssertDriverContentsWithFrameAre (

+ 9 - 9
UnitTests/Views/ScrollViewTests.cs

@@ -195,7 +195,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (topLabel, sv, bottomLabel);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -250,7 +250,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         sv.Add (new Window { X = 3, Y = 3, Width = 20, Height = 20 });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -297,7 +297,7 @@ public class ScrollViewTests (ITestOutputHelper output)
                                               );
 
         sv.ContentOffset = new (20, 20);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -461,7 +461,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (sv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (new (-25, -25), sv.ContentOffset);
         Assert.Equal (new (50, 50), sv.GetContentSize ());
@@ -497,7 +497,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (sv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (50, sv.GetContentSize ().Width);
         Assert.Equal (50, sv.GetContentSize ().Height);
@@ -567,7 +567,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (win);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         var expected = @"
  ┌──────────────────┐
@@ -898,7 +898,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (sv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -917,7 +917,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
         sv.ContentOffset = new (5, 5);
         sv.LayoutSubviews ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -1085,7 +1085,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         var top = new Toplevel ();
         top.Add (sv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (4, sv.Subviews.Count);
         Assert.Equal (2, sv.Subviews [0].Subviews.Count);

+ 16 - 16
UnitTests/Views/TabViewTests.cs

@@ -145,21 +145,21 @@ public class TabViewTests (ITestOutputHelper output)
         {
             args = new () { ScreenPosition = new (i, 1), Flags = MouseFlags.ReportMousePosition };
             Application.RaiseMouseEvent (args);
-            Application.Refresh ();
+            Application.LayoutAndDrawToplevels ();
             Assert.Null (clicked);
             Assert.Equal (tab1, tv.SelectedTab);
         }
 
         args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab1, clicked);
         Assert.Equal (tab1, tv.SelectedTab);
 
         // Click to tab2
         args = new () { ScreenPosition = new (6, 1), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab2, clicked);
         Assert.Equal (tab2, tv.SelectedTab);
 
@@ -172,7 +172,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         // Tab 1 was clicked but event handler blocked navigation
         Assert.Equal (tab1, clicked);
@@ -180,7 +180,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         args = new () { ScreenPosition = new (12, 1), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         // Clicking beyond last tab should raise event with null Tab
         Assert.Null (clicked);
@@ -235,7 +235,7 @@ public class TabViewTests (ITestOutputHelper output)
         // Click the right arrow
         var args = new MouseEventArgs { ScreenPosition = new (6, 2), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Null (clicked);
         Assert.Equal (tab1, oldChanged);
         Assert.Equal (tab2, newChanged);
@@ -255,7 +255,7 @@ public class TabViewTests (ITestOutputHelper output)
         // Click the left arrow
         args = new () { ScreenPosition = new (0, 2), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Null (clicked);
         Assert.Equal (tab2, oldChanged);
         Assert.Equal (tab1, newChanged);
@@ -326,7 +326,7 @@ public class TabViewTests (ITestOutputHelper output)
         // Click the right arrow
         var args = new MouseEventArgs { ScreenPosition = new (7, 3), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Null (clicked);
         Assert.Equal (tab1, oldChanged);
         Assert.Equal (tab2, newChanged);
@@ -348,7 +348,7 @@ public class TabViewTests (ITestOutputHelper output)
         // Click the left arrow
         args = new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked };
         Application.RaiseMouseEvent (args);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Null (clicked);
         Assert.Equal (tab2, oldChanged);
         Assert.Equal (tab1, newChanged);
@@ -399,7 +399,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the cursor up key to focus the selected tab
         Application.RaiseKeyDownEvent (Key.CursorUp);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         // Is the selected tab focused
         Assert.Equal (tab1, tv.SelectedTab);
@@ -417,7 +417,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the cursor right key to select the next tab
         Application.RaiseKeyDownEvent (Key.CursorRight);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab1, oldChanged);
         Assert.Equal (tab2, newChanged);
         Assert.Equal (tab2, tv.SelectedTab);
@@ -475,7 +475,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the cursor left key to select the previous tab
         Application.RaiseKeyDownEvent (Key.CursorLeft);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab2, oldChanged);
         Assert.Equal (tab1, newChanged);
         Assert.Equal (tab1, tv.SelectedTab);
@@ -485,7 +485,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the end key to select the last tab
         Application.RaiseKeyDownEvent (Key.End);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab1, oldChanged);
         Assert.Equal (tab2, newChanged);
         Assert.Equal (tab2, tv.SelectedTab);
@@ -494,7 +494,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the home key to select the first tab
         Application.RaiseKeyDownEvent (Key.Home);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab2, oldChanged);
         Assert.Equal (tab1, newChanged);
         Assert.Equal (tab1, tv.SelectedTab);
@@ -503,7 +503,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the page down key to select the next set of tabs
         Application.RaiseKeyDownEvent (Key.PageDown);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab1, oldChanged);
         Assert.Equal (tab2, newChanged);
         Assert.Equal (tab2, tv.SelectedTab);
@@ -512,7 +512,7 @@ public class TabViewTests (ITestOutputHelper output)
 
         // Press the page up key to select the previous set of tabs
         Application.RaiseKeyDownEvent (Key.PageUp);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (tab2, oldChanged);
         Assert.Equal (tab1, newChanged);
         Assert.Equal (tab1, tv.SelectedTab);

+ 27 - 27
UnitTests/Views/TextViewTests.cs

@@ -723,7 +723,7 @@ public class TextViewTests
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.False (tv.WordWrap);
         Assert.Equal (Point.Empty, tv.CursorPosition);
@@ -796,7 +796,7 @@ This is the second line.
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.True (tv.WordWrap);
         Assert.Equal (Point.Empty, tv.CursorPosition);
@@ -869,7 +869,7 @@ This is the second line.
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.False (tv.WordWrap);
         Assert.Equal (Point.Empty, tv.CursorPosition);
@@ -942,7 +942,7 @@ This is the second line.
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.True (tv.WordWrap);
         Assert.Equal (Point.Empty, tv.CursorPosition);
@@ -6738,7 +6738,7 @@ This is the second line.
         Assert.True (_textView.Multiline);
         _textView.NewKeyDownEvent (Key.Tab);
         Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -6747,7 +6747,7 @@ TAB to jump between text field",
                                                      );
 
         _textView.TabWidth = 4;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -6758,7 +6758,7 @@ TAB to jump between text field",
         _textView.NewKeyDownEvent (Key.Tab.WithShift);
         Assert.Equal ("TAB to jump between text fields.", _textView.Text);
         Assert.True (_textView.NeedsDisplay);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -6824,7 +6824,7 @@ TAB to jump between text field",
         top.Add (win);
         Application.Begin (top);
         ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         //this passes
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
@@ -6853,7 +6853,7 @@ TAB to jump between text field",
         tv.Used = false;
         tv.CursorPosition = Point.Empty;
         tv.InsertText ("\r\naaa\r\nbbb");
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -6902,7 +6902,7 @@ TAB to jump between text field",
         top.Add (win);
         Application.Begin (top);
         ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         //this passes
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (
@@ -6931,7 +6931,7 @@ TAB to jump between text field",
         tv.Used = false;
         tv.CursorPosition = Point.Empty;
         tv.InsertText ("\naaa\nbbb");
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -7000,7 +7000,7 @@ TAB to jump between text field",
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.False (tv.WordWrap);
         Assert.Equal (Point.Empty, tv.CursorPosition);
@@ -8173,7 +8173,7 @@ line.
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.Equal (Point.Empty, tv.CursorPosition);
         Assert.Equal (0, tv.LeftColumn);
@@ -8187,7 +8187,7 @@ aaaa
 
         tv.CursorPosition = new Point (5, 0);
         Assert.True (tv.NewKeyDownEvent (Key.Backspace));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (0, tv.LeftColumn);
 
         TestHelpers.AssertDriverContentsAre (
@@ -8198,7 +8198,7 @@ aaa
                                             );
 
         Assert.True (tv.NewKeyDownEvent (Key.Backspace));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (0, tv.LeftColumn);
 
         TestHelpers.AssertDriverContentsAre (
@@ -8209,7 +8209,7 @@ aa
                                             );
 
         Assert.True (tv.NewKeyDownEvent (Key.Backspace));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (0, tv.LeftColumn);
 
         TestHelpers.AssertDriverContentsAre (
@@ -8220,7 +8220,7 @@ a
                                             );
 
         Assert.True (tv.NewKeyDownEvent (Key.Backspace));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (0, tv.LeftColumn);
 
         TestHelpers.AssertDriverContentsAre (
@@ -8231,7 +8231,7 @@ a
                                             );
 
         Assert.True (tv.NewKeyDownEvent (Key.Backspace));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (0, tv.LeftColumn);
 
         TestHelpers.AssertDriverContentsAre (
@@ -8253,7 +8253,7 @@ a
         _textView.Text = "Line 1.\nLine 2.";
         _textView.WordWrap = true;
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.True (_textView.WordWrap);
 
@@ -8268,12 +8268,12 @@ Line 2.",
         Assert.Equal ("Line 1.", _textView.SelectedText);
 
         Assert.True (_textView.NewKeyDownEvent (new Key (del)));
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre ("Line 2.", _output);
 
         Assert.True (_textView.NewKeyDownEvent (Key.H.WithShift));
         Assert.NotEqual (Rectangle.Empty, _textView._needsDisplayRect);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -8910,7 +8910,7 @@ line.
         var top = new Toplevel ();
         top.Add (tv);
         Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -8922,7 +8922,7 @@ This is the second line.",
         tv.Width = 10;
         tv.Height = 25;
         tv.WordWrap = true;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -8964,7 +8964,7 @@ line.  ",
         var top = new Toplevel ();
         top.Add (tv);
         RunState rs = Application.Begin (top);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Assert.True (tv.InheritsPreviousAttribute);
 
@@ -9006,7 +9006,7 @@ Error   ";
         TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
 
         tv.WordWrap = true;
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
         TestHelpers.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
 
@@ -9018,7 +9018,7 @@ Error   ";
         tv.IsSelecting = false;
         tv.CursorPosition = new (2, 4);
         tv.Paste ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expectedText = @"
 TopLevel  
@@ -9053,7 +9053,7 @@ Dialogror ";
         tv.IsSelecting = false;
         tv.CursorPosition = new (2, 4);
         tv.Paste ();
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         expectedText = @"
 TopLevel  

+ 12 - 12
UnitTests/Views/ToplevelTests.cs

@@ -456,7 +456,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                                                        ScreenPosition = new (2, 2), Flags = MouseFlags.Button1Pressed
                                                                                                       | MouseFlags.ReportMousePosition
                                                                    });
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.Equal (Application.Top.Border, Application.MouseGrabView);
                                          Assert.Equal (new (1, 2, 10, 3), Application.Top.Frame);
@@ -478,7 +478,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                                                    {
                                                                        ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                                                    });
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
                                          Assert.Equal (new (1, 1, 10, 3), Application.Top.Frame);
@@ -497,7 +497,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
 
                                          // Ungrab the mouse
                                          Application.RaiseMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Released });
-                                         Application.Refresh ();
+                                         Application.LayoutAndDrawToplevels ();
 
                                          Assert.Null (Application.MouseGrabView);
                                      }
@@ -752,7 +752,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
         top.SetNeedsLayout ();
         top.LayoutSubviews ();
         Assert.Equal (new (6, 6, 191, 91), win.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Application.RaiseMouseEvent (
                                   new ()
@@ -763,7 +763,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
         top.SetNeedsLayout ();
         top.LayoutSubviews ();
         Assert.Equal (new (2, 2, 195, 95), win.Frame);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.Button1Released });
 
@@ -784,7 +784,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
         RunState rsTop = Application.Begin (top);
         ((FakeDriver)Application.Driver!).SetBufferSize (40, 10);
         RunState rsWindow = Application.Begin (window);
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 40, 10), top.Frame);
         Assert.Equal (new (0, 0, 20, 3), window.Frame);
 
@@ -800,7 +800,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                       ScreenPosition = new (-11, -4), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                   });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 40, 10), top.Frame);
         Assert.Equal (new (-11, -4, 20, 3), window.Frame);
 
@@ -813,7 +813,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                       ScreenPosition = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                   });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 20, 3), top.Frame);
         Assert.Equal (new (-1, -1, 20, 3), window.Frame);
 
@@ -826,7 +826,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                       ScreenPosition = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                   });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 19, 2), top.Frame);
         Assert.Equal (new (-1, -1, 20, 3), window.Frame);
 
@@ -836,7 +836,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                       ScreenPosition = new (18, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                   });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 19, 2), top.Frame);
         Assert.Equal (new (18, 1, 20, 3), window.Frame);
 
@@ -847,7 +847,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
                                       ScreenPosition = new (19, 2), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
                                   });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
         Assert.Equal (new (0, 0, 19, 2), top.Frame);
         Assert.Equal (new (19, 2, 20, 3), window.Frame);
         //TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
@@ -986,7 +986,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
 
         Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 2), Flags = MouseFlags.Button1Clicked });
 
-        Application.Refresh ();
+        Application.LayoutAndDrawToplevels ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @$"

+ 1 - 1
UnitTests/Views/ViewDisposalTest.cs

@@ -60,7 +60,7 @@ public class ViewDisposalTest (ITestOutputHelper output)
         // make sure the application is doing to the views whatever its supposed to do to the views
         for (var i = 0; i < 100; i++)
         {
-            Application.Refresh ();
+            Application.LayoutAndDrawToplevels ();
         }
 
         top.Remove (container);