Changes due to the requested changes.

This commit is contained in:
BDisp
2022-07-04 13:03:07 +01:00
committed by Tig Kindel
parent 63bcd2b1fc
commit 32fa12e0bd
3 changed files with 39 additions and 34 deletions

View File

@@ -155,12 +155,13 @@ namespace Terminal.Gui {
public bool AutoSize { get; set; }
/// <summary>
/// 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 <see cref="Text"/> will have trailing spaces preserved
/// or not when <see cref="WordWrap"/> is enabled. If `true` any trailing spaces will be trimmed when
/// either the <see cref="Text"/> property is changed or when <see cref="WordWrap"/> is set to `true`.
/// The default is `false`.
/// </summary>
public bool PreserveTrailingSpaces { get; set; }
// TODO: Add Vertical Text Alignment
/// <summary>
/// Controls the horizontal text-alignment property.
/// </summary>

View File

@@ -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 {
}
/// <summary>
/// Used by <see cref="Text"/> to resize the view's <see cref="Bounds"/> with the <see cref="TextFormatter.Size"/>.
/// Setting <see cref="AutoSize"/> to true only work if the <see cref="Width"/> and <see cref="Height"/> are null or
/// <see cref="LayoutStyle.Absolute"/> values and doesn't work with <see cref="LayoutStyle.Computed"/> layout
/// and <see cref="ForceValidatePosDim"/> to avoid breaking the <see cref="Pos"/> and <see cref="Dim"/> settings.
/// Gets or sets a flag that determines whether the View will be automatically resized to fit the <see cref="Text"/>.
/// The default is `false`. Set to `true` to turn on AutoSize. If <see cref="AutoSize"/> is `true` the <see cref="Width"/>
/// and <see cref="Height"/> 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 <see cref="ForceValidatePosDim"/> is `true` the new values of <see cref="Width"/> and
/// <see cref="Height"/> must be of the same types of the existing one to avoid breaking the <see cref="Dim"/> settings.
/// </summary>
public virtual bool AutoSize {
get => autoSize;
@@ -2421,8 +2423,10 @@ namespace Terminal.Gui {
}
/// <summary>
/// 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 <see cref="TextFormatter.Text"/> will have trailing spaces preserved
/// or not when <see cref="TextFormatter.WordWrap"/> is enabled. If `true` any trailing spaces will be trimmed when
/// either the <see cref="Text"/> property is changed or when <see cref="TextFormatter.WordWrap"/> is set to `true`.
/// The default is `false`.
/// </summary>
public virtual bool PreserveTrailingSpaces {
get => TextFormatter.PreserveTrailingSpaces;
@@ -2496,7 +2500,7 @@ namespace Terminal.Gui {
public virtual bool IsInitialized { get; set; }
/// <summary>
/// Gets information if the view was already added to the superview.
/// Gets information if the view was already added to the <see cref="SuperView"/>.
/// </summary>
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 {
}
/// <summary>
/// Calculates the size to fit all text if <see cref="AutoSize"/> is true.
/// Gets the size to fit all text if <see cref="AutoSize"/> is true.
/// </summary>
/// <returns>The <see cref="Size"/></returns>
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));
}
/// <summary>
/// Calculates the width to fit the text if <see cref="AutoSize"/> is true.
/// </summary>
/// <returns>The width length.</returns>
public int CalculateAutoSizeWidth ()
{
return CalculateAutoSize ().Width;
}
/// <summary>
/// Calculates the height to fit the text if <see cref="AutoSize"/> is true.
/// </summary>
/// <returns>The height length.</returns>
public int CalculateAutoSizeHeight ()
{
return CalculateAutoSize ().Height;
}
bool IsValidAutoSize (out Size autoSize)
{
var rect = TextFormatter.CalcRect (frame.X, frame.Y, TextFormatter.Text, TextDirection);

View File

@@ -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 ();
}