浏览代码

Alignment->Justification

Tig 1 年之前
父节点
当前提交
37073d29b5

+ 2 - 2
Terminal.Gui/Drawing/Thickness.cs

@@ -232,8 +232,8 @@ public class Thickness : IEquatable<Thickness>
             var tf = new TextFormatter
             {
                 Text = label is null ? string.Empty : $"{label} {this}",
-                Alignment = Justification.Centered,
-                VerticalAlignment = Justification.Bottom,
+                Justification = Justification.Centered,
+                VerticalJustification = Justification.Bottom,
                 AutoSize = true
             };
             tf.Draw (rect, Application.Driver.CurrentAttribute, Application.Driver.CurrentAttribute, rect);

+ 61 - 58
Terminal.Gui/Text/TextFormatter.cs

@@ -1,7 +1,9 @@
+using System.Diagnostics;
+
 namespace Terminal.Gui;
 
 /// <summary>
-///     Provides text formatting. Supports <see cref="View.HotKey"/>s, horizontal alignment, vertical alignment,
+///     Provides text formatting. Supports <see cref="View.HotKey"/>s, horizontal justification, vertical justification,
 ///     multiple lines, and word-based line wrap.
 /// </summary>
 public class TextFormatter
@@ -15,25 +17,24 @@ public class TextFormatter
     private Size _size;
     private int _tabWidth = 4;
     private string _text;
-    private Justification _textAlignment;
+    private Justification _textJustification;
     private TextDirection _textDirection;
-    private Justification _textVerticalAlignment;
+    private Justification _textVerticalJustification;
     private bool _wordWrap = true;
 
-    /// <summary>Controls the horizontal text-alignment property.</summary>
-    /// <value>The text alignment.</value>
-    public Justification Alignment
+    /// <summary>Get or sets the horizontal text justification.</summary>
+    /// <value>The text justification.</value>
+    public Justification Justification
     {
-        get => _textAlignment;
-        set => _textAlignment = EnableNeedsFormat (value);
+        get => _textJustification;
+        set => _textJustification = EnableNeedsFormat (value);
     }
 
     /// <summary>Gets or sets whether the <see cref="Size"/> should be automatically changed to fit the <see cref="Text"/>.</summary>
     /// <remarks>
     ///     <para>Used when <see cref="View"/> is using <see cref="Dim.Auto"/> to resize the view's <see cref="View.Viewport"/> to fit <see cref="Size"/>.</para>
     ///     <para>
-    ///         AutoSize is ignored if <see cref="Justification.Justified"/> and
-    ///         <see cref="Justification.Justified"/> are used.
+    ///         AutoSize is ignored if <see cref="Justification.Justified"/> is used.
     ///     </para>
     /// </remarks>
     public bool AutoSize
@@ -68,9 +69,8 @@ public class TextFormatter
     ///     Only the first HotKey specifier found in <see cref="Text"/> is supported.
     /// </remarks>
     /// <param name="isWidth">
-    ///     If <see langword="true"/> (the default) the width required for the HotKey specifier is returned. Otherwise the
-    ///     height
-    ///     is returned.
+    ///     If <see langword="true"/> (the default) the width required for the HotKey specifier is returned. Otherwise, the
+    ///     height is returned.
     /// </param>
     /// <returns>
     ///     The number of characters required for the <see cref="TextFormatter.HotKeySpecifier"/>. If the text
@@ -97,8 +97,8 @@ public class TextFormatter
     /// </summary>
     public int CursorPosition { get; internal set; }
 
-    /// <summary>Controls the text-direction property.</summary>
-    /// <value>The text vertical alignment.</value>
+    /// <summary>Gets or sets the text-direction.</summary>
+    /// <value>The text direction.</value>
     public TextDirection Direction
     {
         get => _textDirection;
@@ -112,8 +112,7 @@ public class TextFormatter
             }
         }
     }
-
-
+    
     /// <summary>
     ///     Determines if the viewport width will be used or only the text width will be used,
     ///     If <see langword="true"/> all the viewport area will be filled with whitespaces and the same background color
@@ -223,12 +222,12 @@ public class TextFormatter
         }
     }
 
-    /// <summary>Controls the vertical text-alignment property.</summary>
-    /// <value>The text vertical alignment.</value>
-    public Justification VerticalAlignment
+    /// <summary>Gets or sets the vertical text-justification.</summary>
+    /// <value>The text vertical justification.</value>
+    public Justification VerticalJustification
     {
-        get => _textVerticalAlignment;
-        set => _textVerticalAlignment = EnableNeedsFormat (value);
+        get => _textVerticalJustification;
+        set => _textVerticalJustification = EnableNeedsFormat (value);
     }
 
     /// <summary>Gets or sets whether word wrap will be used to fit <see cref="Text"/> to <see cref="Size"/>.</summary>
@@ -318,10 +317,10 @@ public class TextFormatter
 
             // When text is justified, we lost left or right, so we use the direction to align. 
 
-            int x, y;
+            int x = 0, y = 0;
 
-            // Horizontal Alignment
-            if (Alignment is Justification.Right)
+            // Horizontal Justification
+            if (Justification is Justification.Right)
             {
                 if (isVertical)
                 {
@@ -336,7 +335,7 @@ public class TextFormatter
                     CursorPosition = screen.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0);
                 }
             }
