diff --git a/Terminal.Gui/Core/TextFormatter.cs b/Terminal.Gui/Core/TextFormatter.cs
index 66e046e47..f45cbd949 100644
--- a/Terminal.Gui/Core/TextFormatter.cs
+++ b/Terminal.Gui/Core/TextFormatter.cs
@@ -155,12 +155,13 @@ namespace Terminal.Gui {
public bool AutoSize { get; set; }
///
- /// Get or sets a flag if the wrapped text will keep the trailing spaces or
- /// the trailing spaces will be trimmed (default).
+ /// Gets or sets a flag that determines whether will have trailing spaces preserved
+ /// or not when is enabled. If `true` any trailing spaces will be trimmed when
+ /// either the property is changed or when is set to `true`.
+ /// The default is `false`.
///
public bool PreserveTrailingSpaces { get; set; }
- // TODO: Add Vertical Text Alignment
///
/// Controls the horizontal text-alignment property.
///
diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs
index a859bdb9e..2870be858 100644
--- a/Terminal.Gui/Core/View.cs
+++ b/Terminal.Gui/Core/View.cs
@@ -827,7 +827,7 @@ namespace Terminal.Gui {
var _y = y is Pos.PosAbsolute ? y.Anchor (0) : frame.Y;
if (AutoSize) {
- var s = CalculateAutoSize ();
+ var s = GetAutoSize ();
var w = width is Dim.DimAbsolute && width.Anchor (0) > s.Width ? width.Anchor (0) : s.Width;
var h = height is Dim.DimAbsolute && height.Anchor (0) > s.Height ? height.Anchor (0) : s.Height;
frame = new Rect (new Point (_x, _y), new Size (w, h));
@@ -2118,7 +2118,7 @@ namespace Terminal.Gui {
var s = Size.Empty;
if (AutoSize) {
- s = CalculateAutoSize ();
+ s = GetAutoSize ();
}
if (x is Pos.PosCenter) {
@@ -2401,10 +2401,12 @@ namespace Terminal.Gui {
}
///
- /// Used by to resize the view's with the .
- /// Setting to true only work if the and are null or
- /// values and doesn't work with layout
- /// and to avoid breaking the and settings.
+ /// Gets or sets a flag that determines whether the View will be automatically resized to fit the .
+ /// The default is `false`. Set to `true` to turn on AutoSize. If is `true` the
+ /// and will always be used if the text size is lower. If the text size is higher the bounds will
+ /// be resized to fit it.
+ /// In addition, if is `true` the new values of and
+ /// must be of the same types of the existing one to avoid breaking the settings.
///
public virtual bool AutoSize {
get => autoSize;
@@ -2421,8 +2423,10 @@ namespace Terminal.Gui {
}
///
- /// Get or sets a flag if the wrapped text will keep the trailing spaces or
- /// the trailing spaces will be trimmed (default).
+ /// Gets or sets a flag that determines whether will have trailing spaces preserved
+ /// or not when is enabled. If `true` any trailing spaces will be trimmed when
+ /// either the property is changed or when is set to `true`.
+ /// The default is `false`.
///
public virtual bool PreserveTrailingSpaces {
get => TextFormatter.PreserveTrailingSpaces;
@@ -2496,7 +2500,7 @@ namespace Terminal.Gui {
public virtual bool IsInitialized { get; set; }
///
- /// Gets information if the view was already added to the superview.
+ /// Gets information if the view was already added to the .
///
public bool IsAdded { get; private set; }
@@ -2581,7 +2585,7 @@ namespace Terminal.Gui {
}
var aSize = true;
- var nBoundsSize = CalculateAutoSize ();
+ var nBoundsSize = GetAutoSize ();
if (nBoundsSize != Bounds.Size) {
if (ForceValidatePosDim) {
aSize = SetWidthHeight (nBoundsSize);
@@ -2615,34 +2619,16 @@ namespace Terminal.Gui {
}
///
- /// Calculates the size to fit all text if is true.
+ /// Gets the size to fit all text if is true.
///
/// The
- public Size CalculateAutoSize ()
+ public Size GetAutoSize ()
{
var rect = TextFormatter.CalcRect (Bounds.X, Bounds.Y, TextFormatter.Text, TextFormatter.Direction);
return new Size (rect.Size.Width - GetHotKeySpecifierLength (),
rect.Size.Height - GetHotKeySpecifierLength (false));
}
- ///
- /// Calculates the width to fit the text if is true.
- ///
- /// The width length.
- public int CalculateAutoSizeWidth ()
- {
- return CalculateAutoSize ().Width;
- }
-
- ///
- /// Calculates the height to fit the text if is true.
- ///
- /// The height length.
- public int CalculateAutoSizeHeight ()
- {
- return CalculateAutoSize ().Height;
- }
-
bool IsValidAutoSize (out Size autoSize)
{
var rect = TextFormatter.CalcRect (frame.X, frame.Y, TextFormatter.Text, TextDirection);
diff --git a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs
index 1068f6796..4cfa487d4 100644
--- a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs
+++ b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs
@@ -7,7 +7,7 @@ namespace UICatalog.Scenarios {
public override void Setup ()
{
var text = "Hello World";
- //var text = "Hello World 你";
+ var wideText = "Hello World 你";
var color = Colors.Dialog;
var labelH = new Label (text, TextDirection.LeftRight_TopBottom) {
@@ -73,6 +73,24 @@ namespace UICatalog.Scenarios {
labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces = ckbPreserveTrailingSpaces.Checked;
Win.Add (ckbPreserveTrailingSpaces);
+ var ckbWideText = new CheckBox ("Use wide runes") {
+ X = Pos.Center (),
+ Y = Pos.Center () + 9
+ };
+ ckbWideText.Toggled += (_) => {
+ if (ckbWideText.Checked) {
+ labelH.Text = labelV.Text = editText.Text = wideText;
+ labelH.Width = 14;
+ labelV.Height = 13;
+ } else {
+ labelH.Text = labelV.Text = editText.Text = text;
+ labelH.Width = 11;
+ labelV.Width = 1;
+ labelV.Height = 11;
+ }
+ };
+ Win.Add (ckbWideText);
+
Win.KeyUp += (_) =>
labelH.Text = labelV.Text = text = editText.Text.ToString ();
}