Browse Source

renamed scenario

Tig Kindel 1 year ago
parent
commit
b22c1e3121

+ 1 - 1
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -1077,7 +1077,7 @@ internal class WindowsDriver : ConsoleDriver {
 				inputEvent.KeyEvent = FromVKPacketToKeyEventRecord (inputEvent.KeyEvent);
 			}
 			var keyInfo = ToConsoleKeyInfoEx (inputEvent.KeyEvent);
-			Debug.WriteLine ($"event: {inputEvent.ToString ()} {keyInfo.ToString (keyInfo)}");
+			//Debug.WriteLine ($"event: {inputEvent.ToString ()} {keyInfo.ToString (keyInfo)}");
 
 
 			var map = MapKey (keyInfo);

+ 1 - 0
Terminal.Gui/View/View.cs

@@ -280,6 +280,7 @@ namespace Terminal.Gui {
 				_oldCanFocus = CanFocus;
 				_oldTabIndex = _tabIndex;
 
+				// BUGBUG: These should move to EndInit as they access Bounds causing debug spew.
 				UpdateTextDirection (TextDirection);
 				UpdateTextFormatterText ();
 				SetHotKey ();

+ 20 - 9
Terminal.Gui/View/ViewLayout.cs

@@ -420,7 +420,7 @@ namespace Terminal.Gui {
 		/// <exception cref="InvalidOperationException"></exception>
 		void CheckDimAuto ()
 		{
-			if (!ValidatePosDim || (Width is not Dim.DimAuto && Height is not Dim.DimAuto)) {
+			if (!ValidatePosDim || !IsInitialized || (Width is not Dim.DimAuto && Height is not Dim.DimAuto)) {
 				return;
 			}
 
@@ -455,10 +455,14 @@ namespace Terminal.Gui {
 
 			// Verify none of the subviews are using Dim objects that depend on the SuperView's dimensions.
 			foreach (var view in Subviews) {
-				ThrowInvalid (view, view.Width, nameof (view.Width));
-				ThrowInvalid (view, view.Height, nameof (view.Height));
-				ThrowInvalid (view, view.X, nameof (view.X));
-				ThrowInvalid (view, view.Y, nameof (view.Y));
+				if (Width is Dim.DimAuto { _min: null }) {
+					ThrowInvalid (view, view.Width, nameof (view.Width));
+					ThrowInvalid (view, view.X, nameof (view.X));
+				}
+				if (Height is Dim.DimAuto { _min: null }) {
+					ThrowInvalid (view, view.Height, nameof (view.Height));
+					ThrowInvalid (view, view.Y, nameof (view.Y));
+				}
 			}
 		}
 
@@ -582,7 +586,9 @@ namespace Terminal.Gui {
 				SetNeedsDisplay ();
 			}
 
-			if (LayoutStyle == LayoutStyle.Computed && (SuperView?.Height is Dim.DimAuto || (SuperView?.Width is Dim.DimAuto))) {
+			if (IsInitialized
+			&& SuperView != null
+			&& LayoutStyle == LayoutStyle.Computed && (SuperView?.Height is Dim.DimAuto || (SuperView?.Width is Dim.DimAuto))) {
 				// DimAuto is in play, force a layout.
 				SuperView.LayoutSubviews ();
 			}
@@ -793,10 +799,10 @@ namespace Terminal.Gui {
 					if (width) {
 						var furthestRight = Subviews.Count == 0 ? 0 : Subviews.Max (v => v.Frame.X + v.Frame.Width);
 						//newDimension = furthestRight + thickness.Left + thickness.Right;
-						newDimension = int.Max (furthestRight + thickness.Left + thickness.Right, auto._min?.Anchor (0) ?? 0);
+						newDimension = int.Max (furthestRight + thickness.Left + thickness.Right, auto._min?.Anchor (SuperView?.Bounds.Width ?? 0) ?? 0);
 					} else {
 						var furthestBottom = Subviews.Count == 0 ? 0 : Subviews.Max (v => v.Frame.Y + v.Frame.Height);
-						newDimension = int.Max (furthestBottom + thickness.Top + thickness.Bottom, auto._min?.Anchor (0) ?? 0);
+						newDimension = int.Max (furthestBottom + thickness.Top + thickness.Bottom, auto._min?.Anchor (SuperView?.Bounds.Height ?? 0) ?? 0);
 						//newDimension = furthestBottom + thickness.Top + thickness.Bottom;
 					}
 					break;
@@ -906,7 +912,8 @@ namespace Terminal.Gui {
 
 		internal void CollectAll (View from, ref HashSet<View> nNodes, ref HashSet<(View, View)> nEdges)
 		{
-			foreach (var v in from.InternalSubviews) {
+			// BUGBUG: This should really only work on initialized subviews
+			foreach (var v in from.InternalSubviews/*.Where(v => v.IsInitialized)*/) {
 				nNodes.Add (v);
 				if (v._layoutStyle != LayoutStyle.Computed) {
 					continue;
@@ -1034,6 +1041,10 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public virtual void LayoutSubviews ()
 		{
+			if (!IsInitialized) {
+				Debug.WriteLine ($"WARNING: LayoutSubviews called before view has been initialized. This is likely a bug in {this}");
+			}
+
 			if (!LayoutNeeded) {
 				return;
 			}

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

@@ -59,7 +59,7 @@ public class Dialog : Window {
 	{
 		X = Pos.Center ();
 		Y = Pos.Center ();
-		//ValidatePosDim = true;
+		ValidatePosDim = true;
 
 		Width = Dim.Percent (85);
 		Height = Dim.Percent (85);

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

@@ -178,7 +178,7 @@ public class RadioGroup : View {
 					AddKeyBindingsForHotKey (KeyCode.Null, hotKey);
 				}
 			}
-			if (prevCount != _radioLabels.Count) {
+			if (IsInitialized && prevCount != _radioLabels.Count) {
 				SetWidthHeight (_radioLabels);
 			}
 			SelectedItem = 0;

+ 4 - 6
UICatalog/Scenarios/DimAutoSize.cs → UICatalog/Scenarios/DimAutoDemo.cs

@@ -2,9 +2,9 @@ using Terminal.Gui;
 
 namespace UICatalog.Scenarios;
 
-[ScenarioMetadata ("DimAutoSize", "Demonstrates Dim.AutoSize")]
+[ScenarioMetadata ("DimAuto", "Demonstrates Dim.Auto")]
 [ScenarioCategory ("Layout")]
-public class DimAutoSize : Scenario {
+public class DimAutoDemo : Scenario {
 	public override void Init ()
 	{
 		Application.Init ();
@@ -30,7 +30,7 @@ public class DimAutoSize : Scenario {
 
 		var resetButton = new Button () {
 			Text = "P_ut Button Back",
-			X = 0,
+			X = Pos.Center (),
 			Y = Pos.Bottom(label)
 		};
 
@@ -45,15 +45,13 @@ public class DimAutoSize : Scenario {
 
 		resetButton.Clicked += (s, e) => {
 			movingButton.Y = Pos.Bottom (resetButton);
-			// BUGBUG: Should this be required? I don't thinks so.
-			//movingButton.SuperView.LayoutSubviews ();
 		};
 
 		var view = new FrameView () {
 			Title = "Type in the TextField to make View grow.",
 			X = 3,
 			Y = 3,
-			Width = Dim.Auto (),
+			Width = Dim.Auto (min: Dim.Percent(50)),
 			Height = Dim.Auto (min: 10)
 		};
 		view.ValidatePosDim = true;

+ 3 - 0
UnitTests/View/Layout/DimAutoTests.cs

@@ -187,6 +187,9 @@ public class DimAutoTests {
 			Height = 10
 		};
 
+		superView.BeginInit ();
+		superView.EndInit ();
+
 		Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
 
 		subView.Width = 10;

+ 9 - 0
UnitTests/View/Layout/DimTests.cs

@@ -579,6 +579,8 @@ public class DimTests {
 		f.Add (v1, v2);
 		w.Add (f);
 		t.Add (w);
+		t.BeginInit ();
+		t.EndInit ();
 
 		// BUGBUG: v2 - f references t here; t is f's super-superview. This is supported!
 		// BUGBUG: v2 - f references v2 here; v2 is f's subview. This is not supported!
@@ -622,6 +624,8 @@ public class DimTests {
 		f.Add (v1, v2);
 		w.Add (f);
 		t.Add (w);
+		t.BeginInit ();
+		t.EndInit ();
 
 		f.Width = Dim.Width (t) - Dim.Width (w) + 4; // 80 - 74 = 6
 		f.Height = Dim.Height (t) - Dim.Height (w) + 4; // 25 - 19 = 6
@@ -670,6 +674,9 @@ public class DimTests {
 		sub.Width = Dim.Fill () - Dim.Width (v2);
 		sub.Height = Dim.Fill () - Dim.Height (v2);
 
+		t.BeginInit ();
+		t.EndInit ();
+		
 		Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
 		t.Dispose ();
 		v2.Dispose ();
@@ -1316,6 +1323,8 @@ public class DimTests {
 
 		container.Add (label);
 		Application.Top.Add (container);
+		Application.Top.BeginInit ();
+		Application.Top.EndInit ();
 		Application.Top.LayoutSubviews ();
 
 		Assert.Equal (100, container.Frame.Width);