From ce1e243df27e3a2dc1b10061fa162655f86d4e98 Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 10 May 2024 11:27:02 -0600 Subject: [PATCH] Justification->Alignment --- .../Drawing/{Justification.cs => Aligner.cs} | 28 +++-- Terminal.Gui/Drawing/Thickness.cs | 4 +- Terminal.Gui/Resources/config.json | 2 +- Terminal.Gui/Text/TextFormatter.cs | 100 +++++++-------- Terminal.Gui/View/Layout/PosDim.cs | 88 +++++++------ Terminal.Gui/View/ViewText.cs | 22 ++-- Terminal.Gui/Views/Button.cs | 4 +- Terminal.Gui/Views/CheckBox.cs | 2 +- Terminal.Gui/Views/Dialog.cs | 12 +- Terminal.Gui/Views/Menu/Menu.cs | 2 +- Terminal.Gui/Views/MessageBox.cs | 8 +- Terminal.Gui/Views/ProgressBar.cs | 2 +- Terminal.Gui/Views/Slider.cs | 8 +- Terminal.Gui/Views/TableView/ColumnStyle.cs | 26 ++-- Terminal.Gui/Views/TableView/TableView.cs | 6 +- Terminal.Gui/Views/TextValidateField.cs | 12 +- Terminal.Gui/Views/Wizard/Wizard.cs | 2 +- UICatalog/Scenarios/BasicColors.cs | 4 +- UICatalog/Scenarios/Buttons.cs | 52 ++++---- UICatalog/Scenarios/CharacterMap.cs | 2 +- .../Scenarios/CollectionNavigatorTester.cs | 4 +- UICatalog/Scenarios/ColorPicker.cs | 4 +- UICatalog/Scenarios/ComputedLayout.cs | 30 ++--- UICatalog/Scenarios/CsvEditor.cs | 30 ++--- UICatalog/Scenarios/Dialogs.cs | 18 +-- UICatalog/Scenarios/DynamicMenuBar.cs | 4 +- UICatalog/Scenarios/Editor.cs | 18 +-- UICatalog/Scenarios/ListColumns.cs | 2 +- UICatalog/Scenarios/MessageBoxes.cs | 18 +-- UICatalog/Scenarios/Mouse.cs | 4 +- .../{PosJustification.cs => PosAlign.cs} | 100 +++++++-------- UICatalog/Scenarios/TableEditor.cs | 10 +- UICatalog/Scenarios/Text.cs | 2 +- ...ection.cs => TextAlignmentAndDirection.cs} | 104 +++++++-------- UICatalog/Scenarios/TextFormatterDemo.cs | 42 +++---- UICatalog/Scenarios/TimeAndDate.cs | 12 +- UICatalog/Scenarios/Unicode.cs | 2 +- UICatalog/Scenarios/ViewExperiments.cs | 10 +- UICatalog/Scenarios/Wizards.cs | 8 +- UnitTests/Configuration/ThemeScopeTests.cs | 6 +- UnitTests/Configuration/ThemeTests.cs | 4 +- UnitTests/Dialogs/DialogTests.cs | 32 ++--- UnitTests/Text/TextFormatterTests.cs | 118 +++++++++--------- UnitTests/View/DrawTests.cs | 6 +- UnitTests/View/Layout/Dim.AutoTests.cs | 12 +- UnitTests/View/Text/AutoSizeTrueTests.cs | 16 +-- UnitTests/Views/ButtonTests.cs | 8 +- UnitTests/Views/CheckBoxTests.cs | 26 ++-- UnitTests/Views/LabelTests.cs | 2 +- UnitTests/Views/TextValidateFieldTests.cs | 40 +++--- UnitTests/Views/ToplevelTests.cs | 4 +- docfx/docs/layout.md | 2 +- docfx/docs/migratingfromv1.md | 8 +- docfx/docs/newinv2.md | 2 +- 54 files changed, 551 insertions(+), 543 deletions(-) rename Terminal.Gui/Drawing/{Justification.cs => Aligner.cs} (93%) rename UICatalog/Scenarios/{PosJustification.cs => PosAlign.cs} (81%) rename UICatalog/Scenarios/{TextJustificationAndDirection.cs => TextAlignmentAndDirection.cs} (84%) diff --git a/Terminal.Gui/Drawing/Justification.cs b/Terminal.Gui/Drawing/Aligner.cs similarity index 93% rename from Terminal.Gui/Drawing/Justification.cs rename to Terminal.Gui/Drawing/Aligner.cs index d2b87a9a6..97f507391 100644 --- a/Terminal.Gui/Drawing/Justification.cs +++ b/Terminal.Gui/Drawing/Aligner.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using static Terminal.Gui.Pos; namespace Terminal.Gui; @@ -15,7 +14,8 @@ public enum Alignment /// /// /// - /// If the container is smaller than the total size of the items, the right items will be clipped (their locations will be greater than the container size). + /// If the container is smaller than the total size of the items, the right items will be clipped (their locations + /// will be greater than the container size). /// /// /// @@ -39,7 +39,8 @@ public enum Alignment /// /// /// - /// If the container is smaller than the total size of the items, the left items will be clipped (their locations will be negative). + /// If the container is smaller than the total size of the items, the left items will be clipped (their locations + /// will be negative). /// /// /// @@ -99,7 +100,8 @@ public enum Alignment /// /// /// - /// If the container is smaller than the total size of the items, the right items will be clipped (their locations will be greater than the container size). + /// If the container is smaller than the total size of the items, the right items will be clipped (their locations + /// will be greater than the container size). /// /// /// @@ -123,7 +125,8 @@ public enum Alignment /// /// /// - /// If the container is smaller than the total size of the items, the left items will be clipped (their locations will be negative). + /// If the container is smaller than the total size of the items, the left items will be clipped (their locations + /// will be negative). /// /// /// @@ -138,7 +141,7 @@ public enum Alignment /// Set to to ensure at least one line between /// each item. /// - LastBottomRestTop = LastRightRestLeft, + LastBottomRestTop = LastRightRestLeft } /// @@ -157,7 +160,7 @@ public class Aligner : INotifyPropertyChanged set { _alignment = value; - PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (Alignment))); + PropertyChanged?.Invoke (this, new (nameof (Alignment))); } } @@ -172,7 +175,7 @@ public class Aligner : INotifyPropertyChanged set { _containerSize = value; - PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (ContainerSize))); + PropertyChanged?.Invoke (this, new (nameof (ContainerSize))); } } @@ -185,8 +188,9 @@ public class Aligner : INotifyPropertyChanged /// /// /// - /// If the total size of the items is greater than the container size, the space between items will be ignored starting - /// from the right. + /// If the total size of the items is greater than the container size, the space between items will be ignored + /// starting + /// from the right. /// /// public bool PutSpaceBetweenItems @@ -195,11 +199,11 @@ public class Aligner : INotifyPropertyChanged set { _putSpaceBetweenItems = value; - PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (PutSpaceBetweenItems))); + PropertyChanged?.Invoke (this, new (nameof (PutSpaceBetweenItems))); } } - /// + /// public event PropertyChangedEventHandler PropertyChanged; /// diff --git a/Terminal.Gui/Drawing/Thickness.cs b/Terminal.Gui/Drawing/Thickness.cs index 3ee360f50..f541465d2 100644 --- a/Terminal.Gui/Drawing/Thickness.cs +++ b/Terminal.Gui/Drawing/Thickness.cs @@ -232,8 +232,8 @@ public class Thickness : IEquatable var tf = new TextFormatter { Text = label is null ? string.Empty : $"{label} {this}", - Justification = Alignment.Centered, - VerticalJustification = Alignment.Bottom, + Alignment = Alignment.Centered, + VerticalAlignment = Alignment.Bottom, AutoSize = true }; tf.Draw (rect, Application.Driver.CurrentAttribute, Application.Driver.CurrentAttribute, rect); diff --git a/Terminal.Gui/Resources/config.json b/Terminal.Gui/Resources/config.json index c073d5aad..c2a63fe15 100644 --- a/Terminal.Gui/Resources/config.json +++ b/Terminal.Gui/Resources/config.json @@ -24,7 +24,7 @@ "Themes": [ { "Default": { - "Dialog.DefaultButtonJustification": "Right", + "Dialog.DefaultButtonAlignment": "Right", "FrameView.DefaultBorderStyle": "Single", "Window.DefaultBorderStyle": "Single", "ColorSchemes": [ diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index c05b84e7e..3d2e0d61d 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -3,7 +3,7 @@ using System.Diagnostics; namespace Terminal.Gui; /// -/// Provides text formatting. Supports s, horizontal justification, vertical justification, +/// Provides text formatting. Supports s, horizontal alignment, vertical alignment, /// multiple lines, and word-based line wrap. /// public class TextFormatter @@ -17,17 +17,17 @@ public class TextFormatter private Size _size; private int _tabWidth = 4; private string _text; - private Alignment _textJustification; + private Alignment _textAlignment; private TextDirection _textDirection; - private Alignment _textVerticalJustification; + private Alignment _textVerticalAlignment; private bool _wordWrap = true; - /// Get or sets the horizontal text justification. - /// The text justification. - public Alignment Justification + /// Get or sets the horizontal text alignment. + /// The text alignment. + public Alignment Alignment { - get => _textJustification; - set => _textJustification = EnableNeedsFormat (value); + get => _textAlignment; + set => _textAlignment = EnableNeedsFormat (value); } /// Gets or sets whether the should be automatically changed to fit the . @@ -222,12 +222,12 @@ public class TextFormatter } } - /// Gets or sets the vertical text-justification. - /// The text vertical justification. - public Alignment VerticalJustification + /// Gets or sets the vertical text-alignment. + /// The text vertical alignment. + public Alignment VerticalAlignment { - get => _textVerticalJustification; - set => _textVerticalJustification = EnableNeedsFormat (value); + get => _textVerticalAlignment; + set => _textVerticalAlignment = EnableNeedsFormat (value); } /// Gets or sets whether word wrap will be used to fit to . @@ -319,8 +319,8 @@ public class TextFormatter int x = 0, y = 0; - // Horizontal Justification - if (Justification is Alignment.Right) + // Horizontal Alignment + if (Alignment is Alignment.Right) { if (isVertical) { @@ -335,7 +335,7 @@ public class TextFormatter CursorPosition = screen.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0); } } - else if (Justification is Alignment.Left) + else if (Alignment is Alignment.Left) { if (isVertical) { @@ -351,7 +351,7 @@ public class TextFormatter CursorPosition = _hotKeyPos > -1 ? _hotKeyPos : 0; } - else if (Justification is Alignment.Justified) + else if (Alignment is Alignment.Justified) { if (isVertical) { @@ -374,7 +374,7 @@ public class TextFormatter CursorPosition = _hotKeyPos > -1 ? _hotKeyPos : 0; } - else if (Justification is Alignment.Centered) + else if (Alignment is Alignment.Centered) { if (isVertical) { @@ -394,13 +394,13 @@ public class TextFormatter } else { - Debug.WriteLine ($"Unsupported Justification: {nameof (VerticalJustification)}"); + Debug.WriteLine ($"Unsupported Alignment: {nameof (VerticalAlignment)}"); return; } - // Vertical Justification - if (VerticalJustification is Alignment.Bottom) + // Vertical Alignment + if (VerticalAlignment is Alignment.Bottom) { if (isVertical) { @@ -411,7 +411,7 @@ public class TextFormatter y = screen.Bottom - linesFormatted.Count + line; } } - else if (VerticalJustification is Alignment.Top) + else if (VerticalAlignment is Alignment.Top) { if (isVertical) { @@ -422,7 +422,7 @@ public class TextFormatter y = screen.Top + line; } } - else if (VerticalJustification is Alignment.Justified) + else if (VerticalAlignment is Alignment.Justified) { if (isVertical) { @@ -436,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 (VerticalJustification is Alignment.Centered) + else if (VerticalAlignment is Alignment.Centered) { if (isVertical) { @@ -451,7 +451,7 @@ public class TextFormatter } else { - Debug.WriteLine ($"Unsupported Justification: {nameof (VerticalJustification)}"); + Debug.WriteLine ($"Unsupported Alignment: {nameof (VerticalAlignment)}"); return; } @@ -474,8 +474,8 @@ public class TextFormatter { if (idx < 0 || (isVertical - ? VerticalJustification != Alignment.Bottom && current < 0 - : Justification != Alignment.Right && x + current + colOffset < 0)) + ? VerticalAlignment != Alignment.Bottom && current < 0 + : Alignment != Alignment.Right && x + current + colOffset < 0)) { current++; @@ -564,7 +564,7 @@ public class TextFormatter if (HotKeyPos > -1 && idx == HotKeyPos) { - if ((isVertical && VerticalJustification == Alignment.Justified) || (!isVertical && Justification == Alignment.Justified)) + if ((isVertical && VerticalAlignment == Alignment.Justified) || (!isVertical && Alignment == Alignment.Justified)) { CursorPosition = idx - start; } @@ -702,7 +702,7 @@ public class TextFormatter _lines = Format ( text, Size.Height, - VerticalJustification == Alignment.Justified, + VerticalAlignment == Alignment.Justified, Size.Width > colsWidth && WordWrap, PreserveTrailingSpaces, TabWidth, @@ -726,7 +726,7 @@ public class TextFormatter _lines = Format ( text, Size.Width, - Justification == Alignment.Justified, + Alignment == Alignment.Justified, Size.Height > 1 && WordWrap, PreserveTrailingSpaces, TabWidth, @@ -980,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 Justification + // pad it out with spaces to the given Alignment int toPad = width - text.EnumerateRunes ().Sum (c => c.GetColumns ()); return text + new string (' ', toPad); @@ -1002,7 +1002,7 @@ public class TextFormatter /// instance to access any of his objects. /// A list of word wrapped lines. /// - /// This method does not do any justification. + /// This method does not do any alignment. /// This method strips Newline ('\n' and '\r\n') sequences before processing. /// /// If is at most one space will be preserved @@ -1034,7 +1034,7 @@ public class TextFormatter List runes = StripCRLF (text).ToRuneList (); int start = Math.Max ( - !runes.Contains ((Rune)' ') && textFormatter is { VerticalJustification: Alignment.Bottom } && IsVerticalDirection (textDirection) + !runes.Contains ((Rune)' ') && textFormatter is { VerticalAlignment: Alignment.Bottom } && IsVerticalDirection (textDirection) ? runes.Count - width : 0, 0); @@ -1252,7 +1252,7 @@ public class TextFormatter /// The number of columns to clip the text to. Text longer than will be /// clipped. /// - /// Justification. + /// Alignment. /// The text direction. /// The number of columns used for a tab. /// instance to access any of his objects. @@ -1260,13 +1260,13 @@ public class TextFormatter public static string ClipAndJustify ( string text, int width, - Alignment textJustification, + Alignment textAlignment, TextDirection textDirection = TextDirection.LeftRight_TopBottom, int tabWidth = 0, TextFormatter textFormatter = null ) { - return ClipAndJustify (text, width, textJustification == Alignment.Justified, textDirection, tabWidth, textFormatter); + return ClipAndJustify (text, width, textAlignment == Alignment.Justified, textDirection, tabWidth, textFormatter); } /// Justifies text within a specified width. @@ -1307,12 +1307,12 @@ public class TextFormatter { if (IsHorizontalDirection (textDirection)) { - if (textFormatter is { Justification: Alignment.Right }) + if (textFormatter is { Alignment: Alignment.Right }) { return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection); } - if (textFormatter is { Justification: Alignment.Centered }) + if (textFormatter is { Alignment: Alignment.Centered }) { return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection); } @@ -1322,12 +1322,12 @@ public class TextFormatter if (IsVerticalDirection (textDirection)) { - if (textFormatter is { VerticalJustification: Alignment.Bottom }) + if (textFormatter is { VerticalAlignment: Alignment.Bottom }) { return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection); } - if (textFormatter is { VerticalJustification: Alignment.Centered }) + if (textFormatter is { VerticalAlignment: Alignment.Centered }) { return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection); } @@ -1345,14 +1345,14 @@ public class TextFormatter if (IsHorizontalDirection (textDirection)) { - if (textFormatter is { Justification: Alignment.Right }) + if (textFormatter is { Alignment: Alignment.Right }) { if (GetRuneWidth (text, tabWidth, textDirection) > width) { return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection); } } - else if (textFormatter is { Justification: Alignment.Centered }) + else if (textFormatter is { Alignment: Alignment.Centered }) { return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection); } @@ -1364,14 +1364,14 @@ public class TextFormatter if (IsVerticalDirection (textDirection)) { - if (textFormatter is { VerticalJustification: Alignment.Bottom }) + if (textFormatter is { VerticalAlignment: Alignment.Bottom }) { if (runes.Count - zeroLength > width) { return GetRangeThatFits (runes, runes.Count - width, text, width, tabWidth, textDirection); } } - else if (textFormatter is { VerticalJustification: Alignment.Centered }) + else if (textFormatter is { VerticalAlignment: Alignment.Centered }) { return GetRangeThatFits (runes, Math.Max ((runes.Count - width) / 2, 0), text, width, tabWidth, textDirection); } @@ -1475,10 +1475,10 @@ public class TextFormatter return s.ToString (); } - /// Formats text into lines, applying text justification and optionally wrapping text to new lines on word boundaries. + /// Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries. /// /// The number of columns to constrain the text to for word wrapping and clipping. - /// Specifies how the text will be justified horizontally. + /// Specifies how the text will be aligned horizontally. /// /// If , the text will be wrapped to new lines no longer than /// . If , forces text to fit a single line. Line breaks are converted @@ -1501,7 +1501,7 @@ public class TextFormatter public static List Format ( string text, int width, - Alignment textJustification, + Alignment textAlignment, bool wordWrap, bool preserveTrailingSpaces = false, int tabWidth = 0, @@ -1513,7 +1513,7 @@ public class TextFormatter return Format ( text, width, - textJustification == Alignment.Justified, + textAlignment == Alignment.Justified, wordWrap, preserveTrailingSpaces, tabWidth, @@ -1523,7 +1523,7 @@ public class TextFormatter ); } - /// Formats text into lines, applying text justification and optionally wrapping text to new lines on word boundaries. + /// Formats text into lines, applying text alignment and optionally wrapping text to new lines on word boundaries. /// /// The number of columns to constrain the text to for word wrapping and clipping. /// Specifies whether the text should be justified. @@ -1887,7 +1887,7 @@ public class TextFormatter return lineIdx; } - /// Calculates the rectangle required to hold text, assuming no word wrapping or justification. + /// Calculates the rectangle required to hold text, assuming no word wrapping or alignment. /// /// This API will return incorrect results if the text includes glyphs who's width is dependent on surrounding /// glyphs (e.g. Arabic). diff --git a/Terminal.Gui/View/Layout/PosDim.cs b/Terminal.Gui/View/Layout/PosDim.cs index 79bd498b2..d6737b220 100644 --- a/Terminal.Gui/View/Layout/PosDim.cs +++ b/Terminal.Gui/View/Layout/PosDim.cs @@ -46,6 +46,14 @@ namespace Terminal.Gui; /// /// /// +/// +/// +/// +/// Creates a object that aligns a set of views. +/// +/// +/// +/// /// /// /// @@ -206,12 +214,12 @@ public class Pos /// - /// Creates a object that justifies a set of views according to the specified justification. + /// Creates a object that aligns a set of views according to the specified alignment setting. /// - /// - /// The optional, unique identifier for the set of views to justify according to . + /// + /// The optional, unique identifier for the set of views to align according to . /// - public static Pos Justify (Alignment justification, int groupId = 0) { return new PosJustify (justification, groupId); } + public static Pos Align (Alignment alignment, int groupId = 0) { return new PosAlign (alignment, groupId); } /// Serves as the default hash function. /// A hash code for the current object. @@ -496,47 +504,45 @@ public class Pos /// - /// Enables justification of a set of views. + /// Enables alignment of a set of views. /// /// /// - /// The Group ID is used to identify a set of views that should be justified together. When only a single - /// set of views is justified, setting the Group ID is not needed because it defaults to 0. + /// The Group ID is used to identify a set of views that should be alignment together. When only a single + /// set of views is aligned, setting the Group ID is not needed because it defaults to 0. /// /// - /// The first view added to the Superview with a given Group ID is used to determine the justification of the group. - /// The justification is applied to all views with the same Group ID. + /// The first view added to the Superview with a given Group ID is used to determine the alignment of the group. + /// The alignment is applied to all views with the same Group ID. /// /// - public class PosJustify : Pos + public class PosAlign : Pos { - // TODO: Figure out how to invalidate _location if Justifier changes. - /// /// The cached location. Used to store the calculated location to avoid recalculating it. /// private int? _location; /// - /// Gets the identifier of a set of views that should be justified together. When only a single - /// set of views is justified, setting the is not needed because it defaults to 0. + /// Gets the identifier of a set of views that should be aligned together. When only a single + /// set of views is aligned, setting the is not needed because it defaults to 0. /// private readonly int _groupId; /// - /// Gets the justification settings. + /// Gets the alignment settings. /// - public Aligner Justifier { get; } = new (); + public Aligner Aligner { get; } = new (); /// - /// Justifies the views in that have the same group ID as . + /// Aligns the views in that have the same group ID as . /// /// /// /// /// - private static void JustifyGroup (int groupId, IList views, Dim.Dimension dimension, int size) + private static void AlignGroup (int groupId, IList views, Dim.Dimension dimension, int size) { if (views is null) { @@ -547,14 +553,14 @@ public class Pos List viewsInGroup = views.Where ( v => { - if (dimension == Dimension.Width && v.X is PosJustify justifyX) + if (dimension == Dimension.Width && v.X is PosAlign alignX) { - return justifyX._groupId == groupId; + return alignX._groupId == groupId; } - if (dimension == Dimension.Height && v.Y is PosJustify justifyY) + if (dimension == Dimension.Height && v.Y is PosAlign alignY) { - return justifyY._groupId == groupId; + return alignY._groupId == groupId; } return false; @@ -566,13 +572,13 @@ public class Pos foreach (var view in viewsInGroup) { - var posJustify = dimension == Dimension.Width ? view.X as PosJustify : view.Y as PosJustify; + var posAlign = dimension == Dimension.Width ? view.X as PosAlign : view.Y as PosAlign; - if (posJustify is { }) + if (posAlign is { }) { if (firstInGroup is null) { - firstInGroup = posJustify.Justifier; + firstInGroup = posAlign.Aligner; } dimensionsList.Add (dimension == Dimension.Width ? view.Frame.Width : view.Frame.Height); @@ -590,29 +596,29 @@ public class Pos for (var index = 0; index < viewsInGroup.Count; index++) { View view = viewsInGroup [index]; - PosJustify justify = dimension == Dimension.Width ? view.X as PosJustify : view.Y as PosJustify; + PosAlign align = dimension == Dimension.Width ? view.X as PosAlign : view.Y as PosAlign; - if (justify is { }) + if (align is { }) { - justify._location = locations [index]; + align._location = locations [index]; } } } /// - /// Enables justification of a set of views. + /// Enables alignment of a set of views. /// - /// - /// The unique identifier for the set of views to justify according to . - public PosJustify (Alignment justification, int groupId = 0) + /// + /// The unique identifier for the set of views to align according to . + public PosAlign (Alignment alignment, int groupId = 0) { - Justifier.PutSpaceBetweenItems = true; - Justifier.Alignment = justification; + Aligner.PutSpaceBetweenItems = true; + Aligner.Alignment = alignment; _groupId = groupId; - Justifier.PropertyChanged += Justifier_PropertyChanged; + Aligner.PropertyChanged += Aligner_PropertyChanged; } - private void Justifier_PropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) + private void Aligner_PropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) { _location = null; } @@ -620,19 +626,19 @@ public class Pos /// public override bool Equals (object other) { - return other is PosJustify justify && _groupId == justify._groupId && _location == justify._location && justify.Justifier.Equals (Justifier); + return other is PosAlign align && _groupId == align._groupId && _location == align._location && align.Aligner.Equals (Aligner); } /// public override int GetHashCode () { - return Justifier.GetHashCode () ^ _groupId.GetHashCode (); + return Aligner.GetHashCode () ^ _groupId.GetHashCode (); } /// public override string ToString () { - return $"Justify(groupId={_groupId}, justification={Justifier.Alignment})"; + return $"Align(groupId={_groupId}, alignment={Aligner.Alignment})"; } internal override int Anchor (int width) @@ -642,7 +648,7 @@ public class Pos internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension) { - if (_location.HasValue && Justifier.ContainerSize == superviewDimension) + if (_location.HasValue && Aligner.ContainerSize == superviewDimension) { return _location.Value; } @@ -652,7 +658,7 @@ public class Pos return 0; } - JustifyGroup (_groupId, us.SuperView.Subviews, dimension, superviewDimension); + AlignGroup (_groupId, us.SuperView.Subviews, dimension, superviewDimension); if (_location.HasValue) { diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index 6e2ec991a..b45e0061f 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -34,7 +34,7 @@ public partial class View /// /// /// The text will be drawn starting at the view origin (0, 0) and will be formatted according - /// to and . + /// to and . /// /// /// The text will word-wrap to additional lines if it does not fit horizontally. If 's height @@ -80,19 +80,19 @@ public partial class View public event EventHandler> TextChanged; /// - /// Gets or sets how the View's is justified horizontally when drawn. Changing this property will + /// Gets or sets how the View's is aligned horizontally when drawn. Changing this property will /// redisplay the . /// /// /// or are using , the will be adjusted to fit the text. /// - /// The text justification. - public virtual Alignment TextJustification + /// The text alignment. + public virtual Alignment TextAlignment { - get => TextFormatter.Justification; + get => TextFormatter.Alignment; set { - TextFormatter.Justification = value; + TextFormatter.Alignment = value; UpdateTextFormatterText (); OnResizeNeeded (); } @@ -122,20 +122,20 @@ public partial class View public TextFormatter TextFormatter { get; init; } = new () { }; /// - /// Gets or sets how the View's is justified vertically when drawn. Changing this property will + /// Gets or sets how the View's is aligned vertically when drawn. Changing this property will /// redisplay /// the . /// /// /// or are using , the will be adjusted to fit the text. /// - /// The vertical text justification. - public virtual Alignment VerticalTextJustification + /// The vertical text alignment. + public virtual Alignment VerticalTextAlignment { - get => TextFormatter.VerticalJustification; + get => TextFormatter.VerticalAlignment; set { - TextFormatter.VerticalJustification = value; + TextFormatter.VerticalAlignment = value; SetNeedsDisplay (); } } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 0a0fa5040..5fa80b70d 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -37,8 +37,8 @@ public class Button : View /// The width of the is computed based on the text length. The height will always be 1. public Button () { - TextJustification = Alignment.Centered; - VerticalTextJustification = Alignment.Centered; + TextAlignment = Alignment.Centered; + VerticalTextAlignment = Alignment.Centered; _leftBracket = Glyphs.LeftBracket; _rightBracket = Glyphs.RightBracket; diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index 8d598be2e..7bc069b02 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -153,7 +153,7 @@ public class CheckBox : View /// protected override void UpdateTextFormatterText () { - switch (TextJustification) + switch (TextAlignment) { case Alignment.Left: case Alignment.Centered: diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index f7210744b..232830da5 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -51,7 +51,7 @@ public class Dialog : Window ColorScheme = Colors.ColorSchemes ["Dialog"]; Modal = true; - ButtonJustification = DefaultButtonJustification; + ButtonAlignment = DefaultButtonAlignment; AddCommand ( Command.QuitToplevel, @@ -96,9 +96,9 @@ public class Dialog : Window } } - // TODO: Update button.X = Pos.Justify when justification changes - /// Determines how the s are justified along the bottom of the dialog. - public Alignment ButtonJustification { get; set; } + // TODO: Update button.X = Pos.Justify when alignment changes + /// Determines how the s are aligned along the bottom of the dialog. + public Alignment ButtonAlignment { get; set; } /// Optional buttons to lay out at the bottom of the dialog. public Button [] Buttons @@ -122,7 +122,7 @@ public class Dialog : Window /// This property can be set in a Theme. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] [JsonConverter (typeof (JsonStringEnumConverter))] - public static Alignment DefaultButtonJustification { get; set; } = Alignment.Right; + public static Alignment DefaultButtonAlignment { get; set; } = Alignment.Right; /// /// Adds a to the , its layout will be controlled by the @@ -136,7 +136,7 @@ public class Dialog : Window return; } - button.X = Pos.Justify (ButtonJustification); + button.X = Pos.Align (ButtonAlignment); button.Y = Pos.AnchorEnd () - 1; _buttons.Add (button); diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index b55bdfac5..4e2fa3320 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -891,7 +891,7 @@ internal sealed class Menu : View var tf = new TextFormatter { AutoSize = true, - Justification = Alignment.Centered, HotKeySpecifier = MenuBar.HotKeySpecifier, Text = textToDraw + Alignment = Alignment.Centered, HotKeySpecifier = MenuBar.HotKeySpecifier, Text = textToDraw }; // The -3 is left/right border + one space (not sure what for) diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index 72e0f42b1..bf391997b 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -340,8 +340,8 @@ public static class MessageBox } } - Alignment buttonJust = Dialog.DefaultButtonJustification; - Dialog.DefaultButtonJustification = Alignment.Centered; + Alignment buttonJust = Dialog.DefaultButtonAlignment; + Dialog.DefaultButtonAlignment = Alignment.Centered; var d = new Dialog { Buttons = buttonList.ToArray (), @@ -350,7 +350,7 @@ public static class MessageBox Width = Dim.Percent (60), Height = 5 // Border + one line of text + vspace + buttons }; - Dialog.DefaultButtonJustification = buttonJust; + Dialog.DefaultButtonAlignment = buttonJust; if (width != 0) { @@ -374,7 +374,7 @@ public static class MessageBox var messageLabel = new Label { Text = message, - TextJustification = Alignment.Centered, + TextAlignment = Alignment.Centered, X = Pos.Center (), Y = 0 }; diff --git a/Terminal.Gui/Views/ProgressBar.cs b/Terminal.Gui/Views/ProgressBar.cs index 9c56625b2..26760c04d 100644 --- a/Terminal.Gui/Views/ProgressBar.cs +++ b/Terminal.Gui/Views/ProgressBar.cs @@ -181,7 +181,7 @@ public class ProgressBar : View if (ProgressBarFormat != ProgressBarFormat.Simple && !_isActivity) { - var tf = new TextFormatter { Justification = Alignment.Centered, Text = Text }; + var tf = new TextFormatter { Alignment = Alignment.Centered, Text = Text }; var attr = new Attribute (ColorScheme.HotNormal.Foreground, ColorScheme.HotNormal.Background); if (_fraction > .5) diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 95ed09fd8..efddec1d3 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -930,7 +930,7 @@ public class Slider : View } } - private string JustifyText (string text, int width, Alignment justification) + private string AlignText (string text, int width, Alignment alignment) { 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 (alignment) { case Alignment.Justified: return TextFormatter.Justify (text, width); @@ -1293,7 +1293,7 @@ public class Slider : View switch (_config._legendsOrientation) { case Orientation.Horizontal: - text = JustifyText (text, _config._innerSpacing + 1, Alignment.Centered); + text = AlignText (text, _config._innerSpacing + 1, Alignment.Centered); break; case Orientation.Vertical: @@ -1311,7 +1311,7 @@ public class Slider : View break; case Orientation.Vertical: - text = JustifyText (text, _config._innerSpacing + 1, Alignment.Centered); + text = AlignText (text, _config._innerSpacing + 1, Alignment.Centered); break; } diff --git a/Terminal.Gui/Views/TableView/ColumnStyle.cs b/Terminal.Gui/Views/TableView/ColumnStyle.cs index 02615e696..2d277abd9 100644 --- a/Terminal.Gui/Views/TableView/ColumnStyle.cs +++ b/Terminal.Gui/Views/TableView/ColumnStyle.cs @@ -1,17 +1,17 @@ namespace Terminal.Gui; /// -/// Describes how to render a given column in a including and +/// Describes how to render a given column in a including and /// textual representation of cells (e.g. date formats) /// See TableView Deep Dive for more information. /// public class ColumnStyle { /// - /// Defines a delegate for returning custom justification per cell based on cell values. When specified this will - /// override + /// Defines a delegate for returning custom alignment per cell based on cell values. When specified this will + /// override /// - public Func JustificationGetter; + public Func AlignmentGetter; /// /// Defines a delegate for returning a custom color scheme per cell based on cell values. Return null for the @@ -29,10 +29,10 @@ public class ColumnStyle private bool _visible = true; /// - /// Defines the default justification for all values rendered in this column. For custom justification based on cell - /// contents use . + /// Defines the default alignment for all values rendered in this column. For custom alignment based on cell + /// contents use . /// - public Alignment Justification { get; set; } + public Alignment Alignment { get; set; } /// Defines the format for values e.g. "yyyy-MM-dd" for dates public string Format { get; set; } @@ -69,19 +69,19 @@ public class ColumnStyle } /// - /// Returns the justification for the cell based on and / - /// + /// Returns the alignment for the cell based on and / + /// /// /// /// - public Alignment GetJustification (object cellValue) + public Alignment GetAlignment (object cellValue) { - if (JustificationGetter is { }) + if (AlignmentGetter is { }) { - return JustificationGetter (cellValue); + return AlignmentGetter (cellValue); } - return Justification; + return Alignment; } /// diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 0931faa31..8689521e5 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 justification specified in (or left + /// using the alignment specified in (or left /// if no style is defined) /// /// The object in this cell of the /// The string representation of /// - /// Optional style indicating custom justification for the cell + /// Optional style indicating custom alignment for the cell /// private string TruncateOrPad ( object originalCellValue, @@ -2085,7 +2085,7 @@ public class TableView : View - (representation.EnumerateRunes ().Sum (c => c.GetColumns ()) + 1 /*leave 1 space for cell boundary*/); - switch (colStyle?.GetJustification (originalCellValue) ?? Alignment.Left) + switch (colStyle?.GetAlignment (originalCellValue) ?? Alignment.Left) { case Alignment.Left: return representation + new string (' ', toPad); diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index 034a0a69b..11ed14089 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -539,7 +539,7 @@ namespace Terminal.Gui { int c = _provider.Cursor (mouseEvent.X - GetMargins (Viewport.Width).left); - if (_provider.Fixed == false && TextJustification == Alignment.Right && Text.Length > 0) + if (_provider.Fixed == false && TextAlignment == Alignment.Right && Text.Length > 0) { c++; } @@ -633,7 +633,7 @@ namespace Terminal.Gui // When it's right-aligned and it's a normal input, the cursor behaves differently. int curPos; - if (_provider?.Fixed == false && TextJustification == Alignment.Right) + if (_provider?.Fixed == false && TextAlignment == Alignment.Right) { curPos = _cursorPosition + left - 1; } @@ -650,7 +650,7 @@ namespace Terminal.Gui /// private bool BackspaceKeyHandler () { - if (_provider.Fixed == false && TextJustification == Alignment.Right && _cursorPosition <= 1) + if (_provider.Fixed == false && TextAlignment == Alignment.Right && _cursorPosition <= 1) { return false; } @@ -688,7 +688,7 @@ namespace Terminal.Gui /// private bool DeleteKeyHandler () { - if (_provider.Fixed == false && TextJustification == Alignment.Right) + if (_provider.Fixed == false && TextAlignment == Alignment.Right) { _cursorPosition = _provider.CursorLeft (_cursorPosition); } @@ -709,7 +709,7 @@ namespace Terminal.Gui return true; } - /// Margins for text justification. + /// Margins for text alignment. /// Total width /// Left and right margins private (int left, int right) GetMargins (int width) @@ -717,7 +717,7 @@ namespace Terminal.Gui int count = Text.Length; int total = width - count; - switch (TextJustification) + switch (TextAlignment) { case Alignment.Left: return (0, total); diff --git a/Terminal.Gui/Views/Wizard/Wizard.cs b/Terminal.Gui/Views/Wizard/Wizard.cs index 049668e5e..f9283b9c8 100644 --- a/Terminal.Gui/Views/Wizard/Wizard.cs +++ b/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 - ButtonJustification = Alignment.Justified; + ButtonAlignment = Alignment.Justified; BorderStyle = LineStyle.Double; //// Add a horiz separator diff --git a/UICatalog/Scenarios/BasicColors.cs b/UICatalog/Scenarios/BasicColors.cs index 510d36d40..58bbcce88 100644 --- a/UICatalog/Scenarios/BasicColors.cs +++ b/UICatalog/Scenarios/BasicColors.cs @@ -32,7 +32,7 @@ public class BasicColors : Scenario Y = 0, Width = 1, Height = 13, - VerticalTextJustification = Alignment.Bottom, + VerticalTextAlignment = Alignment.Bottom, ColorScheme = new ColorScheme { Normal = attr }, Text = bg.ToString (), TextDirection = TextDirection.TopBottom_LeftRight @@ -45,7 +45,7 @@ public class BasicColors : Scenario Y = y, Width = 13, Height = 1, - TextJustification = Alignment.Right, + TextAlignment = Alignment.Right, ColorScheme = new ColorScheme { Normal = attr }, Text = bg.ToString () }; diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 1f0943d28..d5beae1fa 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/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 Justification (changes the four buttons above): " + X = 2, Y = Pos.Bottom (computedFrame) + 1, Text = "Text Alignment (changes the four buttons above): " }; main.Add (label); @@ -287,39 +287,39 @@ public class Buttons : Scenario switch (args.SelectedItem) { case 0: - moveBtn.TextJustification = Alignment.Left; - sizeBtn.TextJustification = Alignment.Left; - moveBtnA.TextJustification = Alignment.Left; - sizeBtnA.TextJustification = Alignment.Left; - moveHotKeyBtn.TextJustification = Alignment.Left; - moveUnicodeHotKeyBtn.TextJustification = Alignment.Left; + moveBtn.TextAlignment = Alignment.Left; + sizeBtn.TextAlignment = Alignment.Left; + moveBtnA.TextAlignment = Alignment.Left; + sizeBtnA.TextAlignment = Alignment.Left; + moveHotKeyBtn.TextAlignment = Alignment.Left; + moveUnicodeHotKeyBtn.TextAlignment = Alignment.Left; break; case 1: - moveBtn.TextJustification = Alignment.Right; - sizeBtn.TextJustification = Alignment.Right; - moveBtnA.TextJustification = Alignment.Right; - sizeBtnA.TextJustification = Alignment.Right; - moveHotKeyBtn.TextJustification = Alignment.Right; - moveUnicodeHotKeyBtn.TextJustification = Alignment.Right; + moveBtn.TextAlignment = Alignment.Right; + sizeBtn.TextAlignment = Alignment.Right; + moveBtnA.TextAlignment = Alignment.Right; + sizeBtnA.TextAlignment = Alignment.Right; + moveHotKeyBtn.TextAlignment = Alignment.Right; + moveUnicodeHotKeyBtn.TextAlignment = Alignment.Right; break; case 2: - moveBtn.TextJustification = Alignment.Centered; - sizeBtn.TextJustification = Alignment.Centered; - moveBtnA.TextJustification = Alignment.Centered; - sizeBtnA.TextJustification = Alignment.Centered; - moveHotKeyBtn.TextJustification = Alignment.Centered; - moveUnicodeHotKeyBtn.TextJustification = Alignment.Centered; + moveBtn.TextAlignment = Alignment.Centered; + sizeBtn.TextAlignment = Alignment.Centered; + moveBtnA.TextAlignment = Alignment.Centered; + sizeBtnA.TextAlignment = Alignment.Centered; + moveHotKeyBtn.TextAlignment = Alignment.Centered; + moveUnicodeHotKeyBtn.TextAlignment = Alignment.Centered; break; case 3: - moveBtn.TextJustification = Alignment.Justified; - sizeBtn.TextJustification = Alignment.Justified; - moveBtnA.TextJustification = Alignment.Justified; - sizeBtnA.TextJustification = Alignment.Justified; - moveHotKeyBtn.TextJustification = Alignment.Justified; - moveUnicodeHotKeyBtn.TextJustification = Alignment.Justified; + moveBtn.TextAlignment = Alignment.Justified; + sizeBtn.TextAlignment = Alignment.Justified; + moveBtnA.TextAlignment = Alignment.Justified; + sizeBtnA.TextAlignment = Alignment.Justified; + moveHotKeyBtn.TextAlignment = Alignment.Justified; + moveUnicodeHotKeyBtn.TextAlignment = Alignment.Justified; break; } @@ -439,7 +439,7 @@ public class Buttons : Scenario Y = Pos.Top (_down), Width = Dim.Function (() => Digits), Height = 1, - TextJustification = Alignment.Centered, + TextAlignment = Alignment.Centered, CanFocus = true }; diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index cb4d77a70..4fdfeebc8 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -958,7 +958,7 @@ internal class CharMap : View Y = 1, Width = Dim.Fill (), Height = Dim.Fill (1), - TextJustification = Alignment.Centered + TextAlignment = Alignment.Centered }; var spinner = new SpinnerView { X = Pos.Center (), Y = Pos.Center (), Style = new Aesthetic () }; spinner.AutoSpin = true; diff --git a/UICatalog/Scenarios/CollectionNavigatorTester.cs b/UICatalog/Scenarios/CollectionNavigatorTester.cs index 69d8f51a1..0c9b3ab14 100644 --- a/UICatalog/Scenarios/CollectionNavigatorTester.cs +++ b/UICatalog/Scenarios/CollectionNavigatorTester.cs @@ -142,7 +142,7 @@ public class CollectionNavigatorTester : Scenario var label = new Label { Text = "ListView", - TextJustification = Alignment.Centered, + TextAlignment = Alignment.Centered, X = 0, Y = 1, // for menu Width = Dim.Percent (50), @@ -171,7 +171,7 @@ public class CollectionNavigatorTester : Scenario var label = new Label { Text = "TreeView", - TextJustification = Alignment.Centered, + TextAlignment = Alignment.Centered, X = Pos.Right (_listView) + 2, Y = 1, // for menu Width = Dim.Percent (50), diff --git a/UICatalog/Scenarios/ColorPicker.cs b/UICatalog/Scenarios/ColorPicker.cs index 5b92f96dd..6d5f61814 100644 --- a/UICatalog/Scenarios/ColorPicker.cs +++ b/UICatalog/Scenarios/ColorPicker.cs @@ -69,8 +69,8 @@ public class ColorPickers : Scenario { Title = "Color Sample", Text = "Lorem Ipsum", - TextJustification = Alignment.Centered, - VerticalTextJustification = Alignment.Centered, + TextAlignment = Alignment.Centered, + VerticalTextAlignment = Alignment.Centered, BorderStyle = LineStyle.Heavy, X = Pos.Center (), Y = Pos.Center (), diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index ac19ff82b..5fcf85c75 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -86,12 +86,12 @@ public class ComputedLayout : Scenario var i = 1; var txt = "Resize the terminal to see computed layout in action."; List