Skip to content

Commit af9c6d7

Browse files
authored
Change LayoutAndDraw in v2 applications to simply set draw/layout flags instead of force a buffer refresh (#3943)
1 parent 79cd4e9 commit af9c6d7

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

Terminal.Gui/Application/Application.Run.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ public static void Run (Toplevel view, Func<Exception, bool>? errorHandler = nul
411411
/// </summary>
412412
/// <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>
413413
public static void LayoutAndDraw (bool forceDraw = false)
414+
{
415+
ApplicationImpl.Instance.LayoutAndDraw (forceDraw);
416+
}
417+
418+
internal static void LayoutAndDrawImpl (bool forceDraw = false)
414419
{
415420
bool neededLayout = View.Layout (TopLevels.Reverse (), Screen.Size);
416421

Terminal.Gui/Application/ApplicationImpl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,10 @@ public virtual bool RemoveTimeout (object token)
294294
{
295295
return Application.MainLoop?.TimedEvents.RemoveTimeout (token) ?? false;
296296
}
297+
298+
/// <inheritdoc />
299+
public virtual void LayoutAndDraw (bool forceDraw)
300+
{
301+
Application.LayoutAndDrawImpl (forceDraw);
302+
}
297303
}

Terminal.Gui/Application/IApplication.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,11 @@ public T Run<T> (Func<Exception, bool>? errorHandler = null, IConsoleDriver? dri
182182
/// <see langword="false"/>
183183
/// if the timeout is not found.</returns>
184184
bool RemoveTimeout (object token);
185+
186+
/// <summary>
187+
/// Causes any Toplevels that need layout to be laid out. Then draws any Toplevels that need display. Only Views that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out.
188+
/// Only Views that need to be drawn (see <see cref="View.NeedsDraw"/>) will be drawn.
189+
/// </summary>
190+
/// <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>
191+
void LayoutAndDraw (bool forceDraw);
185192
}

Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,12 @@ public override void Invoke (Action action)
232232

233233
/// <inheritdoc/>
234234
public override bool RemoveTimeout (object token) { return _timedEvents.RemoveTimeout (token); }
235+
236+
/// <inheritdoc />
237+
public override void LayoutAndDraw (bool forceDraw)
238+
{
239+
// No more ad-hoc drawing, you must wait for iteration to do it
240+
Application.Top?.SetNeedsDraw();
241+
Application.Top?.SetNeedsLayout ();
242+
}
235243
}

Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ internal void IterationImpl ()
130130
{
131131
Logging.Redraws.Add (1);
132132

133-
// TODO: Test only
134-
Application.LayoutAndDraw (true);
133+
Application.LayoutAndDrawImpl (true);
135134

136135
Out.Write (OutputBuffer);
137136

0 commit comments

Comments
 (0)