-            else if (Alignment is Justification.Left)
+            else if (Justification is Justification.Left)
             {
                 if (isVertical)
                 {
@@ -352,7 +351,7 @@ public class TextFormatter
 
                 CursorPosition = _hotKeyPos > -1 ? _hotKeyPos : 0;
             }
-            else if (Alignment is Justification.Justified)
+            else if (Justification is Justification.Justified)
             {
                 if (isVertical)
                 {
@@ -375,7 +374,7 @@ public class TextFormatter
 
                 CursorPosition = _hotKeyPos > -1 ? _hotKeyPos : 0;
             }
-            else if (Alignment is Justification.Centered)
+            else if (Justification is Justification.Centered)
             {
                 if (isVertical)
                 {
@@ -395,11 +394,13 @@ public class TextFormatter
             }
             else
             {
-                throw new ArgumentOutOfRangeException ($"{nameof (Alignment)}");
+                Debug.WriteLine ($"Unsupported Justification: {nameof (VerticalJustification)}");
+
+                return;
             }
 
-            // Vertical Alignment
-            if (VerticalAlignment is Justification.Bottom)
+            // Vertical Justification
+            if (VerticalJustification is Justification.Bottom)
             {
                 if (isVertical)
                 {
@@ -410,7 +411,7 @@ public class TextFormatter
                     y = screen.Bottom - linesFormatted.Count + line;
                 }
             }
-            else if (VerticalAlignment is Justification.Top)
+            else if (VerticalJustification is Justification.Top)
             {
                 if (isVertical)
                 {
@@ -421,7 +422,7 @@ public class TextFormatter
                     y = screen.Top + line;
                 }
             }
-            else if (VerticalAlignment is Justification.Justified)
+            else if (VerticalJustification is Justification.Justified)
             {
                 if (isVertical)
                 {
@@ -435,7 +436,7 @@ public class TextFormatter
                         line < linesFormatted.Count - 1 ? screen.Height - interval <= 1 ? screen.Top + 1 : screen.Top + line * interval : screen.Bottom - 1;
                 }
             }
-            else if (VerticalAlignment is Justification.Centered)
+            else if (VerticalJustification is Justification.Centered)
             {
                 if (isVertical)
                 {
@@ -450,7 +451,9 @@ public class TextFormatter
             }
             else
             {
-                throw new ArgumentOutOfRangeException ($"{nameof (VerticalAlignment)}");
+               Debug.WriteLine ($"Unsupported Justification: {nameof (VerticalJustification)}");
+
+               return;
             }
 
             int colOffset = screen.X < 0 ? Math.Abs (screen.X) : 0;
@@ -471,8 +474,8 @@ public class TextFormatter
                 {
                     if (idx < 0
                         || (isVertical
-                                ? VerticalAlignment != Justification.Bottom && current < 0
-                                : Alignment != Justification.Right && x + current + colOffset < 0))
+                                ? VerticalJustification != Justification.Bottom && current < 0
+                                : Justification != Justification.Right && x + current + colOffset < 0))
                     {
                         current++;
 
@@ -561,7 +564,7 @@ public class TextFormatter
 
                 if (HotKeyPos > -1 && idx == HotKeyPos)
                 {
-                    if ((isVertical && VerticalAlignment == Justification.Justified) || (!isVertical && Alignment == Justification.Justified))
+                    if ((isVertical && VerticalJustification == Justification.Justified) || (!isVertical && Justification == Justification.Justified))
                     {
                         CursorPosition = idx - start;
                     }
@@ -699,7 +702,7 @@ public class TextFormatter
                 _lines = Format (
                                  text,
                                  Size.Height,
-                                 VerticalAlignment == Justification.Justified,
+                                 VerticalJustification == Justification.Justified,
                                  Size.Width > colsWidth && WordWrap,
                                  PreserveTrailingSpaces,
                                  TabWidth,
@@ -723,7 +726,7 @@ public class TextFormatter
                 _lines = Format (
                                  text,
                                  Size.Width,
-                                 Alignment == Justification.Justified,
+                                 Justification == Justification.Justified,
                                  Size.Height > 1 && WordWrap,
                                  PreserveTrailingSpaces,
                                  TabWidth,
@@ -977,7 +980,7 @@ public class TextFormatter
         // if value is not wide enough
         if (text.EnumerateRunes ().Sum (c => c.GetColumns ()) < width)
         {
-            // pad it out with spaces to the given alignment
+            // pad it out with spaces to the given Justification
             int toPad = width - text.EnumerateRunes ().Sum (c => c.GetColumns ());
 
             return text + new string (' ', toPad);
@@ -1031,7 +1034,7 @@ public class TextFormatter
         List<Rune> runes = StripCRLF (text).ToRuneList ();
 
         int start = Math.Max (
-                              !runes.Contains ((Rune)' ') && textFormatter is { VerticalAlignment: Justification.Bottom } && IsVerticalDirection (textDirection)
+                              !runes.Contains ((Rune)' ') && textFormatter is { VerticalJustification: Justification.Bottom } && IsVerticalDirection (textDirection)
                                   ? runes.Count - width
                                   : 0,
                               0);
@@ -1249,7 +1252,7 @@ public class TextFormatter
     ///     The number of columns to clip the text to. Text longer than <paramref name="width"/> will be
     ///     clipped.
     /// </param>
-    /// <param name="talign">Alignment.</param>
+    /// <param name="textJustification">Justification.</param>
     /// <param name="textDirection">The text direction.</param>
     /// <param name="tabWidth">The number of columns used for a tab.</param>
     /// <param name="textFormatter"><see cref="TextFormatter"/> instance to access any of his objects.</param>
@@ -1257,13 +1260,13 @@ public class TextFormatter
     public static string ClipAndJustify (
         string text,
         int width,
-        Justification talign,
+        Justification textJustification,
         TextDirection textDirection = TextDirection.LeftRight_TopBottom,
         int tabWidth = 0,
         TextFormatter textFormatter = null
     )
     {
-        return ClipAndJustify (text, width, talign == Justification.Justified, textDirection, tabWidth, textFormatter);
+        return ClipAndJustify (text, width, textJustification == Justification.Justified, textDirection, tabWidth, textFormatter);
     }
 
     /// <summary>Justifies text within a specified width.</summary>
@@ -1304,12 +1307,12 @@ public class TextFormatter
         {
             if (IsHorizontalDirection (textDirection))
             {
-                if (textFormatter is { Alignment: Justification.Right })
+                if (textFormatter is { Justification: Justification.Right })
                 {
                     return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection);
                 }
 
-                if (textFormatter is { Alignment: Justification.Centered })
+                if (textFormatter is { Justification: Justification.Centered })
                 {
                     return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
                 }
@@ -1319,12 +1322,12 @@ public class TextFormatter
 
             if (IsVerticalDirection (textDirection))
             {
-                if (textFormatter is { VerticalAlignment: Justification.Bottom })
+                if (textFormatter is { VerticalJustification: Justification.Bottom })
                 {
                     return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection);
                 }
 
-                if (textFormatter is { VerticalAlignment: Justification.Centered })
+                if (textFormatter is { VerticalJustification: Justification.Centered })
                 {
                     return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
                 }
@@ -1342,14 +1345,14 @@ public class TextFormatter
 
         if (IsHorizontalDirection (textDirection))
         {
-            if (textFormatter is { Alignment: Justification.Right })
+            if (textFormatter is { Justification: Justification.Right })
             {
                 if (GetRuneWidth (text, tabWidth, textDirection) > width)
                 {
                     return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection);
                 }
             }
-            else if (textFormatter is { Alignment: Justification.Centered })
+            else if (textFormatter is { Justification: Justification.Centered })
             {
                 return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
             }
@@ -1361,14 +1364,14 @@ public class TextFormatter
 
         if (IsVerticalDirection (textDirection))
         {
-            if (textFormatter is { VerticalAlignment: Justification.Bottom })
+            if (textFormatter is { VerticalJustification: Justification.Bottom })
             {
                 if (runes.Count - zeroLength > width)
                 {
                     return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection);
                 }
             }
-            else if (textFormatter is { VerticalAlignment: Justification.Centered })
+            else if (textFormatter is { VerticalJustification: Justification.Centered })
             {
                 return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection);
             }
@@ -1472,10 +1475,10 @@ public class TextFormatter
         return s.ToString ();
     }
 
-    /// <summary>Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.</summary>
+    /// <summary>Formats text into lines, applying text justification and optionally wrapping text to new lines on word boundaries.</summary>
     /// <param name="text"></param>
     /// <param name="width">The number of columns to constrain the text to for word wrapping and clipping.</param>
-    /// <param name="talign">Specifies how the text will be aligned horizontally.</param>
+    /// <param name="textJustification">Specifies how the text will be justified horizontally.</param>
     /// <param name="wordWrap">
     ///     If <see langword="true"/>, the text will be wrapped to new lines no longer than
     ///     <paramref name="width"/>. If <see langword="false"/>, forces text to fit a single line. Line breaks are converted
@@ -1498,7 +1501,7 @@ public class TextFormatter
     public static List<string> Format (
         string text,
         int width,
-        Justification talign,
+        Justification textJustification,
         bool wordWrap,
         bool preserveTrailingSpaces = false,
         int tabWidth = 0,
@@ -1510,7 +1513,7 @@ public class TextFormatter
         return Format (
                        text,
                        width,
-                       talign == Justification.Justified,
+                       textJustification == Justification.Justified,
                        wordWrap,
                        preserveTrailingSpaces,
                        tabWidth,
@@ -1520,7 +1523,7 @@ public class TextFormatter
                       );
     }
 
-    /// <summary>Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries.</summary>
+    /// <summary>Formats text into lines, applying text justification and optionally wrapping text to new lines on word boundaries.</summary>
     /// <param name="text"></param>
     /// <param name="width">The number of columns to constrain the text to for word wrapping and clipping.</param>
     /// <param name="justify">Specifies whether the text should be justified.</param>

+ 9 - 9
Terminal.Gui/View/ViewText.cs

@@ -80,19 +80,19 @@ public partial class View
     public event EventHandler<StateEventArgs<string>> TextChanged;
 
     /// <summary>
-    ///     Gets or sets how the View's <see cref="Text"/> is aligned horizontally when drawn. Changing this property will
+    ///     Gets or sets how the View's <see cref="Text"/> is justified horizontally when drawn. Changing this property will
     ///     redisplay the <see cref="View"/>.
     /// </summary>
     /// <remarks>
     ///     <para> <see cref="View.Width"/> or <see cref="View.Height"/> are using <see cref="Dim.DimAutoStyle.Text"/>, the <see cref="ContentSize"/> will be adjusted to fit the text.</para>
     /// </remarks>
-    /// <value>The text alignment.</value>
+    /// <value>The text justification.</value>
     public virtual Justification Justification
     {
-        get => TextFormatter.Alignment;
+        get => TextFormatter.Justification;
         set
         {
-            TextFormatter.Alignment = value;
+            TextFormatter.Justification = value;
             UpdateTextFormatterText ();
             OnResizeNeeded ();
         }
@@ -105,7 +105,7 @@ public partial class View
     /// <remarks>
     ///     <para> <see cref="View.Width"/> or <see cref="View.Height"/> are using <see cref="Dim.DimAutoStyle.Text"/>, the <see cref="ContentSize"/> will be adjusted to fit the text.</para>
     /// </remarks>
-    /// <value>The text alignment.</value>
+    /// <value>The text direction.</value>
     public virtual TextDirection TextDirection
     {
         get => TextFormatter.Direction;
@@ -122,20 +122,20 @@ public partial class View
     public TextFormatter TextFormatter { get; init; } = new () { };
 
     /// <summary>
-    ///     Gets or sets how the View's <see cref="Text"/> is aligned vertically when drawn. Changing this property will
+    ///     Gets or sets how the View's <see cref="Text"/> is justified vertically when drawn. Changing this property will
     ///     redisplay
     ///     the <see cref="View"/>.
     /// </summary>
     /// <remarks>
     ///     <para> <see cref="View.Width"/> or <see cref="View.Height"/> are using <see cref="Dim.DimAutoStyle.Text"/>, the <see cref="ContentSize"/> will be adjusted to fit the text.</para>
     /// </remarks>
-    /// <value>The text alignment.</value>
+    /// <value>The vertical text justification.</value>
     public virtual Justification VerticalJustification
     {
-        get => TextFormatter.VerticalAlignment;
+        get => TextFormatter.VerticalJustification;
         set
         {
-            TextFormatter.VerticalAlignment = value;
+            TextFormatter.VerticalJustification = value;
             SetNeedsDisplay ();
         }
     }

+ 5 - 5
Terminal.Gui/Views/Dialog.cs

@@ -51,7 +51,7 @@ public class Dialog : Window
         ColorScheme = Colors.ColorSchemes ["Dialog"];
 
         Modal = true;
-        ButtonAlignment = DefaultButtonJustification;
+        ButtonJustification = DefaultButtonJustification;
 
         AddCommand (
                     Command.QuitToplevel,
@@ -96,9 +96,9 @@ public class Dialog : Window
         }
     }
 
-    // TODO: Update button.X = Pos.Justify when alignment changes
-    /// <summary>Determines how the <see cref="Dialog"/> <see cref="Button"/>s are aligned along the bottom of the dialog.</summary>
-    public Justification ButtonAlignment { get; set; }
+    // TODO: Update button.X = Pos.Justify when justification changes
+    /// <summary>Determines how the <see cref="Dialog"/> <see cref="Button"/>s are justified along the bottom of the dialog.</summary>
+    public Justification ButtonJustification { get; set; }
 
     /// <summary>Optional buttons to lay out at the bottom of the dialog.</summary>
     public Button [] Buttons
@@ -136,7 +136,7 @@ public class Dialog : Window
             return;
         }
 
-        button.X = Pos.Justify (ButtonAlignment);
+        button.X = Pos.Justify (ButtonJustification);
         button.Y = Pos.AnchorEnd () - 1;
 
         _buttons.Add (button);

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

@@ -891,7 +891,7 @@ internal sealed class Menu : View
                     var tf = new TextFormatter
                     {
                         AutoSize = true,
-                        Alignment = Justification.Centered, HotKeySpecifier = MenuBar.HotKeySpecifier, Text = textToDraw
+                        Justification = Justification.Centered, HotKeySpecifier = MenuBar.HotKeySpecifier, Text = textToDraw
                     };
 
                     // The -3 is left/right border + one space (not sure what for)

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

@@ -181,7 +181,7 @@ public class ProgressBar : View
 
         if (ProgressBarFormat != ProgressBarFormat.Simple && !_isActivity)
         {
-            var tf = new TextFormatter { Alignment = Justification.Centered, Text = Text };
+            var tf = new TextFormatter { Justification = Justification.Centered, Text = Text };
             var attr = new Attribute (ColorScheme.HotNormal.Foreground, ColorScheme.HotNormal.Background);
 
             if (_fraction > .5)

+ 21 - 21
Terminal.Gui/Views/TableView/ColumnStyle.cs

@@ -1,17 +1,17 @@
 namespace Terminal.Gui;
 
 /// <summary>
-///     Describes how to render a given column in  a <see cref="TableView"/> including <see cref="Alignment"/> and
+///     Describes how to render a given column in  a <see cref="TableView"/> including <see cref="Justification"/> and
 ///     textual representation of cells (e.g. date formats)
 ///     <a href="../docs/tableview.md">See TableView Deep Dive for more information</a>.
 /// </summary>
 public class ColumnStyle
 {
     /// <summary>
-    ///     Defines a delegate for returning custom alignment per cell based on cell values.  When specified this will
-    ///     override <see cref="Alignment"/>
+    ///     Defines a delegate for returning custom justification per cell based on cell values. When specified this will
+    ///     override <see cref="Justification"/>
     /// </summary>
-    public Func<object, Justification> AlignmentGetter;
+    public Func<object, Justification> JustificationGetter;
 
     /// <summary>
     ///     Defines a delegate for returning a custom color scheme per cell based on cell values. Return null for the
@@ -20,26 +20,26 @@ public class ColumnStyle
     public CellColorGetterDelegate ColorGetter;
 
     /// <summary>
-    ///     Defines a delegate for returning custom representations of cell values.  If not set then
-    ///     <see cref="object.ToString()"/> is used.  Return values from your delegate may be truncated e.g. based on
+    ///     Defines a delegate for returning custom representations of cell values. If not set then
+    ///     <see cref="object.ToString()"/> is used. Return values from your delegate may be truncated e.g. based on
     ///     <see cref="MaxWidth"/>
     /// </summary>
     public Func<object, string> RepresentationGetter;
 
-    private bool visible = true;
+    private bool _visible = true;
 
     /// <summary>
-    ///     Defines the default alignment for all values rendered in this column.  For custom alignment based on cell
-    ///     contents use <see cref="AlignmentGetter"/>.
+    ///     Defines the default justification for all values rendered in this column. For custom justification based on cell
+    ///     contents use <see cref="JustificationGetter"/>.
     /// </summary>
-    public Justification Alignment { get; set; }
+    public Justification Justification { get; set; }
 
     /// <summary>Defines the format for values e.g. "yyyy-MM-dd" for dates</summary>
     public string Format { get; set; }
 
     /// <summary>
-    ///     Set the maximum width of the column in characters.  This value will be ignored if more than the tables
-    ///     <see cref="TableView.MaxCellWidth"/>.  Defaults to <see cref="TableView.DefaultMaxCellWidth"/>
+    ///     Set the maximum width of the column in characters. This value will be ignored if more than the tables
+    ///     <see cref="TableView.MaxCellWidth"/>. Defaults to <see cref="TableView.DefaultMaxCellWidth"/>
     /// </summary>
     public int MaxWidth { get; set; } = TableView.DefaultMaxCellWidth;
 
@@ -47,7 +47,7 @@ public class ColumnStyle
     public int MinAcceptableWidth { get; set; } = TableView.DefaultMinAcceptableWidth;
 
     /// <summary>
-    ///     Set the minimum width of the column in characters.  Setting this will ensure that even when a column has short
+    ///     Set the minimum width of the column in characters. Setting this will ensure that even when a column has short
     ///     content/header it still fills a given width of the control.
     ///     <para>
     ///         This value will be ignored if more than the tables <see cref="TableView.MaxCellWidth"/> or the
@@ -64,24 +64,24 @@ public class ColumnStyle
     /// <remarks>If <see cref="MaxWidth"/> is 0 then <see cref="Visible"/> will always return false.</remarks>
     public bool Visible
     {
-        get => MaxWidth >= 0 && visible;
-        set => visible = value;
+        get => MaxWidth >= 0 && _visible;
+        set => _visible = value;
     }
 
     /// <summary>
-    ///     Returns the alignment for the cell based on <paramref name="cellValue"/> and <see cref="AlignmentGetter"/>/
-    ///     <see cref="Alignment"/>
+    ///     Returns the justification for the cell based on <paramref name="cellValue"/> and <see cref="JustificationGetter"/>/
+    ///     <see cref="Justification"/>
     /// </summary>
     /// <param name="cellValue"></param>
     /// <returns></returns>
-    public Justification GetAlignment (object cellValue)
+    public Justification GetJustification (object cellValue)
     {
-        if (AlignmentGetter is { })
+        if (JustificationGetter is { })
         {
-            return AlignmentGetter (cellValue);
+            return JustificationGetter (cellValue);
         }
 
-        return Alignment;
+        return Justification;
     }
 
     /// <summary>

+ 2 - 2
Terminal.Gui/Views/TableView/TableStyle.cs

@@ -15,11 +15,11 @@ public class TableStyle
     /// </summary>
     public bool AlwaysUseNormalColorForVerticalCellLines { get; set; } = false;
 
-    /// <summary>Collection of columns for which you want special rendering (e.g. custom column lengths, text alignment etc)</summary>
+    /// <summary>Collection of columns for which you want special rendering (e.g. custom column lengths, text justification, etc.)</summary>
     public Dictionary<int, ColumnStyle> ColumnStyles { get; set; } = new ();
 
     /// <summary>
-    ///     Determines rendering when the last column in the table is visible but it's content or
+    ///     Determines rendering when the last column in the table is visible, but it's content or
     ///     <see cref="ColumnStyle.MaxWidth"/> is less than the remaining space in the control.  True (the default) will expand
     ///     the column to fill the remaining bounds of the control.  False will draw a column ending line and leave a blank
     ///     column that cannot be selected in the remaining space.

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

@@ -2085,7 +2085,7 @@ public class TableView : View
                         - (representation.EnumerateRunes ().Sum (c => c.GetColumns ())
                            + 1 /*leave 1 space for cell boundary*/);
 
-            switch (colStyle?.GetAlignment (originalCellValue) ?? Justification.Left)
+            switch (colStyle?.GetJustification (originalCellValue) ?? Justification.Left)
             {
                 case Justification.Left:
                     return representation + new string (' ', toPad);

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

@@ -709,7 +709,7 @@ namespace Terminal.Gui
             return true;
         }
 
-        /// <summary>Margins for text alignment.</summary>
+        /// <summary>Margins for text justification.</summary>
         /// <param name="width">Total width</param>
         /// <returns>Left and right margins</returns>
         private (int left, int right) GetMargins (int width)

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

@@ -85,7 +85,7 @@ public class Wizard : Dialog
     {
         // Using Justify causes the Back and Next buttons to be hard justified against
         // the left and right edge
-        ButtonAlignment = Justification.Justified;
+        ButtonJustification = Justification.Justified;
         BorderStyle = LineStyle.Double;
 
         //// Add a horiz separator

+ 1 - 1
UICatalog/Scenarios/Buttons.cs

@@ -209,7 +209,7 @@ public class Buttons : Scenario
 
         var label = new Label
         {
-            X = 2, Y = Pos.Bottom (computedFrame) + 1, Text = "Text Alignment (changes the four buttons above): "
+            X = 2, Y = Pos.Bottom (computedFrame) + 1, Text = "Text Justification (changes the four buttons above): "
         };
         main.Add (label);
 

+ 2 - 2
UICatalog/Scenarios/ComputedLayout.cs

@@ -86,7 +86,7 @@ public class ComputedLayout : Scenario
         var i = 1;
         var txt = "Resize the terminal to see computed layout in action.";
         List<Label> labelList = new ();
-        labelList.Add (new Label { Text = "The lines below show different TextAlignments" });
+        labelList.Add (new Label { Text = "The lines below show different justification" });
 
         labelList.Add (
                        new Label
@@ -148,7 +148,7 @@ public class ComputedLayout : Scenario
                                  };
         i = 1;
         labelList = new List<Label> ();
-        labelList.Add (new Label { Text = "The lines below show different TextAlignments" });
+        labelList.Add (new Label { Text = "The lines below show different justifications" });
 
         labelList.Add (
                        new Label

+ 8 - 8
UICatalog/Scenarios/CsvEditor.cs

@@ -218,7 +218,7 @@ public class CsvEditor : Scenario
         _tableView.Update ();
     }
 
-    private void Align (Justification newAlignment)
+    private void Align (Justification newJustification)
     {
         if (NoTableLoaded ())
         {
@@ -226,11 +226,11 @@ public class CsvEditor : Scenario
         }
 
         ColumnStyle style = _tableView.Style.GetOrCreateColumnStyle (_tableView.SelectedColumn);
-        style.Alignment = newAlignment;
+        style.Justification = newJustification;
 
-        _miLeft.Checked = style.Alignment == Justification.Left;
-        _miRight.Checked = style.Alignment == Justification.Right;
-        _miCentered.Checked = style.Alignment == Justification.Centered;
+        _miLeft.Checked = style.Justification == Justification.Left;
+        _miRight.Checked = style.Justification == Justification.Right;
+        _miCentered.Checked = style.Justification == Justification.Centered;
 
         _tableView.Update ();
     }
@@ -437,9 +437,9 @@ public class CsvEditor : Scenario
 
         ColumnStyle style = _tableView.Style.GetColumnStyleIfAny (_tableView.SelectedColumn);
 
-        _miLeft.Checked = style?.Alignment == Justification.Left;
-        _miRight.Checked = style?.Alignment == Justification.Right;
-        _miCentered.Checked = style?.Alignment == Justification.Centered;
+        _miLeft.Checked = style?.Justification == Justification.Left;
+        _miRight.Checked = style?.Justification == Justification.Right;
+        _miCentered.Checked = style?.Justification == Justification.Centered;
     }
 
     private void Open ()

+ 1 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -282,7 +282,7 @@ public class Dialogs : Scenario
             dialog = new()
             {
                 Title = titleEdit.Text,
-                ButtonAlignment = (Justification)styleRadioGroup.SelectedItem,
+                ButtonJustification = (Justification)styleRadioGroup.SelectedItem,
                 Buttons = buttons.ToArray ()
             };
 

+ 4 - 4
UICatalog/Scenarios/TableEditor.cs

@@ -1107,12 +1107,12 @@ public class TableEditor : Scenario
     {
         _tableView.Style.ColumnStyles.Clear ();
 
-        var alignMid = new ColumnStyle { Alignment = Justification.Centered };
-        var alignRight = new ColumnStyle { Alignment = Justification.Right };
+        var alignMid = new ColumnStyle { Justification = Justification.Centered };
+        var alignRight = new ColumnStyle { Justification = Justification.Right };
 
         var dateFormatStyle = new ColumnStyle
         {
-            Alignment = Justification.Right,
+            Justification = Justification.Right,
             RepresentationGetter = v =>
                                        v is DateTime d ? d.ToString ("yyyy-MM-dd") : v.ToString ()
         };
@@ -1121,7 +1121,7 @@ public class TableEditor : Scenario
         {
             Format = "0.##",
             MinWidth = 10,
-            AlignmentGetter = v => v is double d
+            JustificationGetter = v => v is double d
                                        ?
 
                                        // align negative values right

+ 0 - 142
UICatalog/Scenarios/TextAlignments.cs

@@ -1,142 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Terminal.Gui;
-
-namespace UICatalog.Scenarios;
-
-[ScenarioMetadata ("Simple Text Alignment", "Demonstrates horizontal text alignment")]
-[ScenarioCategory ("Text and Formatting")]
-public class TextAlignments : Scenario
-{
-    public override void Setup ()
-    {
-        Win.X = 10;
-        Win.Width = Dim.Fill (10);
-
-        var txt = "Hello world, how are you today? Pretty neat!";
-        var unicodeSampleText = "A Unicode sentence (пÑРвеÑ) has words.";
-
-        List<Justification> alignments = Enum.GetValues (typeof (Justification)).Cast<Justification> ().ToList ();
-        Label [] singleLines = new Label [alignments.Count];
-        Label [] multipleLines = new Label [alignments.Count];
-
-        var multiLineHeight = 5;
-
-        foreach (Justification alignment in alignments)
-        {
-            singleLines [(int)alignment] = new()
-            {
-                Justification = alignment,
-                X = 1,
-
-                Width = Dim.Fill (1),
-                Height = 1,
-                ColorScheme = Colors.ColorSchemes ["Dialog"],
-                Text = txt
-            };
-
-            multipleLines [(int)alignment] = new()
-            {
-                Justification = alignment,
-                X = 1,
-
-                Width = Dim.Fill (1),
-                Height = multiLineHeight,
-                ColorScheme = Colors.ColorSchemes ["Dialog"],
-                Text = txt
-            };
-        }
-
-        // Add a label & text field so we can demo IsDefault
-        var editLabel = new Label { X = 0, Y = 0, Text = "Text:" };
-        Win.Add (editLabel);
-
-        var edit = new TextView
-        {
-            X = Pos.Right (editLabel) + 1,
-            Y = Pos.Y (editLabel),
-            Width = Dim.Fill ("Text:".Length + "  Unicode Sample".Length + 2),
-            Height = 4,
-            ColorScheme = Colors.ColorSchemes ["TopLevel"],
-            Text = txt
-        };
-
-        edit.TextChanged += (s, e) =>
-                            {
-                                foreach (Justification alignment in alignments)
-                                {
-                                    singleLines [(int)alignment].Text = edit.Text;
-                                    multipleLines [(int)alignment].Text = edit.Text;
-                                }
-                            };
-        Win.Add (edit);
-
-        var unicodeSample = new Button { X = Pos.Right (edit) + 1, Y = 0, Text = "Unicode Sample" };
-        unicodeSample.Accept += (s, e) => { edit.Text = unicodeSampleText; };
-        Win.Add (unicodeSample);
-
-        var update = new Button { X = Pos.Right (edit) + 1, Y = Pos.Bottom (edit) - 1, Text = "_Update" };
-
-        update.Accept += (s, e) =>
-                         {
-                             foreach (Justification alignment in alignments)
-                             {
-                                 singleLines [(int)alignment].Text = edit.Text;
-                                 multipleLines [(int)alignment].Text = edit.Text;
-                             }
-                         };
-        Win.Add (update);
-
-        var enableHotKeyCheckBox = new CheckBox
-        {
-            X = 0, Y = Pos.Bottom (edit), Text = "Enable Hotkey (_)", Checked = false
-        };
-
-        Win.Add (enableHotKeyCheckBox);
-
-        var label = new Label
-        {
-            Y = Pos.Bottom (enableHotKeyCheckBox) + 1, Text = "Demonstrating single-line (should clip):"
-        };
-        Win.Add (label);
-
-        foreach (Justification alignment in alignments)
-        {
-            label = new() { Y = Pos.Bottom (label), Text = $"{alignment}:" };
-            Win.Add (label);
-            singleLines [(int)alignment].Y = Pos.Bottom (label);
-            Win.Add (singleLines [(int)alignment]);
-            label = singleLines [(int)alignment];
-        }
-
-        txt += "\nSecond line\n\nFourth Line.";
-        label = new() { Y = Pos.Bottom (label), Text = "Demonstrating multi-line and word wrap:" };
-        Win.Add (label);
-
-        foreach (Justification alignment in alignments)
-        {
-            label = new() { Y = Pos.Bottom (label), Text = $"{alignment}:" };
-            Win.Add (label);
-            multipleLines [(int)alignment].Y = Pos.Bottom (label);
-            Win.Add (multipleLines [(int)alignment]);
-            label = multipleLines [(int)alignment];
-        }
-
-        enableHotKeyCheckBox.Toggled += (s, e) =>
-                                        {
-                                            foreach (Justification alignment in alignments)
-                                            {
-                                                singleLines [(int)alignment].HotKeySpecifier =
-                                                    e.OldValue == true ? (Rune)0xffff : (Rune)'_';
-
-                                                multipleLines [(int)alignment].HotKeySpecifier =
-                                                    e.OldValue == true ? (Rune)0xffff : (Rune)'_';
-                                            }
-
-                                            Win.SetNeedsDisplay ();
-                                            Win.LayoutSubviews ();
-                                        };
-    }
-}

+ 13 - 1
UICatalog/Scenarios/TextFormatterDemo.cs

@@ -63,7 +63,19 @@ public class TextFormatterDemo : Scenario
 
         app.Add (unicodeCheckBox);
 
-        List<Justification> alignments = Enum.GetValues (typeof (Justification)).Cast<Justification> ().ToList ();
+        static IEnumerable<T> GetUniqueEnumValues<T> () where T : Enum
+        {
+            var values = new HashSet<T> ();
+            foreach (T v in Enum.GetValues (typeof(T)))
+            {
+                if (values.Add (v))
+                {
+                    yield return v;
+                }
+            }
+        }
+
+        List<Justification> alignments = GetUniqueEnumValues<Justification>().ToList ();
         Label [] singleLines = new Label [alignments.Count];
         Label [] multipleLines = new Label [alignments.Count];
 

+ 3 - 3
UICatalog/Scenarios/TextAlignmentsAndDirection.cs → UICatalog/Scenarios/TextJustificationAndDirection.cs

@@ -6,9 +6,9 @@ using Terminal.Gui;
 
 namespace UICatalog.Scenarios;
 
-[ScenarioMetadata ("Text Alignment and Direction", "Demos horizontal and vertical text alignment and text direction.")]
+[ScenarioMetadata ("Text Justification and Direction", "Demos horizontal and vertical text justification and direction.")]
 [ScenarioCategory ("Text and Formatting")]
-public class TextAlignmentsAndDirections : Scenario
+public class TextJustificationAndDirections : Scenario
 {
     public override void Main ()
     {
@@ -389,7 +389,7 @@ public class TextAlignmentsAndDirections : Scenario
         mtxts.Add (txtLabelBC);
         mtxts.Add (txtLabelBR);
 
-        // Save Alignments in Data
+        // Save Justification in Data
         foreach (Label t in mtxts)
         {
             t.Data = new { h = t.Justification, v = t.VerticalJustification };

+ 5 - 5
UnitTests/Dialogs/DialogTests.cs

@@ -32,7 +32,7 @@ public class DialogTests
             Title = title,
             Width = width,
             Height = 1,
-            ButtonAlignment = Justification.Centered,
+            ButtonJustification = Justification.Centered,
             Buttons = [new Button { Text = btn1Text }]
         };
 
@@ -57,7 +57,7 @@ public class DialogTests
             Title = title,
             Width = width,
             Height = 1,
-            ButtonAlignment = Justification.Justified,
+            ButtonJustification = Justification.Justified,
             Buttons = [new Button { Text = btn1Text }]
         };
 
@@ -82,7 +82,7 @@ public class DialogTests
             Title = title,
             Width = width,
             Height = 1,
-            ButtonAlignment = Justification.Right,
+            ButtonJustification = Justification.Right,
             Buttons = [new Button { Text = btn1Text }]
         };
 
@@ -107,7 +107,7 @@ public class DialogTests
             Title = title,
             Width = width,
             Height = 1,
-            ButtonAlignment = Justification.Left,
+            ButtonJustification = Justification.Left,
             Buttons = [new Button { Text = btn1Text }]
         };
 
@@ -1359,7 +1359,7 @@ public class DialogTests
             Y = 0,
             Width = width,
             Height = 1,
-            ButtonAlignment = align,
+            ButtonJustification = align,
             Buttons = btns
         };
 

+ 19 - 19
UnitTests/Text/TextFormatterTests.cs

@@ -53,36 +53,36 @@ public class TextFormatterTests
         tf.Text = testText;
         Size expectedSize = new (testText.Length, 1);
         Assert.Equal (testText, tf.Text);
-        Assert.Equal (Justification.Left, tf.Alignment);
+        Assert.Equal (Justification.Left, tf.Justification);
         Assert.Equal (expectedSize, tf.Size);
         tf.Draw (testBounds, new Attribute (), new Attribute ());
         Assert.Equal (expectedSize, tf.Size);
         Assert.NotEmpty (tf.GetLines ());
 
-        tf.Alignment = Justification.Right;
+        tf.Justification = Justification.Right;
         expectedSize = new (testText.Length, 1);
         Assert.Equal (testText, tf.Text);
-        Assert.Equal (Justification.Right, tf.Alignment);
+        Assert.Equal (Justification.Right, tf.Justification);
         Assert.Equal (expectedSize, tf.Size);
         tf.Draw (testBounds, new Attribute (), new Attribute ());
         Assert.Equal (expectedSize, tf.Size);
         Assert.NotEmpty (tf.GetLines ());
 
-        tf.Alignment = Justification.Right;
+        tf.Justification = Justification.Right;
         expectedSize = new (testText.Length, 1);
         tf.Size = expectedSize;
         Assert.Equal (testText, tf.Text);
-        Assert.Equal (Justification.Right, tf.Alignment);
+        Assert.Equal (Justification.Right, tf.Justification);
         Assert.Equal (expectedSize, tf.Size);
         tf.Draw (testBounds, new Attribute (), new Attribute ());
         Assert.Equal (expectedSize, tf.Size);
         Assert.NotEmpty (tf.GetLines ());
 
-        tf.Alignment = Justification.Centered;
+        tf.Justification = Justification.Centered;
         expectedSize = new (testText.Length, 1);
         tf.Size = expectedSize;
         Assert.Equal (testText, tf.Text);
-        Assert.Equal (Justification.Centered, tf.Alignment);
+        Assert.Equal (Justification.Centered, tf.Justification);
         Assert.Equal (expectedSize, tf.Size);
         tf.Draw (testBounds, new Attribute (), new Attribute ());
         Assert.Equal (expectedSize, tf.Size);
@@ -1336,7 +1336,7 @@ ssb
         Assert.NotEmpty (tf.GetLines ());
         Assert.False (tf.NeedsFormat); // get_Lines causes a Format
 
-        tf.Alignment = Justification.Centered;
+        tf.Justification = Justification.Centered;
         Assert.True (tf.NeedsFormat);
         Assert.NotEmpty (tf.GetLines ());
         Assert.False (tf.NeedsFormat); // get_Lines causes a Format
@@ -3362,7 +3362,7 @@ ssb
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Left,
+            Justification = Justification.Left,
             AutoSize = autoSize,
         };
 
@@ -3399,7 +3399,7 @@ ssb
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Right,
+            Justification = Justification.Right,
             AutoSize = autoSize,
         };
 
@@ -3442,7 +3442,7 @@ ssb
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Centered,
+            Justification = Justification.Centered,
             AutoSize = autoSize,
         };
 
@@ -3487,7 +3487,7 @@ ssb
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Justified,
+            Justification = Justification.Justified,
             AutoSize = autoSize,
         };
 
@@ -3577,7 +3577,7 @@ Nice       Work")]
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Justified,
+            Justification = Justification.Justified,
             Size = new Size (width, height),
             MultiLine = true
         };
@@ -3629,7 +3629,7 @@ ek")]
         {
             Text = text,
             Direction = TextDirection.TopBottom_LeftRight,
-            VerticalAlignment = Justification.Justified,
+            VerticalJustification = Justification.Justified,
             Size = new Size (width, height),
             MultiLine = true
         };
@@ -3685,9 +3685,9 @@ ek")]
         TextFormatter tf = new ()
         {
             Text = text,
-            Alignment = Justification.Right,
+            Justification = Justification.Right,
             Direction = TextDirection.TopBottom_LeftRight,
-            VerticalAlignment = Justification.Bottom,
+            VerticalJustification = Justification.Bottom,
             AutoSize = autoSize,
         };
 
@@ -3827,7 +3827,7 @@ B")]
         {
             Text = text,
             Direction = TextDirection.TopBottom_LeftRight,
-            VerticalAlignment = Justification.Centered,
+            VerticalJustification = Justification.Centered,
             AutoSize = autoSize,
         };
 
@@ -6239,8 +6239,8 @@ B")]
     {
         TextFormatter tf = new ()
         {
-            Alignment = horizontalTextAlignment,
-            VerticalAlignment = Justification,
+            Justification = horizontalTextAlignment,
+            VerticalJustification = Justification,
             Direction = textDirection,
             Size = new (7, 7),
             Text = text

+ 2 - 2
UnitTests/View/Layout/Dim.AutoTests.cs

@@ -681,11 +681,11 @@ public class DimAutoTests (ITestOutputHelper output)
         Assert.False (view.TextFormatter.AutoSize);
         Assert.Equal (Size.Empty, view.Frame.Size);
 
-        view.TextFormatter.Alignment = Justification.Justified;
+        view.TextFormatter.Justification = Justification.Justified;
         Assert.False (view.TextFormatter.AutoSize);
         Assert.Equal (Size.Empty, view.Frame.Size);
 
-        view.TextFormatter.VerticalAlignment = Justification.Centered;
+        view.TextFormatter.VerticalJustification = Justification.Centered;
         Assert.False (view.TextFormatter.AutoSize);
         Assert.Equal (Size.Empty, view.Frame.Size);
 

+ 1 - 1
UnitTests/View/Text/AutoSizeTrueTests.cs

@@ -1937,7 +1937,7 @@ Y
             Width = 1,
             Height = height,
             TextDirection = TextDirection.TopBottom_LeftRight,
-            Justification = Justification.Centered
+            VerticalJustification = Justification.Centered
         };
         if (autoSize)
         {