Преглед на файлове

disabled word wrap on single line labels

Charlie Kindel преди 5 години
родител
ревизия
ceafb2db41
променени са 2 файла, в които са добавени 38 реда и са изтрити 26 реда
  1. 17 5
      Terminal.Gui/Views/Label.cs
  2. 21 21
      UICatalog/Scenarios/TextAlignments.cs

+ 17 - 5
Terminal.Gui/Views/Label.cs

@@ -163,7 +163,7 @@ namespace Terminal.Gui {
 		void Recalc ()
 		{
 			recalcPending = false;
-			Recalc (text, lines, Frame.Width, textAlignment);
+			Recalc (text, lines, Frame.Width, textAlignment, Bounds.Height > 1);
 		}
 
 		static List<ustring> WordWrap (ustring text, int margin)
@@ -195,9 +195,21 @@ namespace Terminal.Gui {
 			return lines;
 		}
 
-		static void Recalc (ustring textStr, List<ustring> lineResult, int width, TextAlignment talign)
+		static void Recalc (ustring textStr, List<ustring> lineResult, int width, TextAlignment talign, bool wordWrap)
 		{
 			lineResult.Clear ();
+
+			if (wordWrap == false) {
+				textStr = textStr.Replace ("\f", " ")
+				.Replace ("\n", " ")
+				.Replace ("\r", " ")
+				.Replace ("\t", " ")
+				.Replace ("\v", " ")
+				.TrimSpace ();
+				lineResult.Add (ClipAndJustify (textStr, width, talign));
+				return;
+			}
+
 			int textLen = textStr.Length;
 			int lp = 0;
 			for (int i = 0; i < textLen; i++) {
@@ -271,7 +283,7 @@ namespace Terminal.Gui {
 		public static int MeasureLines (ustring text, int width)
 		{
 			var result = new List<ustring> ();
-			Recalc (text, result, width, TextAlignment.Left);
+			Recalc (text, result, width, TextAlignment.Left, true);
 			return result.Count;
 		}
 
@@ -284,7 +296,7 @@ namespace Terminal.Gui {
 		public static int MaxWidth (ustring text, int width)
 		{
 			var result = new List<ustring> ();
-			Recalc (text, result, width, TextAlignment.Left);
+			Recalc (text, result, width, TextAlignment.Left, true);
 			return result.Max (s => s.RuneCount);
 		}
 
@@ -297,7 +309,7 @@ namespace Terminal.Gui {
 		public static int MaxHeight (ustring text, int width)
 		{
 			var result = new List<ustring> ();
-			Recalc (text, result, width, TextAlignment.Left);
+			Recalc (text, result, width, TextAlignment.Left, true);
 			return result.Count;
 		}
 

+ 21 - 21
UICatalog/Scenarios/TextAlignments.cs

@@ -9,30 +9,30 @@ namespace UICatalog {
 	class TextAlignments : Scenario {
 		public override void Setup ()
 		{
+#if true
+			string txt = "Hello world, how are you today? Pretty neat!";
+#else
+			string txt = "Hello world, how are you today? Unicode:  ~  gui.cs  . Neat?";
+#endif
 			var alignments = Enum.GetValues (typeof (Terminal.Gui.TextAlignment)).Cast<Terminal.Gui.TextAlignment> ().ToList ();
-			//var label = new Label ($"Demonstrating single-line (should clip!):") { Y = 0 };
-			//Win.Add (label);
-			string txt = "Hello world, how are you doing today? This is a test of the emergency.";
-
-			//foreach (var alignment in alignments) {
-			//	label = new Label ($"{alignment}:") { Y = Pos.Bottom (label) };
-			//	Win.Add (label);
-			//	label = new Label (txt) { TextAlignment = alignment, Y = Pos.Bottom (label), Width = Dim.Fill (), Height = 1, ColorScheme = Colors.Dialog };
-			//	Win.Add (label);
-			//}
-
-			// Demonstrate that wrapping labels are not yet implemented (#352)
-			//txt += "\nSecond line\n\nFourth Line.";
-			//label = new Label ($"Demonstrating multi-line (note wrap is not yet implemented):") { Y = Pos.Bottom (label) + 1 };
-			//Win.Add (label);
+			var label = new Label ($"Demonstrating single-line (should clip!):") { Y = 0 };
+			Win.Add (label);
+			foreach (var alignment in alignments) {
+				label = new Label ($"{alignment}:") { Y = Pos.Bottom (label) };
+				Win.Add (label);
+				label = new Label (txt) { TextAlignment = alignment, Y = Pos.Bottom (label), Width = Dim.Fill (), Height = 1, ColorScheme = Colors.Dialog };
+				Win.Add (label);
+			}
 
-			//foreach (var alignment in alignments) {
-			var alignment = TextAlignment.Left;
-			//label = new Label ($"{alignment}:") { Y = Pos.Bottom (label)};
-			//Win.Add (label);
-			var label = new Label (txt) { TextAlignment = alignment, Width = Dim.Fill (), Height = 6, ColorScheme = Colors.Dialog, Y = 0 };// Pos.Bottom (label) };
+			txt += "\nSecond line\n\nFourth Line.";
+			label = new Label ($"Demonstrating multi-line and word wrap:") { Y = Pos.Bottom (label) + 1 };
+			Win.Add (label);
+			foreach (var alignment in alignments) {
+				label = new Label ($"{alignment}:") { Y = Pos.Bottom (label) };
+				Win.Add (label);
+				label = new Label (txt) { TextAlignment = alignment, Width = Dim.Fill (), Height = 6, ColorScheme = Colors.Dialog, Y = Pos.Bottom (label) };
 				Win.Add (label);
-			//}
+			}
 		}
 	}
 }