2
0
Эх сурвалжийг харах

Fixes #979. Force call LayoutSubviews to perform layout.

BDisp 4 жил өмнө
parent
commit
550392cab6

+ 3 - 6
Terminal.Gui/Views/TextField.cs

@@ -46,21 +46,18 @@ namespace Terminal.Gui {
 		/// Initializes a new instance of the <see cref="TextField"/> class using <see cref="LayoutStyle.Computed"/> positioning.
 		/// </summary>
 		/// <param name="text">Initial text contents.</param>
-		public TextField (string text) : this (ustring.Make (text))
-		{
-			Initialize ();
-		}
+		public TextField (string text) : this (ustring.Make (text)) { }
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="TextField"/> class using <see cref="LayoutStyle.Computed"/> positioning.
 		/// </summary>
-		public TextField () : this (string.Empty) { Initialize (); }
+		public TextField () : this (string.Empty) { }
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="TextField"/> class using <see cref="LayoutStyle.Computed"/> positioning.
 		/// </summary>
 		/// <param name="text">Initial text contents.</param>
-		public TextField (ustring text)
+		public TextField (ustring text) : base (text)
 		{
 			Initialize (text, 0);
 			Width = text.RuneCount + 1;

+ 8 - 6
UICatalog/Scenarios/MessageBoxes.cs

@@ -124,19 +124,21 @@ namespace UICatalog {
 			};
 			frame.Add (styleRadioGroup);
 
-			frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit) 
-				+ Dim.Height(numButtonsEdit) + Dim.Height (styleRadioGroup) + 2;
+			frame.LayoutSubviews ();
+
+			frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit)
+				+ Dim.Height (numButtonsEdit) + Dim.Height (styleRadioGroup) + 2;
 
 			label = new Label ("Button Pressed:") {
 				X = Pos.Center (),
-				Y = Pos.Bottom (frame) + 2,
+				Y = Pos.Bottom (frame) + 4,
 				Height = 1,
 				TextAlignment = Terminal.Gui.TextAlignment.Right,
 			};
 			Win.Add (label);
-			var buttonPressedLabel = new Label ("") {
+			var buttonPressedLabel = new Label (" ") {
 				X = Pos.Center (),
-				Y = Pos.Bottom (frame) + 4,
+				Y = Pos.Bottom (frame) + 5,
 				Width = 25,
 				Height = 1,
 				ColorScheme = Colors.Error,
@@ -146,7 +148,7 @@ namespace UICatalog {
 
 			var showMessageBoxButton = new Button ("Show MessageBox") {
 				X = Pos.Center(),
-				Y = Pos.Bottom (frame) + 2			,
+				Y = Pos.Bottom (frame) + 2,
 				IsDefault = true,
 			};
 			showMessageBoxButton.Clicked += () => {

+ 57 - 0
UnitTests/ViewTests.cs

@@ -1020,5 +1020,62 @@ namespace Terminal.Gui {
 			Application.Shutdown ();
 		}
 
+		[Fact]
+		public void View_Difference_Between_An_Object_Initializer_And_A_Constructor ()
+		{
+			// Object Initializer
+			var view = new View () {
+				X = 1,
+				Y = 2,
+				Width = 3,
+				Height = 4
+			};
+			Assert.Equal (1, view.X);
+			Assert.Equal (2, view.Y);
+			Assert.Equal (3, view.Width);
+			Assert.Equal (4, view.Height);
+			Assert.True (view.Frame.IsEmpty);
+			Assert.True (view.Bounds.IsEmpty);
+
+			view.LayoutSubviews ();
+
+			Assert.Equal (1, view.X);
+			Assert.Equal (2, view.Y);
+			Assert.Equal (3, view.Width);
+			Assert.Equal (4, view.Height);
+			Assert.False (view.Frame.IsEmpty);
+			Assert.False (view.Bounds.IsEmpty);
+
+			// Default Constructor
+			view = new View ();
+			Assert.Equal (0, view.X);
+			Assert.Equal (0, view.Y);
+			Assert.Equal (0, view.Width);
+			Assert.Equal (0, view.Height);
+			Assert.True (view.Frame.IsEmpty);
+			Assert.True (view.Bounds.IsEmpty);
+
+			// Constructor
+			view = new View (1, 2, "");
+			Assert.Null (view.X);
+			Assert.Null (view.Y);
+			Assert.Null (view.Width);
+			Assert.Null (view.Height);
+			Assert.False (view.Frame.IsEmpty);
+			Assert.True (view.Bounds.IsEmpty);
+
+			// Default Constructor and post assignment equivalent to Object Initializer
+			view = new View ();
+			view.X = 1;
+			view.Y = 2;
+			view.Width = 3;
+			view.Height = 4;
+			Assert.Equal (1, view.X);
+			Assert.Equal (2, view.Y);
+			Assert.Equal (3, view.Width);
+			Assert.Equal (4, view.Height);
+			Assert.True (view.Frame.IsEmpty);
+			Assert.True (view.Bounds.IsEmpty);
+		}
 	}
 }