Browse Source

Fixed label and updated TextAlignment scenario

Charlie Kindel 5 years ago
parent
commit
c3ee01dc3e
2 changed files with 19 additions and 12 deletions
  1. 1 1
      Terminal.Gui/Views/Label.cs
  2. 18 11
      UICatalog/Scenarios/TextAlignment.cs

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

@@ -179,7 +179,7 @@ namespace Terminal.Gui {
 				int x;
 				switch (textAlignment) {
 				case TextAlignment.Left:
-					x = Frame.Left;
+					x = 0;
 					break;
 				case TextAlignment.Justified:
 					Recalc ();

+ 18 - 11
UICatalog/Scenarios/TextAlignment.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using Terminal.Gui;
 
@@ -9,18 +10,24 @@ namespace UICatalog {
 		public override void Setup ()
 		{
 			int i = 1;
-			string txt = "Hello world, how are you doing today";
-			var labelList = new List<Label> ();
-			labelList.Add (new Label ($"Label:"));
-			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Left, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1 });
-			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Right, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1 });
-			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Centered, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1 });
-			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Justified, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1 });
+			string txt = "Hello world, how are you doing today?";
+
+			var alignments = Enum.GetValues (typeof (Terminal.Gui.TextAlignment)).Cast<Terminal.Gui.TextAlignment> ().ToList();
+
+			foreach (var alignment in alignments) {
+				Win.Add (new Label ($"{alignment}:") { Y = ++i });
+				Win.Add (new Label (txt) { TextAlignment = alignment, Y = i++, Width = Dim.Fill(), ColorScheme = Colors.Dialog });
+			}
+
+			// Demonstrate that wrapping labels are not yet implemented (#352)
 			txt += "\nSecond line";
-			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Left, Width = Dim.Fill (1), Height = 4, X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1 });
+			Win.Add (new Label ($"Demonstrating multi-line (note wrap is not yet implemented):") { Y = ++i });
 
-			Win.Add (labelList.ToArray ());
-			Win.LayoutSubviews ();
+			foreach (var alignment in alignments) {
+				Win.Add (new Label ($"{alignment}:") { Y = ++i });
+				Win.Add (new Label (txt) { TextAlignment = alignment, Y = ++i, Width = Dim.Fill (), Height = 2, ColorScheme = Colors.Dialog });
+				i += 2;
+			}
 		}
 	}
 }