Fixed bugs

This commit is contained in:
Tig
2024-10-24 15:26:13 -06:00
parent bc12c4bdde
commit 76895f1dd3
4 changed files with 25 additions and 26 deletions

View File

@@ -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;
/// <summary>
/// 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 ();
}

View File

@@ -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);
}

View File

@@ -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;
})));

View File

@@ -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;
}