diff --git a/Terminal.Gui/App/ApplicationImpl.Screen.cs b/Terminal.Gui/App/ApplicationImpl.Screen.cs index 978f8214e..ac69266ce 100644 --- a/Terminal.Gui/App/ApplicationImpl.Screen.cs +++ b/Terminal.Gui/App/ApplicationImpl.Screen.cs @@ -1,4 +1,3 @@ - namespace Terminal.Gui.App; internal partial class ApplicationImpl @@ -150,17 +149,6 @@ internal partial class ApplicationImpl /// public void LayoutAndDraw (bool forceRedraw = false) { - List tops = [.. SessionStack!.Select(r => r.Runnable! as View)!]; - - if (Popover?.GetActivePopover () as View is { Visible: true } visiblePopover) - { - visiblePopover.SetNeedsDraw (); - visiblePopover.SetNeedsLayout (); - tops.Insert (0, visiblePopover); - } - - bool neededLayout = View.Layout (tops.ToArray ().Reverse ()!, Screen.Size); - if (ClearScreenNextIteration) { forceRedraw = true; @@ -172,13 +160,28 @@ internal partial class ApplicationImpl Driver?.ClearContents (); } - if (Driver is { }) + List views = [.. SessionStack!.Select (r => r.Runnable! as View)!]; + + if (Popover?.GetActivePopover () as View is { Visible: true } visiblePopover) + { + visiblePopover.SetNeedsDraw (); + visiblePopover.SetNeedsLayout (); + views.Insert (0, visiblePopover); + } + + bool neededLayout = View.Layout (views.ToArray ().Reverse ()!, Screen.Size); + + bool needsDraw = forceRedraw || views.Any (v => v is { NeedsDraw: true } or { SubViewNeedsDraw: true }); + + if (Driver is { } && (neededLayout || needsDraw)) { Logging.Redraws.Add (1); + Logging.Trace ("LayoutAndDraw"); Driver.Clip = new (Screen); - View.Draw (views: tops!, neededLayout || forceRedraw); + View.Draw (views: views.ToArray ().Cast ()!, neededLayout || forceRedraw); + Driver.Clip = new (Screen); Driver?.Refresh (); } diff --git a/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs b/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs index 52709ed7a..38652c38c 100644 --- a/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs +++ b/Terminal.Gui/App/MainLoop/ApplicationMainLoop.cs @@ -137,7 +137,7 @@ public class ApplicationMainLoop : IApplicationMainLoop : IApplicationMainLoop : IApplicationMainLoop