From 40f72db0bd1bc816d68aac37488b63951abefaa1 Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 10 May 2024 10:05:16 -0600 Subject: [PATCH] Alignment->Justification --- Terminal.Gui/Views/Slider.cs | 8 +- Terminal.Gui/Views/TableView/TableView.cs | 4 +- UICatalog/Scenarios/CsvEditor.cs | 14 +- UICatalog/Scenarios/TextFormatterDemo.cs | 42 ++-- UICatalog/Scenarios/Unicode.cs | 2 +- UnitTests/Dialogs/DialogTests.cs | 16 +- UnitTests/Text/TextFormatterTests.cs | 233 ++-------------------- UnitTests/View/DrawTests.cs | 2 +- UnitTests/View/Text/AutoSizeTrueTests.cs | 4 +- UnitTests/Views/CheckBoxTests.cs | 8 +- 10 files changed, 65 insertions(+), 268 deletions(-) diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 4a904419f..6ae7df30c 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -930,7 +930,7 @@ public class Slider : View } } - private string AlignText (string text, int width, Justification Justification) + private string JustifyText (string text, int width, Justification justification) { if (text is null) { @@ -947,7 +947,7 @@ public class Slider : View string s2 = new (' ', w % 2); // Note: The formatter doesn't handle all of this ??? - switch (Justification) + switch (justification) { case Justification.Justified: return TextFormatter.Justify (text, width); @@ -1293,7 +1293,7 @@ public class Slider : View switch (_config._legendsOrientation) { case Orientation.Horizontal: - text = AlignText (text, _config._innerSpacing + 1, Justification.Centered); + text = JustifyText (text, _config._innerSpacing + 1, Justification.Centered); break; case Orientation.Vertical: @@ -1311,7 +1311,7 @@ public class Slider : View break; case Orientation.Vertical: - text = AlignText (text, _config._innerSpacing + 1, Justification.Centered); + text = JustifyText (text, _config._innerSpacing + 1, Justification.Centered); break; } diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 4aab25ac1..db03e33ab 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -2057,13 +2057,13 @@ public class TableView : View /// /// Truncates or pads so that it occupies a exactly - /// using the alignment specified in (or left + /// using the justification specified in (or left /// if no style is defined) /// /// The object in this cell of the /// The string representation of /// - /// Optional style indicating custom alignment for the cell + /// Optional style indicating custom justification for the cell /// private string TruncateOrPad ( object originalCellValue, diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index fb7ed5cbd..73fbd747e 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -76,19 +76,19 @@ public class CsvEditor : Scenario new [] { _miLeft = new MenuItem ( - "_Align Left", + "_Justify Left", "", - () => Align (Justification.Left) + () => Justify (Justification.Left) ), _miRight = new MenuItem ( - "_Align Right", + "_Justify Right", "", - () => Align (Justification.Right) + () => Justify (Justification.Right) ), _miCentered = new MenuItem ( - "_Align Centered", + "_Justify Centered", "", - () => Align (Justification.Centered) + () => Justify (Justification.Centered) ), // Format requires hard typed data table, when we read a CSV everything is untyped (string) so this only works for new columns in this demo @@ -218,7 +218,7 @@ public class CsvEditor : Scenario _tableView.Update (); } - private void Align (Justification newJustification) + private void Justify (Justification newJustification) { if (NoTableLoaded ()) { diff --git a/UICatalog/Scenarios/TextFormatterDemo.cs b/UICatalog/Scenarios/TextFormatterDemo.cs index 14bd1ca0d..340385b90 100644 --- a/UICatalog/Scenarios/TextFormatterDemo.cs +++ b/UICatalog/Scenarios/TextFormatterDemo.cs @@ -75,17 +75,17 @@ public class TextFormatterDemo : Scenario } } - List alignments = GetUniqueEnumValues().ToList (); - Label [] singleLines = new Label [alignments.Count]; - Label [] multipleLines = new Label [alignments.Count]; + List justifications = GetUniqueEnumValues().ToList (); + Label [] singleLines = new Label [justifications.Count]; + Label [] multipleLines = new Label [justifications.Count]; var multiLineHeight = 5; - foreach (Justification alignment in alignments) + foreach (Justification justification in justifications) { - singleLines [(int)alignment] = new() + singleLines [(int)justification] = new() { - Justification = alignment, + Justification = justification, X = 0, Width = Dim.Fill (), @@ -94,9 +94,9 @@ public class TextFormatterDemo : Scenario Text = text }; - multipleLines [(int)alignment] = new() + multipleLines [(int)justification] = new() { - Justification = alignment, + Justification = justification, X = 0, Width = Dim.Fill (), @@ -112,33 +112,33 @@ public class TextFormatterDemo : Scenario }; app.Add (label); - foreach (Justification alignment in alignments) + foreach (Justification justification in justifications) { - label = new() { Y = Pos.Bottom (label), Text = $"{alignment}:" }; + label = new() { Y = Pos.Bottom (label), Text = $"{justification}:" }; app.Add (label); - singleLines [(int)alignment].Y = Pos.Bottom (label); - app.Add (singleLines [(int)alignment]); - label = singleLines [(int)alignment]; + singleLines [(int)justification].Y = Pos.Bottom (label); + app.Add (singleLines [(int)justification]); + label = singleLines [(int)justification]; } label = new() { Y = Pos.Bottom (label), Text = "Demonstrating multi-line and word wrap:" }; app.Add (label); - foreach (Justification alignment in alignments) + foreach (Justification justification in justifications) { - label = new() { Y = Pos.Bottom (label), Text = $"{alignment}:" }; + label = new() { Y = Pos.Bottom (label), Text = $"{justification}:" }; app.Add (label); - multipleLines [(int)alignment].Y = Pos.Bottom (label); - app.Add (multipleLines [(int)alignment]); - label = multipleLines [(int)alignment]; + multipleLines [(int)justification].Y = Pos.Bottom (label); + app.Add (multipleLines [(int)justification]); + label = multipleLines [(int)justification]; } unicodeCheckBox.Toggled += (s, e) => { - foreach (Justification alignment in alignments) + foreach (Justification justification in justifications) { - singleLines [(int)alignment].Text = e.OldValue == true ? text : unicode; - multipleLines [(int)alignment].Text = e.OldValue == true ? text : unicode; + singleLines [(int)justification].Text = e.OldValue == true ? text : unicode; + multipleLines [(int)justification].Text = e.OldValue == true ? text : unicode; } }; diff --git a/UICatalog/Scenarios/Unicode.cs b/UICatalog/Scenarios/Unicode.cs index a16887b3c..214156b8d 100644 --- a/UICatalog/Scenarios/Unicode.cs +++ b/UICatalog/Scenarios/Unicode.cs @@ -133,7 +133,7 @@ public class UnicodeInMenu : Scenario Width = Dim.Percent (50), Height = 1, Justification = Justification.Right, - Text = $"Align Right - {gitString}" + Text = $"Justify Right - {gitString}" }; Win.Add (checkBox, checkBoxRight); diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index 7145a356d..2c9e6df04 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -129,7 +129,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Four () + public void ButtonJustification_Four () { RunState runstate = null; @@ -219,7 +219,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Four_On_Too_Small_Width () + public void ButtonJustification_Four_On_Too_Small_Width () { RunState runstate = null; @@ -312,7 +312,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Four_WideOdd () + public void ButtonJustification_Four_WideOdd () { RunState runstate = null; @@ -404,7 +404,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Four_Wider () + public void ButtonJustification_Four_Wider () { RunState runstate = null; @@ -498,7 +498,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_One () + public void ButtonJustification_One () { var d = (FakeDriver)Driver; RunState runstate = null; @@ -636,7 +636,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Three () + public void ButtonJustification_Three () { RunState runstate = null; @@ -720,7 +720,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Two () + public void ButtonJustification_Two () { RunState runstate = null; @@ -798,7 +798,7 @@ public class DialogTests [Fact] [AutoInitShutdown] - public void ButtonAlignment_Two_Hidden () + public void ButtonJustification_Two_Hidden () { RunState runstate = null; var firstIteration = false; diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index a5509c7bb..de89c5394 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -219,19 +219,19 @@ public class TextFormatterTests [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit public void ClipAndJustify_Valid_Centered (string text, string justifiedText, int maxWidth) { - var align = Justification.Centered; + var justify = Justification.Centered; var textDirection = TextDirection.LeftRight_TopBottom; var tabWidth = 1; Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth); Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); Assert.True (justifiedText.GetRuneCount () <= maxWidth); Assert.True (justifiedText.GetColumns () <= maxWidth); @@ -277,19 +277,19 @@ public class TextFormatterTests [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit public void ClipAndJustify_Valid_Justified (string text, string justifiedText, int maxWidth) { - var align = Justification.Justified; + var justify = Justification.Justified; var textDirection = TextDirection.LeftRight_TopBottom; var tabWidth = 1; Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth); Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); Assert.True (justifiedText.GetRuneCount () <= maxWidth); Assert.True (justifiedText.GetColumns () <= maxWidth); @@ -328,19 +328,19 @@ public class TextFormatterTests [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit public void ClipAndJustify_Valid_Left (string text, string justifiedText, int maxWidth) { - var align = Justification.Left; + var justify = Justification.Left; var textDirection = TextDirection.LeftRight_BottomTop; var tabWidth = 1; Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth); Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); Assert.True (justifiedText.GetRuneCount () <= maxWidth); Assert.True (justifiedText.GetColumns () <= maxWidth); @@ -377,19 +377,19 @@ public class TextFormatterTests [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit public void ClipAndJustify_Valid_Right (string text, string justifiedText, int maxWidth) { - var align = Justification.Right; + var justify = Justification.Right; var textDirection = TextDirection.LeftRight_BottomTop; var tabWidth = 1; Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth); Assert.Equal ( justifiedText, - TextFormatter.ClipAndJustify (text, maxWidth, align, textDirection, tabWidth) + TextFormatter.ClipAndJustify (text, maxWidth, justify, textDirection, tabWidth) ); Assert.True (justifiedText.GetRuneCount () <= maxWidth); Assert.True (justifiedText.GetColumns () <= maxWidth); @@ -2222,176 +2222,6 @@ ssb Assert.Equal (new Size (expectedWidth, expectedHeight), tf.Size); } - - //[Theory] - //[InlineData (Justification.Left, false)] - //[InlineData (Justification.Centered, true)] - //[InlineData (Justification.Right, false)] - //[InlineData (Justification.Justified, true)] - //public void TestSize_DirectionChange_AutoSize_True_Or_False_Horizontal ( - // Justification Justification, - // bool autoSize - //) - //{ - // var tf = new TextFormatter - // { - // Direction = TextDirection.LeftRight_TopBottom, Text = "你你", Alignment = Justification, AutoSize = autoSize - // }; - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - - // tf.Direction = TextDirection.TopBottom_LeftRight; - - // if (autoSize/* && Justification != Justification.Justified*/) - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - // else - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - //} - - //[Theory] - //[InlineData (Justification.Top, false)] - //[InlineData (Justification.Centered, true)] - //[InlineData (Justification.Bottom, false)] - //[InlineData (Justification.Justified, true)] - //public void TestSize_DirectionChange_AutoSize_True_Or_False_Vertical ( - // Justification Justification, - // bool autoSize - //) - //{ - // var tf = new TextFormatter - // { - // Direction = TextDirection.TopBottom_LeftRight, - // Text = "你你", - // VerticalAlignment = Justification, - // AutoSize = autoSize - // }; - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - - // tf.Direction = TextDirection.LeftRight_TopBottom; - - // if (autoSize/* && Justification != Justification.Justified*/) - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - // else - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - //} - - //[Theory] - //[InlineData (TextDirection.LeftRight_TopBottom, false)] - //[InlineData (TextDirection.LeftRight_TopBottom, true)] - //[InlineData (TextDirection.TopBottom_LeftRight, false)] - //[InlineData (TextDirection.TopBottom_LeftRight, true)] - //public void TestSize_SizeChange_AutoSize_True_Or_False (TextDirection textDirection, bool autoSize) - //{ - // var tf = new TextFormatter { Direction = textDirection, Text = "你你", AutoSize = autoSize }; - - // if (textDirection == TextDirection.LeftRight_TopBottom) - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - // else - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - - // tf.Size = new (1, 1); - - // if (autoSize) - // { - // if (textDirection == TextDirection.LeftRight_TopBottom) - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - // else - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - // } - // else - // { - // Assert.Equal (1, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - //} - - //[Theory] - //[InlineData (Justification.Left, false)] - //[InlineData (Justification.Centered, true)] - //[InlineData (Justification.Right, false)] - //[InlineData (Justification.Justified, true)] - //public void TestSize_SizeChange_AutoSize_True_Or_False_Horizontal (Justification Justification, bool autoSize) - //{ - // var tf = new TextFormatter - // { - // Direction = TextDirection.LeftRight_TopBottom, Text = "你你", Alignment = Justification, AutoSize = autoSize - // }; - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - - // tf.Size = new (1, 1); - - // if (autoSize) - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - // else - // { - // Assert.Equal (1, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - //} - - //[Theory] - //[InlineData (Justification.Top, false)] - //[InlineData (Justification.Centered, true)] - //[InlineData (Justification.Bottom, false)] - //[InlineData (Justification.Justified, true)] - //public void TestSize_SizeChange_AutoSize_True_Or_False_Vertical ( - // Justification Justification, - // bool autoSize - //) - //{ - // var tf = new TextFormatter - // { - // Direction = TextDirection.TopBottom_LeftRight, - // Text = "你你", - // VerticalAlignment = Justification, - // AutoSize = autoSize - // }; - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - - // tf.Size = new (1, 1); - - // if (autoSize) - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - // else - // { - // Assert.Equal (1, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - //} - [Theory] [InlineData ("你", TextDirection.LeftRight_TopBottom, false, 0, 0)] [InlineData ("你", TextDirection.LeftRight_TopBottom, true, 2, 1)] @@ -2408,39 +2238,6 @@ ssb Assert.Equal (new Size (expectedWidth, expectedHeight), tf.Size); } - //[Theory] - //[InlineData (TextDirection.LeftRight_TopBottom, false)] - //[InlineData (TextDirection.LeftRight_TopBottom, true)] - //[InlineData (TextDirection.TopBottom_LeftRight, false)] - //[InlineData (TextDirection.TopBottom_LeftRight, true)] - //public void TestSize_TextChange (TextDirection textDirection, bool autoSize) - //{ - // var tf = new TextFormatter { Direction = textDirection, Text = "你", AutoSize = autoSize }; - // Assert.Equal (new Size (2, 1), tf.Size); - // tf.Text = "你你"; - - // Assert.Equal (autoSize, tf.AutoSize); - - // if (autoSize) - // { - // if (textDirection == TextDirection.LeftRight_TopBottom) - // { - // Assert.Equal (4, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - // else - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (2, tf.Size.Height); - // } - // } - // else - // { - // Assert.Equal (2, tf.Size.Width); - // Assert.Equal (1, tf.Size.Height); - // } - //} - [Fact] public void WordWrap_BigWidth () { @@ -6235,12 +6032,12 @@ B")] ****** 0******")] - public void Draw_Text_Alignment (string text, Justification horizontalTextAlignment, Justification Justification, TextDirection textDirection, string expectedText) + public void Draw_Text_Justification (string text, Justification horizontalTextJustification, Justification justification, TextDirection textDirection, string expectedText) { TextFormatter tf = new () { - Justification = horizontalTextAlignment, - VerticalJustification = Justification, + Justification = horizontalTextJustification, + VerticalJustification = justification, Direction = textDirection, Size = new (7, 7), Text = text diff --git a/UnitTests/View/DrawTests.cs b/UnitTests/View/DrawTests.cs index 8d1043046..b28e74c98 100644 --- a/UnitTests/View/DrawTests.cs +++ b/UnitTests/View/DrawTests.cs @@ -332,7 +332,7 @@ public class DrawTests (ITestOutputHelper _output) [Fact] [AutoInitShutdown] [Trait ("Category", "Output")] - public void Colors_On_TextAlignment_Right_And_Bottom () + public void Colors_On_TextJustification_Right_And_Bottom () { var viewRight = new View { diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index af5c0cc8c..e89b791c2 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -1788,7 +1788,7 @@ Y [AutoInitShutdown] [InlineData (true)] [InlineData (false)] - public void View_Draw_Horizontal_Simple_TextAlignments (bool autoSize) + public void View_Draw_Horizontal_Simple_TextJustifications (bool autoSize) { var text = "Hello World"; var width = 20; @@ -1912,7 +1912,7 @@ Y [AutoInitShutdown] [InlineData (true)] [InlineData (false)] - public void View_Draw_Vertical_Simple_TextAlignments (bool autoSize) + public void View_Draw_Vertical_Simple_TextJustifications (bool autoSize) { var text = "Hello World"; var height = 20; diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index 0ff1f75c3..53335ffce 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -244,7 +244,7 @@ public class CheckBoxTests [Fact] [AutoInitShutdown] - public void TextAlignment_Centered () + public void TextJustification_Centered () { var checkBox = new CheckBox { @@ -294,7 +294,7 @@ public class CheckBoxTests [Fact] [AutoInitShutdown] - public void TextAlignment_Justified () + public void TextJustification_Justified () { var checkBox1 = new CheckBox { @@ -361,7 +361,7 @@ public class CheckBoxTests [Fact] [AutoInitShutdown] - public void TextAlignment_Left () + public void TextJustification_Left () { var checkBox = new CheckBox { @@ -410,7 +410,7 @@ public class CheckBoxTests [Fact] [AutoInitShutdown] - public void TextAlignment_Right () + public void TextJustification_Right () { var checkBox = new CheckBox {