From 76895f1dd369ea4ee55f67e2027c44609c3dee4e Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 24 Oct 2024 15:26:13 -0600 Subject: [PATCH] Fixed bugs --- Terminal.Gui/View/View.Layout.cs | 21 +++++++++++---------- Terminal.Gui/View/View.cs | 7 +++---- UICatalog/Scenarios/AllViewsTester.cs | 4 ++-- UnitTests/UICatalog/ScenarioTests.cs | 19 +++++++++---------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Terminal.Gui/View/View.Layout.cs b/Terminal.Gui/View/View.Layout.cs index 7889e9e03..c2ca2dc83 100644 --- a/Terminal.Gui/View/View.Layout.cs +++ b/Terminal.Gui/View/View.Layout.cs @@ -159,7 +159,6 @@ public partial class View // Layout APIs // helper for X, Y, Width, Height setters to ensure consistency private void PosDimSet () { - _needsLayout = false; SetNeedsLayout (); if (_x is PosAbsolute && _y is PosAbsolute && _width is DimAbsolute && _height is DimAbsolute) @@ -656,7 +655,7 @@ public partial class View // Layout APIs #region NeedsLayout // We expose no setter for this to ensure that the ONLY place it's changed is in SetNeedsLayout - private bool _needsLayout = false; + private bool _needsLayout = true; /// /// Indicates the View's Frame or the layout of the View's subviews (including Adornments) have @@ -683,12 +682,6 @@ public partial class View // Layout APIs public void SetNeedsLayout () { - if (NeedsLayout) - { - // Prevent infinite recursion - return; - } - _needsLayout = true; if (Margin is { Subviews.Count: > 0 }) @@ -735,9 +728,17 @@ public partial class View // Layout APIs TextFormatter.NeedsFormat = true; - SuperView?.SetNeedsLayout (); + if (SuperView is { NeedsLayout: false }) + { + SuperView?.SetNeedsLayout (); + } - if (this is Adornment adornment) + if (this is not Adornment adornment) + { + return; + } + + if (adornment.Parent is { NeedsLayout: false }) { adornment.Parent?.SetNeedsLayout (); } diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 92c5da95f..a4403cfdd 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -231,8 +231,6 @@ public partial class View : Responder, ISupportInitializeNotification UpdateTextDirection (TextDirection); UpdateTextFormatterText (); - SetNeedsLayout (); - if (_subviews is { }) { foreach (View view in _subviews) @@ -244,8 +242,9 @@ public partial class View : Responder, ISupportInitializeNotification } } - // TODO: Figure out how to move this out of here and just depend on IsLayoutNeeded in Mainloop - Layout (); + // TODO: Figure out how to move this out of here and just depend on LayoutNeeded in Mainloop + Layout (); // the EventLog in AllViewsTester fails to layout correctly if this is not here (convoluted Dim.Fill(Func)). + SetNeedsLayout (); Initialized?.Invoke (this, EventArgs.Empty); } diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index d0c978612..8c94cbae0 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -186,8 +186,8 @@ public class AllViewsTester : Scenario // We have two choices: // 1) Call Layout explicitly // 2) Throw LayoutException so Layout tries again - _eventLog.Layout (); - // new LayoutException ("_eventLog"); + //_eventLog.Layout (); + throw new LayoutException ("_eventLog"); } return _eventLog.Frame.Width; }))); diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 082cd7879..7305d51e3 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -167,6 +167,8 @@ public class ScenarioTests : TestsAllViews int updatedCount = 0; int drawCompleteCount = 0; + int laidOutCount = 0; + _output.WriteLine ($"Running Scenario '{scenarioType}'"); var scenario = (Scenario)Activator.CreateInstance (scenarioType); @@ -202,6 +204,7 @@ public class ScenarioTests : TestsAllViews _output.WriteLine ($" called Driver.Refresh {refreshedCount} times."); _output.WriteLine ($" which updated the screen {updatedCount} times."); _output.WriteLine ($" called View.Draw {drawCompleteCount} times."); + _output.WriteLine ($" called View.LayoutComplete {laidOutCount} times."); // Restore the configuration locations ConfigurationManager.Locations = savedConfigLocations; @@ -250,8 +253,8 @@ public class ScenarioTests : TestsAllViews if (iterationCount > maxIterations) { // Press QuitKey - _output.WriteLine ($"Attempting to quit with {Application.QuitKey}"); - Application.RaiseKeyDownEvent (Application.QuitKey); + _output.WriteLine ($"Attempting to quit scenario with RequestStop"); + Application.RequestStop (); } } @@ -260,16 +263,17 @@ public class ScenarioTests : TestsAllViews { // Get a list of all subviews under Application.Top (and their subviews, etc.) // and subscribe to their DrawComplete event - void SubscribeToDrawComplete (View view) + void SubscribeAllSubviews (View view) { view.DrawComplete += (s, a) => drawCompleteCount++; + view.SubviewsLaidOut += (s, a) => laidOutCount++; foreach (View subview in view.Subviews) { - SubscribeToDrawComplete (subview); + SubscribeAllSubviews (subview); } } - SubscribeToDrawComplete (Application.Top); + SubscribeAllSubviews (Application.Top); } // If the scenario doesn't close within the abort time, this will force it to quit @@ -287,11 +291,6 @@ public class ScenarioTests : TestsAllViews $"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms and {iterationCount} iterations. Force quit."); Application.RequestStop (); - //// Restore the configuration locations - //ConfigurationManager.Locations = savedConfigLocations; - //ConfigurationManager.Reset (); - - //Application.ResetState (true); return false; }