Explorar o código

Got new title bar look working

Tigger Kindel %!s(int64=2) %!d(string=hai) anos
pai
achega
1ec5afbddf

+ 5 - 5
Terminal.Gui/Core/ConsoleDriver.cs

@@ -930,14 +930,14 @@ namespace Terminal.Gui {
 		/// <remarks></remarks>
 		/// <remarks></remarks>
 		public virtual void DrawWindowTitle (Rect region, ustring title, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, TextAlignment textAlignment = TextAlignment.Left)
 		public virtual void DrawWindowTitle (Rect region, ustring title, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, TextAlignment textAlignment = TextAlignment.Left)
 		{
 		{
-			var width = region.Width - (paddingLeft + 2) * 2;
-			if (!ustring.IsNullOrEmpty (title) && width > 4 && region.Y + paddingTop <= region.Y + paddingBottom) {
-				Move (region.X + 1 + paddingLeft, region.Y + paddingTop);
-				AddRune (' ');
+			var width = region.Width - (paddingLeft + 1) * 2;
+			if (!ustring.IsNullOrEmpty (title) && width > 2 && region.Y + paddingTop <= region.Y + paddingBottom) {
+				Move (region.X + 2 + paddingLeft, region.Y + paddingTop);
+				//AddRune (' ');
 				var str = title.Sum (r => Math.Max (Rune.ColumnWidth (r), 1)) >= width
 				var str = title.Sum (r => Math.Max (Rune.ColumnWidth (r), 1)) >= width
 					? TextFormatter.Format (title, width - 2, false, false) [0] : title;
 					? TextFormatter.Format (title, width - 2, false, false) [0] : title;
 				AddStr (str);
 				AddStr (str);
-				AddRune (' ');
+				//AddRune (' ');
 			}
 			}
 		}
 		}
 
 

+ 21 - 17
Terminal.Gui/Core/Frame.cs

@@ -103,24 +103,32 @@ namespace Terminal.Gui {
 			//OnDrawSubviews (bounds); 
 			//OnDrawSubviews (bounds); 
 
 
 			// TODO: v2 - this will eventually be two controls: "BorderView" and "Label" (for the title)
 			// TODO: v2 - this will eventually be two controls: "BorderView" and "Label" (for the title)
+
+			if (Id == "BorderFrame" && Thickness.Top > 0 && !ustring.IsNullOrEmpty (Parent?.Title)) {
+
+				Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ());
+				Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0);
+			}
+
 			if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) {
 			if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) {
 				var lc = new LineCanvas ();
 				var lc = new LineCanvas ();
 				if (Thickness.Top > 0) {
 				if (Thickness.Top > 0) {
-					if (ustring.IsNullOrEmpty (Parent?.Title)) {
+					// ╔╡ Title ╞═════╗
+					// ╔╡  ╞═════╗
+					if (Frame.Width < 6 || ustring.IsNullOrEmpty (Parent?.Title)) {
+						// ╔╡╞╗ should be ╔══╗
 						lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
 						lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
 					} else {
 					} else {
-
-						lc.AddLine (screenBounds.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
-
-						//// ╔╡ Title ╞═════╗
-						//// Add a short horiz line for ╔╡
-						//lc.AddLine (screenBounds.Location, 1, Orientation.Horizontal, BorderStyle);
-						//// Add a short vert line for ╔╡
-						//lc.AddLine (new Point (screenBounds.X + 1, screenBounds.Location.Y - 1), 1, Orientation.Vertical, BorderStyle.Single);
-						//// Add a short vert line for ╞
-						//lc.AddLine (new Point (screenBounds.X + (Parent.Title.Length + 3), screenBounds.Location.Y - 1), 1, Orientation.Vertical, BorderStyle.Single);
-						//// Add the right hand line for ╞═════╗
-						//lc.AddLine (new Point (screenBounds.X + (Parent.Title.Length + 3), screenBounds.Location.Y), Frame.Width - 1 - (Parent.Title.Length + 2), Orientation.Horizontal, BorderStyle);
+						var titleWidth = Math.Min (Parent.Title.ConsoleWidth, Frame.Width - 6);
+						// ╔╡ Title ╞═════╗
+						// Add a short horiz line for ╔╡
+						lc.AddLine (screenBounds.Location, 1, Orientation.Horizontal, BorderStyle);
+						// Add a short vert line for ╔╡
+						lc.AddLine (new Point (screenBounds.X + 1, screenBounds.Location.Y), 0, Orientation.Vertical, BorderStyle.Single);
+						// Add a short vert line for ╞
+						lc.AddLine (new Point (screenBounds.X + 1 + (titleWidth + 1), screenBounds.Location.Y), 0, Orientation.Vertical, BorderStyle.Single);
+						// Add the right hand line for ╞═════╗
+						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) {
@@ -137,11 +145,7 @@ namespace Terminal.Gui {
 					Driver.AddRune (p.Value);
 					Driver.AddRune (p.Value);
 				}
 				}
 			}
 			}
-			if (Id == "BorderFrame" && Thickness.Top > 0 && !ustring.IsNullOrEmpty (Parent?.Title)) {
 
 
-				Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ());
-				Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0);
-			}
 
 
 			Driver.Clip = prevClip;
 			Driver.Clip = prevClip;
 		}
 		}

