Browse Source

Fixed Dialog tests and Text tess

Tigger Kindel 2 years ago
parent
commit
689b7523f1

+ 10 - 10
Terminal.Gui/Core/Frame.cs

@@ -105,7 +105,7 @@ namespace Terminal.Gui {
 
 			// TODO: v2 - this will eventually be two controls: "BorderView" and "Label" (for the title)
 
-			if (Id == "BorderFrame" && Thickness.Top > 0 && !ustring.IsNullOrEmpty (Parent?.Title)) {
+			if (Id == "BorderFrame" && Thickness.Top > 0 && Frame.Width > 1 && !ustring.IsNullOrEmpty (Parent?.Title)) {
 				var prevAttr = Driver.GetAttribute ();
 				Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ());
 				Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0);
@@ -114,15 +114,15 @@ namespace Terminal.Gui {
 
 			if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) {
 				var lc = new LineCanvas ();
-				if (Thickness.Top > 0) {
-					// ╔╡ Title ╞═════╗
-					// ╔╡  ╞═════╗
-					if (Frame.Width < 6 || ustring.IsNullOrEmpty (Parent?.Title)) {
+				if (Thickness.Top > 0 && Frame.Width > 1 && Frame.Height > 1) {
+					// ╔╡Title╞═════╗
+					// ╔╡╞═════╗
+					if (Frame.Width < 4 || ustring.IsNullOrEmpty (Parent?.Title)) {
 						// ╔╡╞╗ should be ╔══╗
 						lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
 					} else {
-						var titleWidth = Math.Min (Parent.Title.ConsoleWidth, Frame.Width - 6);
-						// ╔╡ Title ╞═════╗
+						var titleWidth = Math.Min (Parent.Title.ConsoleWidth, Frame.Width - 4);
+						// ╔╡Title╞═════╗
 						// Add a short horiz line for ╔╡
 						lc.AddLine (screenBounds.Location, 1, Orientation.Horizontal, BorderStyle);
 						// Add a short vert line for ╔╡
@@ -133,13 +133,13 @@ namespace Terminal.Gui {
 						lc.AddLine (new Point (screenBounds.X + 1 + (titleWidth + 1), screenBounds.Location.Y), Frame.Width - (titleWidth + 3), Orientation.Horizontal, BorderStyle);
 					}
 				}
-				if (Thickness.Left > 0) {
+				if (Thickness.Left > 0 && (Frame.Height > 1 || Thickness.Top == 0)) {
 					lc.AddLine (screenBounds.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle);
 				}
-				if (Thickness.Bottom > 0) {
+				if (Thickness.Bottom > 0 && Frame.Width > 1) {
 					lc.AddLine (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1), screenBounds.Width - 1, Orientation.Horizontal, BorderStyle);
 				}
-				if (Thickness.Right > 0) {
+				if (Thickness.Right > 0 && (Frame.Height > 1 || Thickness.Top == 0)) {
 					lc.AddLine (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y), screenBounds.Height - 1, Orientation.Vertical, BorderStyle);
 				}
 				foreach (var p in lc.GenerateImage (screenBounds)) {

+ 3 - 3
Terminal.Gui/Core/View.cs

@@ -544,7 +544,7 @@ namespace Terminal.Gui {
 			Padding.Parent = this;
 		}
 
-		ustring title;
+		ustring title = ustring.Empty;
 
 		/// <summary>
 		/// The title to be displayed for this <see cref="View"/>. The title will be displayed if <see cref="BorderFrame"/>.<see cref="Thickness.Top"/>
@@ -1029,11 +1029,11 @@ namespace Terminal.Gui {
 				var s = GetAutoSize ();
 				var w = width is Dim.DimAbsolute && width.Anchor (0) > s.Width ? width.Anchor (0) : s.Width;
 				var h = height is Dim.DimAbsolute && height.Anchor (0) > s.Height ? height.Anchor (0) : s.Height;
-				frame = new Rect (new Point (actX, actY), new Size (w, h));
+				Frame = new Rect (new Point (actX, actY), new Size (w, h));
 			} else {
 				var w = width is Dim.DimAbsolute ? width.Anchor (0) : frame.Width;
 				var h = height is Dim.DimAbsolute ? height.Anchor (0) : frame.Height;
-				frame = new Rect (new Point (actX, actY), new Size (w, h));
+				Frame = new Rect (new Point (actX, actY), new Size (w, h));
 				SetMinWidthHeight ();
 			}
 			// BUGBUG: I think these calls are redundant or should be moved into just the AutoSize case

+ 48 - 48
UnitTests/Core/BorderTests.cs

@@ -580,56 +580,56 @@ namespace Terminal.Gui.CoreTests {
 			Assert.Null (Record.Exception (() => label.Redraw (label.Bounds)));
 		}
 
-		[Fact, AutoInitShutdown]
-		public void BorderStyle_And_DrawMarginFrame_Gets_Sets ()
-		{
-			var lblTop = new Label ("At 0,0");
-			var lblFrame = new Label ("Centered") { X = Pos.Center (), Y = Pos.Center () };
-			var frame = new FrameView () { Y = 1, Width = 20, Height = 3 };
-			var lblFill = new Label () { Width = Dim.Fill(),Height = Dim.Fill(), Visible = false };
-			var fillText = new System.Text.StringBuilder ();
-			for (int i = 0; i < frame.Bounds.Height; i++) {
-				if (i > 0) {
-					fillText.AppendLine ("");
-				}
-				for (int j = 0; j < frame.Bounds.Width; j++) {
-					fillText.Append ("█");
-				}
-			}
-			lblFill.Text = fillText.ToString ();
-			frame.Add (lblFill, lblFrame);
-			var lblBottom = new Label ("At 0,4") { Y = 4 };
-			Application.Top.Add (lblTop, frame, lblBottom);
-			Application.Begin (Application.Top);
-
-			Assert.Equal (BorderStyle.Single, frame.Border.BorderStyle);
-			Assert.True (frame.Border.DrawMarginFrame);
-			TestHelpers.AssertDriverContentsWithFrameAre (@"
-At 0,0              
-┌──────────────────┐
-│     Centered     │
-└──────────────────┘
-At 0,4              ", output);
-
-			frame.Border.BorderStyle = BorderStyle.None;
-			Application.Refresh ();
-			Assert.True (frame.Border.DrawMarginFrame);
-			TestHelpers.AssertDriverContentsWithFrameAre (@"
-At 0,0        
-              
-      Centered
-              
-At 0,4        ", output);
-
-//			frame.Border.DrawMarginFrame = false;
-//			lblFill.Visible = true;
-//			Application.Refresh ();
+//		[Fact, AutoInitShutdown]
+//		public void BorderStyle_And_DrawMarginFrame_Gets_Sets ()
+//		{
+//			var lblTop = new Label ("At 0,0");
+//			var lblFrame = new Label ("Centered") { X = Pos.Center (), Y = Pos.Center () };
+//			var frame = new FrameView () { Y = 1, Width = 20, Height = 3 };
+//			var lblFill = new Label () { Width = Dim.Fill(),Height = Dim.Fill(), Visible = false };
+//			var fillText = new System.Text.StringBuilder ();
+//			for (int i = 0; i < frame.Bounds.Height; i++) {
+//				if (i > 0) {
+//					fillText.AppendLine ("");
+//				}
+//				for (int j = 0; j < frame.Bounds.Width; j++) {
+//					fillText.Append ("█");
+//				}
+//			}
+//			lblFill.Text = fillText.ToString ();
+//			frame.Add (lblFill, lblFrame);
+//			var lblBottom = new Label ("At 0,4") { Y = 4 };
+//			Application.Top.Add (lblTop, frame, lblBottom);
+//			Application.Begin (Application.Top);
+
+//			Assert.Equal (BorderStyle.Single, frame.Border.BorderStyle);
+//			Assert.True (frame.Border.DrawMarginFrame);
 //			TestHelpers.AssertDriverContentsWithFrameAre (@"
 //At 0,0              
-//████████████████████
-//██████Centered██████
-//████████████████████
+//┌──────────────────┐
+//│     Centered     │
+//└──────────────────┘
 //At 0,4              ", output);
-		}
+
+//			frame.Border.BorderStyle = BorderStyle.None;
+//			Application.Refresh ();
+//			Assert.True (frame.Border.DrawMarginFrame);
+//			TestHelpers.AssertDriverContentsWithFrameAre (@"
+//At 0,0        
+              
+//      Centered
+              
+//At 0,4        ", output);
+
+////			frame.Border.DrawMarginFrame = false;
+////			lblFill.Visible = true;
+////			Application.Refresh ();
+////			TestHelpers.AssertDriverContentsWithFrameAre (@"
+////At 0,0              
+////████████████████████
+////██████Centered██████
+////████████████████████
+////At 0,4              ", output);
+		//}
 	}
 }

+ 175 - 0
UnitTests/Core/FrameTests.cs

@@ -0,0 +1,175 @@
+using NStack;
+using System;
+using System.Collections.Generic;
+using System.Xml.Linq;
+using Terminal.Gui.Graphs;
+using Xunit;
+using Xunit.Abstractions;
+//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
+
+// Alias Console to MockConsole so we don't accidentally use Console
+using Console = Terminal.Gui.FakeConsole;
+
+namespace Terminal.Gui.CoreTests {
+	public class FrameTests {
+		readonly ITestOutputHelper output;
+
+		public FrameTests (ITestOutputHelper output)
+		{
+			this.output = output;
+		}
+
+		[Theory, AutoInitShutdown]
+		[InlineData (0)]
+		[InlineData (1)]
+		[InlineData (2)]
+		[InlineData (3)]
+		public void BorderFrame_With_Title_Size_Height (int height)
+		{
+			var win = new Window ("1234") {
+				Width = Dim.Fill (),
+				Height = Dim.Fill ()
+			};
+
+			var rs = Application.Begin (win);
+			bool firstIteration = false;
+
+			((FakeDriver)Application.Driver).SetBufferSize (20, height);
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			var expected = string.Empty;
+
+			switch (height) {
+			case 0:
+				//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
+				expected = @"
+";
+				break;
+			case 1:
+				//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
+				expected = @"
+────────────────────";
+				break;
+			case 2:
+				//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
+				expected = @"
+┌┤1234├────────────┐
+└──────────────────┘
+";
+				break;
+			case 3:
+				//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
+				expected = @"
+┌┤1234├────────────┐
+│                  │
+└──────────────────┘
+";
+				break;
+			}
+			_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+		}
+		
+		[Theory, AutoInitShutdown]
+		[InlineData (0)]
+		[InlineData (1)]
+		[InlineData (2)]
+		[InlineData (3)]
+		[InlineData (4)]
+		[InlineData (5)]
+		[InlineData (6)]
+		[InlineData (7)]
+		[InlineData (8)]
+		[InlineData (9)]
+		[InlineData (10)]
+		public void BorderFrame_With_Title_Size_Width (int width)
+		{
+			var win = new Window ("1234") {
+				Width = Dim.Fill (),
+				Height = Dim.Fill ()
+			};
+
+			var rs = Application.Begin (win);
+			bool firstIteration = false;
+
+			((FakeDriver)Application.Driver).SetBufferSize (width, 3);
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			var expected = string.Empty;
+
+			switch (width) {
+			case 1:
+				//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
+				expected = @"
+│
+│
+│";
+				break;
+			case 2:
+				//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
+				expected = @"
+┌┐
+││
+└┘";
+				break;
+			case 3:
+				//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
+				expected = @"
+┌─┐
+│ │
+└─┘
+";
+				break;
+			case 4:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤├┐
+│  │
+└──┘";
+				break;
+			case 5:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤1├┐
+│   │
+└───┘";
+				break;
+			case 6:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤12├┐
+│    │
+└────┘";
+				break;
+			case 7:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤123├┐
+│     │
+└─────┘";
+				break;
+			case 8:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤1234├┐
+│      │
+└──────┘";
+				break;
+			case 9:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤1234├─┐
+│       │
+└───────┘";
+				break;
+			case 10:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌┤1234├──┐
+│        │
+└────────┘";
+				break;
+			}
+			_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+		}
+	}
+}

+ 294 - 2
UnitTests/Core/LayoutTests.cs

@@ -60,7 +60,7 @@ namespace Terminal.Gui.CoreTests {
 			second.X = Pos.Right (first) + 1;
 
 			root.LayoutSubviews ();
-			
+
 			Assert.Equal (6, second.Frame.X);
 		}
 
@@ -1492,7 +1492,7 @@ Y
 
 			testView = new View () {
 				AutoSize = false,
-				X = Pos.Left(testView),
+				X = Pos.Left (testView),
 				Y = Pos.Left (testView),
 				Width = 1,
 				Height = 1
@@ -1514,5 +1514,297 @@ Y
 			Assert.Equal (6, testView.Frame.X);
 			Assert.Equal (6, testView.Frame.Y);
 		}
+
+
+		[Theory, AutoInitShutdown]
+		[InlineData (1)]
+		[InlineData (2)]
+		[InlineData (3)]
+		[InlineData (4)]
+		[InlineData (5)]
+		[InlineData (6)]
+		[InlineData (7)]
+		[InlineData (8)]
+		[InlineData (9)]
+		[InlineData (10)]
+		public void Dim_CenteredSubView_85_Percent_Height (int height)
+		{
+			var win = new Window () {
+				Width = Dim.Fill (),
+				Height = Dim.Fill ()
+			};
+
+			var subview = new Window () {
+				X = Pos.Center (),
+				Y = Pos.Center (),
+				Width = Dim.Percent (85),
+				Height = Dim.Percent (85)
+			};
+
+			win.Add (subview);
+
+			var rs = Application.Begin (win);
+			bool firstIteration = false;
+
+
+
+			((FakeDriver)Application.Driver).SetBufferSize (20, height);
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			var expected = string.Empty;
+
+			switch (height) {
+			case 1:
+				//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
+				expected = @"
+────────────────────";
+				break;
+			case 2:
+				//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
+				expected = @"
+┌──────────────────┐
+└──────────────────┘
+";
+				break;
+			case 3:
+				//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│                  │
+└──────────────────┘
+";
+				break;
+			case 4:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│ ───────────────  │
+│                  │
+└──────────────────┘";
+				break;
+			case 5:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			case 6:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			case 7:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			case 8:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			case 9:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			case 10:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+				break;
+			}
+			_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+		}
+		[Theory, AutoInitShutdown]
+		[InlineData (1)]
+		[InlineData (2)]
+		[InlineData (3)]
+		[InlineData (4)]
+		[InlineData (5)]
+		[InlineData (6)]
+		[InlineData (7)]
+		[InlineData (8)]
+		[InlineData (9)]
+		[InlineData (10)]
+		public void Dim_CenteredSubView_85_Percent_Width (int width)
+		{
+			var win = new Window () {
+				Width = Dim.Fill (),
+				Height = Dim.Fill ()
+			};
+
+			var subview = new Window () {
+				X = Pos.Center (),
+				Y = Pos.Center (),
+				Width = Dim.Percent (85),
+				Height = Dim.Percent (85)
+			};
+
+			win.Add (subview);
+
+			var rs = Application.Begin (win);
+			bool firstIteration = false;
+
+
+
+			((FakeDriver)Application.Driver).SetBufferSize (width, 7);
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			var expected = string.Empty;
+
+			switch (width) {
+			case 1:
+				//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
+				expected = @"
+│
+│
+│
+│
+│
+│
+│";
+				break;
+			case 2:
+				//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
+				expected = @"
+┌┐
+││
+││
+││
+││
+││
+└┘";
+				break;
+			case 3:
+				//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
+				expected = @"
+┌─┐
+│ │
+│ │
+│ │
+│ │
+│ │
+└─┘
+";
+				break;
+			case 4:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──┐
+││ │
+││ │
+││ │
+││ │
+│  │
+└──┘";
+				break;
+			case 5:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌───┐
+│┌┐ │
+│││ │
+│││ │
+│└┘ │
+│   │
+└───┘";
+				break;
+			case 6:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌────┐
+│┌─┐ │
+││ │ │
+││ │ │
+│└─┘ │
+│    │
+└────┘";
+				break;
+			case 7:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌─────┐
+│┌──┐ │
+││  │ │
+││  │ │
+│└──┘ │
+│     │
+└─────┘";
+				break;
+			case 8:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌──────┐
+│┌───┐ │
+││   │ │
+││   │ │
+│└───┘ │
+│      │
+└──────┘";
+				break;
+			case 9:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌───────┐
+│ ┌───┐ │
+│ │   │ │
+│ │   │ │
+│ └───┘ │
+│       │
+└───────┘";
+				break;
+			case 10:
+				//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
+				expected = @"
+┌────────┐
+│ ┌────┐ │
+│ │    │ │
+│ │    │ │
+│ └────┘ │
+│        │
+└────────┘";
+				break;
+			}
+			_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+		}
 	}
 }

+ 11 - 0
UnitTests/Core/ViewTests.cs

@@ -148,6 +148,12 @@ namespace Terminal.Gui.CoreTests {
 				Width = 3,
 				Height = 4
 			};
+			var super = new View (new Rect (0, 0, 10, 10));
+			super.Add (view);
+			super.BeginInit ();
+			super.EndInit ();
+			super.LayoutSubviews ();
+
 			Assert.Equal (1, view.X);
 			Assert.Equal (2, view.Y);
 			Assert.Equal (3, view.Width);
@@ -190,6 +196,11 @@ namespace Terminal.Gui.CoreTests {
 			view.Y = 2;
 			view.Width = 3;
 			view.Height = 4;
+			super = new View (new Rect (0, 0, 10, 10));
+			super.Add (view);
+			super.BeginInit ();
+			super.EndInit ();
+			super.LayoutSubviews ();
 			Assert.Equal (1, view.X);
 			Assert.Equal (2, view.Y);
 			Assert.Equal (3, view.Width);

+ 2 - 2
UnitTests/Drivers/ConsoleDriverTests.cs

@@ -440,7 +440,7 @@ namespace Terminal.Gui.DriverTests {
 ││  Hello World  │ │
 ││               │ │
 ││               │ │
-││    [ Ok ]     │ │
+││     [ Ok ]    │ │
 │└───────────────┘ │
 └──────────────────┘
 ";
@@ -457,7 +457,7 @@ namespace Terminal.Gui.DriverTests {
 ││  Hello World  │ │
 ││               │ │
 ││               │ │
-││    [ Ok ]     │ │
+││     [ Ok ]    │ │
 │└───────────────┘ │
 └──────────────────┘
 ";

+ 21 - 21
UnitTests/Text/TextFormatterTests.cs

@@ -3462,7 +3462,7 @@ This TextFormatter (tf2) is rewritten.
 				Height = 1,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3479,7 +3479,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Vie     │
 │        │
 └────────┘
@@ -3515,7 +3515,7 @@ This TextFormatter (tf2) is rewritten.
 				Width = Dim.Fill () - text.Length,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3532,7 +3532,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Vie     │
 │        │
 └────────┘
@@ -3551,7 +3551,7 @@ This TextFormatter (tf2) is rewritten.
 			var exception = Record.Exception (() => Assert.Equal (new List<ustring> () { ustring.Empty }, view.TextFormatter.Lines));
 			Assert.Null (exception);
 			expected = @"
-┌┤Wind├──┐
+┌────────┐
 │        │
 │        │
 └────────┘
@@ -3570,7 +3570,7 @@ This TextFormatter (tf2) is rewritten.
 				Height = 1,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3587,7 +3587,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Label   │
 │        │
 └────────┘
@@ -3606,7 +3606,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
 			Assert.Single (label.TextFormatter.Lines);
 			expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Label   │
 │        │
 └────────┘
@@ -3626,7 +3626,7 @@ This TextFormatter (tf2) is rewritten.
 				Text = text,
 				AutoSize = false
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3643,7 +3643,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Lab     │
 │        │
 └────────┘
@@ -3662,7 +3662,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Size (0, 1), label.TextFormatter.Size);
 			Assert.Equal (new List<ustring> { ustring.Empty }, label.TextFormatter.Lines);
 			expected = @"
-┌┤Wind├──┐
+┌────────┐
 │        │
 │        │
 └────────┘
@@ -3680,7 +3680,7 @@ This TextFormatter (tf2) is rewritten.
 				Width = Dim.Fill () - text.Length,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3697,7 +3697,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Label   │
 │        │
 └────────┘
@@ -3716,7 +3716,7 @@ This TextFormatter (tf2) is rewritten.
 			var exception = Record.Exception (() => Assert.Single (label.TextFormatter.Lines));
 			Assert.Null (exception);
 			expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Label   │
 │        │
 └────────┘
@@ -3735,7 +3735,7 @@ This TextFormatter (tf2) is rewritten.
 				Text = text,
 				AutoSize = false
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3752,7 +3752,7 @@ This TextFormatter (tf2) is rewritten.
 			Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
 			Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
 			var expected = @"
-┌┤Wind├──┐
+┌────────┐
 │Lab     │
 │        │
 └────────┘
@@ -3771,7 +3771,7 @@ This TextFormatter (tf2) is rewritten.
 			var exception = Record.Exception (() => Assert.Equal (new List<ustring> () { ustring.Empty }, label.TextFormatter.Lines));
 			Assert.Null (exception);
 			expected = @"
-┌┤Wind├──┐
+┌────────┐
 │        │
 │        │
 └────────┘
@@ -3791,7 +3791,7 @@ This TextFormatter (tf2) is rewritten.
 				Text = text,
 				AutoSize = true
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3858,7 +3858,7 @@ This TextFormatter (tf2) is rewritten.
 				Height = Dim.Fill () - text.Length,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3926,7 +3926,7 @@ This TextFormatter (tf2) is rewritten.
 				Text = text,
 				AutoSize = true
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};
@@ -3993,7 +3993,7 @@ This TextFormatter (tf2) is rewritten.
 				Height = Dim.Fill () - text.Length,
 				Text = text
 			};
-			var win = new Window ("Window") {
+			var win = new Window () {
 				Width = Dim.Fill (),
 				Height = Dim.Fill ()
 			};

+ 101 - 0
UnitTests/TopLevels/DialogTests.cs

@@ -91,6 +91,37 @@ namespace Terminal.Gui.TopLevelTests {
 			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
 			TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
 			Application.End (runstate);
+
+			// Wider
+			buttonRow = $"{d.VLine}   {d.LeftBracket} {btnText} {d.RightBracket}   {d.VLine}";
+			width = buttonRow.Length;
+
+			d.SetBufferSize (width, 1);
+
+			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
+			TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
+			Application.End (runstate);
+
+			// Justify
+			buttonRow = $"{d.VLine}      {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
+			Assert.Equal (width, buttonRow.Length);
+			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
+			TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
+			Application.End (runstate);
+
+			// Right
+			buttonRow = $"{d.VLine}      {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
+			Assert.Equal (width, buttonRow.Length);
+			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
+			TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
+			Application.End (runstate);
+
+			// Left
+			buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket}      {d.VLine}";
+			Assert.Equal (width, buttonRow.Length);
+			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
+			TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
+			Application.End (runstate);
 		}
 
 		[Fact]
@@ -685,5 +716,75 @@ namespace Terminal.Gui.TopLevelTests {
 
 			Assert.Equal (4, iterations);
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Dialog_In_Window_With_Size_One_Button_Aligns ()
+		{
+			((FakeDriver)Application.Driver).SetBufferSize (20, 5);
+
+			var win = new Window ();
+
+			int iterations = 0;
+			Application.Iteration += () => {
+				if (++iterations > 2) {
+					Application.RequestStop ();
+				}
+			};
+			
+			win.Loaded += (s, a) => {
+				var dlg = new Dialog ("Test", 18, 3, new Button ("Ok"));
+
+				dlg.Loaded += (s, a) => {
+					Application.Refresh ();
+					var expected = @"
+┌──────────────────┐
+│┌┤Test├──────────┐│
+││     [ Ok ]     ││
+│└────────────────┘│
+└──────────────────┘";
+					_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+				};
+
+				Application.Run (dlg);
+			};
+			Application.Run (win);
+		}
+		
+//		[Theory, AutoInitShutdown]
+//		[InlineData (5)]
+//		//[InlineData (6)]
+//		//[InlineData (7)]
+//		//[InlineData (8)]
+//		//[InlineData (9)]
+//		public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height)
+//		{
+//			((FakeDriver)Application.Driver).SetBufferSize (20, height);
+//			var win = new Window ();
+
+//			Application.Iteration += () => {
+//				var dlg = new Dialog ("Test", new Button ("Ok"));
+
+//				dlg.LayoutComplete += (s, a) => {
+//					Application.Refresh ();
+//					// BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)??
+//					var expected = @"
+//┌┌┤Test├─────────┐─┐
+//││               │ │
+//││     [ Ok ]    │ │
+//│└───────────────┘ │
+//└──────────────────┘";
+//					_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+//					dlg.RequestStop ();
+//					win.RequestStop ();
+//				};
+
+//				Application.Run (dlg);
+//			};
+
+//			Application.Run (win);
+//			Application.Shutdown ();
+//		}
 	}
+
 }

+ 2 - 2
UnitTests/TopLevels/MessageBoxTests.cs

@@ -97,7 +97,7 @@ namespace Terminal.Gui.TopLevelTests {
 		}
 
 		[Fact, AutoInitShutdown]
-		public void MessageBox_With_A_Lower_Fixed_Size ()
+		public void MessageBox_With_A_Smaller_Fixed_Size ()
 		{
 			var iterations = -1;
 			Application.Begin (Application.Top);
@@ -112,7 +112,7 @@ namespace Terminal.Gui.TopLevelTests {
 				} else if (iterations == 1) {
 					Application.Refresh ();
 					TestHelpers.AssertDriverContentsWithFrameAre (@"
-                                    ┌─────┐
+                                    ┌┤T├──┐
                                     │Messa│
                                     │ ge  │
                                     │ Ok ◦│

+ 0 - 1
UnitTests/Types/DimTests.cs

@@ -1247,7 +1247,6 @@ namespace Terminal.Gui.TypeTests {
 		[InlineData (0, false)]
 		[InlineData (50, true)]
 		[InlineData (50, false)]
-
 		public void DimPercentPlusOne (int startingDistance, bool testHorizontal)
 		{
 			var container = new View {