Browse Source

Fixed more minor issues in tests

Tig Kindel 1 year ago
parent
commit
454d7277c8

+ 11 - 8
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -35,8 +35,7 @@ public partial class View {
 	Rect _frame;
 	Rect _frame;
 
 
 	/// <summary>
 	/// <summary>
-	/// Gets or sets location and size of the view. The frame is relative to the <see cref="SuperView"/>'s <see cref="Bounds"/>
-	/// .
+	/// Gets or sets location and size of the view. The frame is relative to the <see cref="SuperView"/>'s <see cref="Bounds"/>.
 	/// </summary>
 	/// </summary>
 	/// <value>
 	/// <value>
 	/// The rectangle describing the location and size of the view, in coordinates relative to the
 	/// The rectangle describing the location and size of the view, in coordinates relative to the
@@ -68,7 +67,9 @@ public partial class View {
 			_y = _frame.Y;
 			_y = _frame.Y;
 			_width = _frame.Width;
 			_width = _frame.Width;
 			_height = _frame.Height;
 			_height = _frame.Height;
-			if (IsInitialized || LayoutStyle == LayoutStyle.Absolute) {
+			
+			// TODO: Figure out if the below can be optimized.
+			if (IsInitialized /*|| LayoutStyle == LayoutStyle.Absolute*/) {
 				LayoutFrames ();
 				LayoutFrames ();
 				TextFormatter.Size = GetTextFormatterSizeNeededForTextAndHotKey ();
 				TextFormatter.Size = GetTextFormatterSizeNeededForTextAndHotKey ();
 				SetNeedsLayout ();
 				SetNeedsLayout ();
@@ -591,12 +592,11 @@ public partial class View {
 	/// </remarks>
 	/// </remarks>
 	protected virtual void OnResizeNeeded ()
 	protected virtual void OnResizeNeeded ()
 	{
 	{
-		//var actX = _x is Pos.PosAbsolute ? _x.Anchor (0) : _frame.X;
-		//var actY = _y is Pos.PosAbsolute ? _y.Anchor (0) : _frame.Y;
-
 		//// TODO: Determine if this API should change Frame as it does.
 		//// TODO: Determine if this API should change Frame as it does.
 		//// TODO: Is it correct behavior? Shouldn't the Frame be changed when SetRelativeLayout
 		//// TODO: Is it correct behavior? Shouldn't the Frame be changed when SetRelativeLayout
 		//// TODO: is eventually called because SetNeedsLayout get set?
 		//// TODO: is eventually called because SetNeedsLayout get set?
+		//var actX = _x is Pos.PosAbsolute ? _x.Anchor (0) : _frame.X;
+		//var actY = _y is Pos.PosAbsolute ? _y.Anchor (0) : _frame.Y;
 		//if (AutoSize) {
 		//if (AutoSize) {
 		//	//if (TextAlignment == TextAlignment.Justified) {
 		//	//if (TextAlignment == TextAlignment.Justified) {
 		//	//	throw new InvalidOperationException ("TextAlignment.Justified cannot be used with AutoSize");
 		//	//	throw new InvalidOperationException ("TextAlignment.Justified cannot be used with AutoSize");
@@ -613,9 +613,12 @@ public partial class View {
 		//	//// This is needed for DimAbsolute values by setting the frame before LayoutSubViews.
 		//	//// This is needed for DimAbsolute values by setting the frame before LayoutSubViews.
 		//	_frame = new Rect (new Point (actX, actY), new Size (w, h)); // Set frame, not Frame!
 		//	_frame = new Rect (new Point (actX, actY), new Size (w, h)); // Set frame, not Frame!
 		//}
 		//}
-		// BUGBUG: I think these calls are redundant or should be moved into just the AutoSize case
 
 
-		SetRelativeLayout (SuperView?.Bounds ?? Application.Top?.Bounds ?? Application.Driver?.Bounds ?? new Rect (0, 0, int.MaxValue, int.MaxValue));
+		// First try SuperView.Bounds, then Application.Current.Bounds, then Application.Top, then Driver
+		// Finally, if none of those are valid, use int.MaxValue (for Unit tests).
+		SetRelativeLayout (SuperView?.Bounds ?? Application.Current?.Bounds ?? Application.Top?.Bounds ?? Application.Driver?.Bounds ?? new Rect (0, 0, int.MaxValue, int.MaxValue));
+
+		// TODO: Determine what, if any of the below is actually needed here.
 		if (IsInitialized/* || LayoutStyle == LayoutStyle.Absolute*/) {
 		if (IsInitialized/* || LayoutStyle == LayoutStyle.Absolute*/) {
 			SetFrameToFitText ();
 			SetFrameToFitText ();
 			LayoutFrames ();
 			LayoutFrames ();

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

@@ -495,11 +495,6 @@ public partial class View : Responder, ISupportInitializeNotification {
 		Padding?.Dispose ();
 		Padding?.Dispose ();
 		Padding = null;
 		Padding = null;
 
 
-		//_height = null;
-		//_width = null;
-		//_x = null;
-		//_y = null;
-
 		for (int i = InternalSubviews.Count - 1; i >= 0; i--) {
 		for (int i = InternalSubviews.Count - 1; i >= 0; i--) {
 			var subview = InternalSubviews [i];
 			var subview = InternalSubviews [i];
 			Remove (subview);
 			Remove (subview);

+ 0 - 5
Terminal.Gui/View/ViewSubViews.cs

@@ -120,11 +120,6 @@ namespace Terminal.Gui {
 			var view = e.Child;
 			var view = e.Child;
 			view.IsAdded = true;
 			view.IsAdded = true;
 			view.OnResizeNeeded ();
 			view.OnResizeNeeded ();
-			//view._x ??= view._frame.X;
-			//view._y ??= view._frame.Y;
-			//view._width ??= view._frame.Width;
-			//view._height ??= view._frame.Height;
-
 			view.Added?.Invoke (this, e);
 			view.Added?.Invoke (this, e);
 		}
 		}
 
 

+ 3 - 15
Terminal.Gui/Views/HexView.cs

@@ -185,21 +185,6 @@ public partial class HexView : View {
 		}
 		}
 	}
 	}
 
 
-	//// BUGBUG: This should be Bounds. Or, even better use View.LayoutComplete event
-	///// <inheritdoc/>
-	//public override Rect Frame {
-	//	get => base.Frame;
-	//	set {
-	//		base.Frame = value;
-
-	//		// Small buffers will just show the position, with the bsize field value (4 bytes)
-	//		bytesPerLine = bsize;
-	//		if (value.Width - displayWidth > 17) {
-	//			bytesPerLine = bsize * ((value.Width - displayWidth) / 18);
-	//		}
-	//	}
-	//}
-
 	//
 	//
 	// This is used to support editing of the buffer on a peer List<>, 
 	// This is used to support editing of the buffer on a peer List<>, 
 	// the offset corresponds to an offset relative to DisplayStart, and
 	// the offset corresponds to an offset relative to DisplayStart, and
@@ -614,6 +599,9 @@ public partial class HexView : View {
 	/// </summary>
 	/// </summary>
 	public Point CursorPosition {
 	public Point CursorPosition {
 		get {
 		get {
+			if (!IsInitialized) {
+				return new Point (0, 0);
+			}
 			int delta = (int)position;
 			int delta = (int)position;
 			int line = delta / bytesPerLine + 1;
 			int line = delta / bytesPerLine + 1;
 			int item = delta % bytesPerLine + 1;
 			int item = delta % bytesPerLine + 1;

+ 3 - 1
UnitTests/Dialogs/DialogTests.cs

@@ -920,8 +920,10 @@ namespace Terminal.Gui.DialogTests {
 		//			Application.Shutdown ();
 		//			Application.Shutdown ();
 		//		}
 		//		}
 
 
+		// TODO: This is not really a Dialog test, but a ViewLayout test (Width = Dim.Fill (1) - Dim.Function (Btn_Width))
+		// TODO: Move (and simplify)
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
-		public void Dialog_In_Window_With_TexxtField_And_Button_AnchorEnd ()
+		public void Dialog_In_Window_With_TextField_And_Button_AnchorEnd ()
 		{
 		{
 			((FakeDriver)Application.Driver).SetBufferSize (20, 5);
 			((FakeDriver)Application.Driver).SetBufferSize (20, 5);
 
 

+ 1 - 1
UnitTests/View/Text/AutoSizeTextTests.cs

@@ -2058,7 +2058,7 @@ Y
 		Assert.Equal (2,             label.Frame.Height);
 		Assert.Equal (2,             label.Frame.Height);
 
 
 		Assert.False (label.AutoSize);
 		Assert.False (label.AutoSize);
-		Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
+		Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
 		Application.End (rs);
 		Application.End (rs);
 	}
 	}