+ 13 - 24
Terminal.Gui/Core/Graphs/LineCanvas.cs

@@ -199,8 +199,8 @@ namespace Terminal.Gui.Graphs {
 			}
 			}
 
 
 			// TODO: Remove these two once we have all of the below ported to IntersectionRuneResolvers
 			// TODO: Remove these two once we have all of the below ported to IntersectionRuneResolvers
-			var useDouble = intersects.Any (i => i.Line.Style == BorderStyle.Double && i.Line.Length != 0);
-			var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded && i.Line.Length != 0);
+			var useDouble = intersects.Any (i => i.Line.Style == BorderStyle.Double);
+			var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded);
 			// TODO: Support ruler
 			// TODO: Support ruler
 			//var useRuler = intersects.Any (i => i.Line.Style == BorderStyle.Ruler && i.Line.Length != 0);
 			//var useRuler = intersects.Any (i => i.Line.Style == BorderStyle.Ruler && i.Line.Length != 0);
 
 
@@ -222,13 +222,6 @@ namespace Terminal.Gui.Graphs {
 
 
 		private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects)
 		private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects)
 		{
 		{
-			if (intersects.All (i => i.Line.Length == 0)) {
-				return IntersectionRuneType.Dot;
-			}
-
-			// ignore dots
-			intersects = intersects.Where (i => i.Type != IntersectionType.Dot).ToArray ();
-
 			var set = new HashSet<IntersectionType> (intersects.Select (i => i.Type));
 			var set = new HashSet<IntersectionType> (intersects.Select (i => i.Type));
 
 
 			#region Crosshair Conditions
 			#region Crosshair Conditions
@@ -489,14 +482,6 @@ namespace Terminal.Gui.Graphs {
 
 
 			internal IntersectionDefinition Intersects (int x, int y)
 			internal IntersectionDefinition Intersects (int x, int y)
 			{
 			{
-				if (IsDot ()) {
-					if (StartsAt (x, y)) {
-						return new IntersectionDefinition (Start, IntersectionType.Dot, this);
-					} else {
-						return null;
-					}
-				}
-
 				switch (Orientation) {
 				switch (Orientation) {
 				case Orientation.Horizontal: return IntersectsHorizontally (x, y);
 				case Orientation.Horizontal: return IntersectsHorizontally (x, y);
 				case Orientation.Vertical: return IntersectsVertically (x, y);
 				case Orientation.Vertical: return IntersectsVertically (x, y);
@@ -514,7 +499,7 @@ namespace Terminal.Gui.Graphs {
 
 
 						return new IntersectionDefinition (
 						return new IntersectionDefinition (
 							Start,
 							Start,
-							Length < 0 ? IntersectionType.StartLeft : IntersectionType.StartRight,
+							GetTypeByLength(IntersectionType.StartLeft, IntersectionType.PassOverHorizontal,IntersectionType.StartRight),
 							this
 							this
 							);
 							);
 
 
@@ -554,7 +539,7 @@ namespace Terminal.Gui.Graphs {
 
 
 						return new IntersectionDefinition (
 						return new IntersectionDefinition (
 							Start,
 							Start,
-							Length < 0 ? IntersectionType.StartUp : IntersectionType.StartDown,
+							GetTypeByLength(IntersectionType.StartUp, IntersectionType.PassOverVertical, IntersectionType.StartDown),
 							this
 							this
 							);
 							);
 
 
@@ -585,6 +570,15 @@ namespace Terminal.Gui.Graphs {
 				}
 				}
 			}
 			}
 
 
+			private IntersectionType GetTypeByLength (IntersectionType typeWhenNegative, IntersectionType typeWhenZero, IntersectionType typeWhenPositive)
+			{
+				if (Length == 0) {
+					return typeWhenZero;
+				} 
+
+				return Length < 0 ? typeWhenNegative : typeWhenPositive;
+			}
+
 			private bool EndsAt (int x, int y)
 			private bool EndsAt (int x, int y)
 			{
 			{
 				if (Orientation == Orientation.Horizontal) {
 				if (Orientation == Orientation.Horizontal) {
@@ -598,11 +592,6 @@ namespace Terminal.Gui.Graphs {
 			{
 			{
 				return Start.X == x && Start.Y == y;
 				return Start.X == x && Start.Y == y;
 			}
 			}
-
-			private bool IsDot ()
-			{
-				return Length == 0;
-			}
 		}
 		}
 	}
 	}
 }
 }

+ 112 - 14
UnitTests/Core/LineCanvasTests.cs

@@ -15,20 +15,6 @@ namespace Terminal.Gui.CoreTests {
 			this.output = output;
 			this.output = output;
 		}
 		}
 
 
-		[Fact, AutoInitShutdown]
-		public void TestLineCanvas_Dot ()
-		{
-			var v = GetCanvas (out var canvas);
-			canvas.AddLine (new Point (0, 0), 0, Orientation.Horizontal, BorderStyle.Single);
-
-			v.Redraw (v.Bounds);
-
-			string looksLike =
-@"    
-.";
-			TestHelpers.AssertDriverContentsAre (looksLike, output);
-		}
-
 		[InlineData (BorderStyle.Single)]
 		[InlineData (BorderStyle.Single)]
 		[InlineData (BorderStyle.Rounded)]
 		[InlineData (BorderStyle.Rounded)]
 		[Theory, AutoInitShutdown]
 		[Theory, AutoInitShutdown]
@@ -311,8 +297,120 @@ namespace Terminal.Gui.CoreTests {
 ";
 ";
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 		}
 		}
+		[Fact, AutoInitShutdown]
+		public void TestLineCanvas_ClipArea_Intersections ()
+		{
+			// Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1)
+			var v = GetCanvas (out var lc);
+			v.Width = 10;
+			v.Height = 1;
+			v.Bounds = new Rect (0, 0, 10, 1);
+
+			// ╔╡ Title ╞═════╗
+			// Add a short horiz line for ╔╡
+			lc.AddLine (new Point (0, 0), 1, Orientation.Horizontal, BorderStyle.Double);
+			//LHS line down
+			lc.AddLine (new Point (0, 0), 5, Orientation.Vertical, BorderStyle.Double);
+
+			//Vertical line before Title, results in a ╡
+			lc.AddLine (new Point (1, 0), 0, Orientation.Vertical, BorderStyle.Single);
+			//Vertical line after Title, results in a ╞
+			lc.AddLine (new Point (6, 0), 0, Orientation.Vertical, BorderStyle.Single);
+
+			// remainder of title
+			lc.AddLine (new Point (6, 0), 3, Orientation.Horizontal, BorderStyle.Double);
+			//RHS line down
+			lc.AddLine (new Point (9, 0), 5, Orientation.Vertical, BorderStyle.Double);
+
+			v.Redraw (v.Bounds);
+
+			string looksLike =
+		@"
+╔╡    ╞══╗
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+		}
+
+		[InlineData(0,0,0, Orientation.Horizontal,BorderStyle.Double,"═")]
+		[InlineData(0,0,0, Orientation.Vertical,BorderStyle.Double,"║")]
+		[InlineData(0,0,0, Orientation.Horizontal,BorderStyle.Single,"─")]
+		[InlineData(0,0,0, Orientation.Vertical,BorderStyle.Single,"│")]
+		[AutoInitShutdown, Theory]
+		public void TestLineCanvas_1LineTests(
+			int x1, int y1,int l1, Orientation o1, BorderStyle s1,
+			string expected
+		)
+		{
+			var v = GetCanvas (out var lc);
+			v.Width = 10;
+			v.Height = 10;
+			v.Bounds = new Rect (0, 0, 10, 10);
+
+			lc.AddLine (new Point (x1, y1), l1, o1, s1);
+
+			v.Redraw (v.Bounds);
+		
+			TestHelpers.AssertDriverContentsAre (expected, output);
+		}
 
 
 
 
+		[Theory, AutoInitShutdown]
+		[InlineData(
+			0,0,1,Orientation.Horizontal,BorderStyle.Double,
+			1,0,0, Orientation.Vertical,BorderStyle.Single, "═╡"
+		)]
+		[InlineData(
+			0,0,0, Orientation.Vertical,BorderStyle.Single,
+			0,0,1,Orientation.Horizontal,BorderStyle.Double,
+			 "╞═"
+		)]
+		[InlineData(
+			0,0,1, Orientation.Vertical,BorderStyle.Single,
+			0,0,0,Orientation.Horizontal,BorderStyle.Double,
+@"
+╤
+│"
+		)]
+		[InlineData(
+			0,0,1, Orientation.Vertical,BorderStyle.Single,
+			0,1,0,Orientation.Horizontal,BorderStyle.Double,
+			@"
+│
+╧
+"
+		)]
+		[InlineData(
+			0,0,0, Orientation.Vertical,BorderStyle.Single,
+			0,0,0,Orientation.Horizontal,BorderStyle.Single,
+			@"┼
+"
+		)]
+		[InlineData(
+			0,0,0, Orientation.Vertical,BorderStyle.Double,
+			0,0,0,Orientation.Horizontal,BorderStyle.Double,
+			@"╬
+"
+		)]
+		public void TestLineCanvas_2LineTests(
+			int x1, int y1,int l1, Orientation o1, BorderStyle s1,
+			int x2, int y2, int l2, Orientation o2, BorderStyle s2,
+			string expected
+		)
+		{
+			var v = GetCanvas (out var lc);
+			v.Width = 10;
+			v.Height = 10;
+			v.Bounds = new Rect (0, 0, 10, 10);
+
+			lc.AddLine (new Point (x1, y1), l1, o1, s1);
+			lc.AddLine (new Point (x2, y2), l2, o2, s2);
+
+			v.Redraw (v.Bounds);
+		
+			TestHelpers.AssertDriverContentsAre (expected, output);
+		}
+		
+
 		/// <summary>
 		/// <summary>
 		/// Creates a new <see cref="View"/> into which a <see cref="LineCanvas"/> is rendered
 		/// Creates a new <see cref="View"/> into which a <see cref="LineCanvas"/> is rendered
 		/// at <see cref="View.DrawContentComplete"/> time.
 		/// at <see cref="View.DrawContentComplete"/> time.