From 427cf4784b73b296fc2efefb896706d6195fcc87 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 29 Apr 2020 09:09:10 -0600 Subject: [PATCH] Text alignment (#397) * not sure why this keeps changing * enhanced Show Text Alignments demo to better illustrate bugs in TextAlignment.Justified --- Example/demo.cs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index f138bc329..a2c11bb7f 100644 --- a/Example/demo.cs +++ b/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);