ソースを参照

Text alignment (#397)

* not sure why this keeps changing

* enhanced Show Text Alignments demo to better illustrate bugs in TextAlignment.Justified
Charlie Kindel 5 年 前
コミット
427cf4784b
1 ファイル変更16 行追加11 行削除
  1. 16 11
      Example/demo.cs

+ 16 - 11
Example/demo.cs

@@ -6,6 +6,7 @@ using System.Diagnostics;
 using System.Globalization;
 using System.Reflection;
 using NStack;
+using System.Text;
 
 static class Demo {
 	//class Box10x : View, IScrollView {
@@ -81,22 +82,26 @@ static class Demo {
 		}
 	}
 
-
 	static void ShowTextAlignments ()
 	{
-		var container = new Dialog (
-			"Text Alignments", 50, 20,
-			new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
-			new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
-
+		var container = new Window ($"Show Text Alignments") {
+			X = 0,
+			Y = 0,
+			Width = Dim.Fill (),
+			Height = Dim.Fill ()
+		};
+		container.OnKeyUp += (KeyEvent ke) => {
+			if (ke.Key == Key.Esc)
+				container.Running = false;
+		};
 
 		int i = 0;
-		string txt = "Hello world, how are you doing today";
+		string txt = "Hello world, how are you doing today?";
 		container.Add (
-				new Label (new Rect (0, 1, 40, 3), $"{i+1}-{txt}") { TextAlignment = TextAlignment.Left },
-				new Label (new Rect (0, 3, 40, 3), $"{i+2}-{txt}") { TextAlignment = TextAlignment.Right },
-				new Label (new Rect (0, 5, 40, 3), $"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered },
-				new Label (new Rect (0, 7, 40, 3), $"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified }
+				new Label ($"{i+1}-{txt}") { TextAlignment = TextAlignment.Left,      Y = 3, Width = Dim.Fill () },
+				new Label ($"{i+2}-{txt}") { TextAlignment = TextAlignment.Right,     Y = 5, Width = Dim.Fill () },
+				new Label ($"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered,  Y = 7, Width = Dim.Fill () },
+				new Label ($"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified, Y = 9, Width = Dim.Fill () }
 			);
 
 		Application.Run (container);