Fixes #1193. A non auto size default Button now preserves his width and thus the text alignment now work. (#1194)

* Fixes #1193. A  non auto size default Button now preserves his width and thus the text alignment now work.

* Fixing the Width and Height checks of the Dim class with AutoSize dependence.

* Toplevel can't be used on Pos/Dim but only his subviews. Was not caught before because the LayoutSubviews  method never gone so deep before.

* Fixed the error that is triggered when the Pos/Dim is the current Application.Top.

* Fixing the breaking APIs SetWidth and SetHeight.

* Fixing from the breaking APIs SetWidth and SetHeight.
This commit is contained in:
BDisp
2021-04-14 16:30:03 +01:00
committed by GitHub
parent 35f9aaeb00
commit 17496ac59e
3 changed files with 48 additions and 19 deletions

View File

@@ -370,7 +370,7 @@ namespace Terminal.Gui {
l = SuperView.Frame.Width;
}
nx = nx + top.Frame.Width > l ? Math.Max (l - top.Frame.Width, 0) : nx;
SetWidth (top.Frame.Width, out int rWidth, out _);
SetWidth (top.Frame.Width, out int rWidth);
if (rWidth < 0 && nx >= top.Frame.X) {
nx = Math.Max (top.Frame.Right - 2, 0);
}
@@ -399,7 +399,7 @@ namespace Terminal.Gui {
}
ny = Math.Min (ny, l);
ny = ny + top.Frame.Height > l ? Math.Max (l - top.Frame.Height, m ? 1 : 0) : ny;
SetHeight (top.Frame.Height, out int rHeight, out _);
SetHeight (top.Frame.Height, out int rHeight);
if (rHeight < 0 && ny >= top.Frame.Y) {
ny = Math.Max (top.Frame.Bottom - 2, 0);
}

View File

@@ -2188,14 +2188,7 @@ namespace Terminal.Gui {
return true;
}
/// <summary>
/// Calculate the width based on the <see cref="Width"/> settings.
/// </summary>
/// <param name="desiredWidth">The desired width.</param>
/// <param name="resultWidth">The real result width.</param>
/// <param name="currentWidth">The real current width.</param>
/// <returns>True if the width can be directly assigned, false otherwise.</returns>
public bool SetWidth (int desiredWidth, out int resultWidth, out int currentWidth)
bool CanSetWidth (int desiredWidth, out int resultWidth, out int currentWidth)
{
int w = desiredWidth;
currentWidth = Width != null ? Width.Anchor (0) : 0;
@@ -2222,14 +2215,7 @@ namespace Terminal.Gui {
return canSetWidth;
}
/// <summary>
/// Calculate the height based on the <see cref="Height"/> settings.
/// </summary>
/// <param name="desiredHeight">The desired height.</param>
/// <param name="resultHeight">The real result height.</param>
/// <param name="currentHeight">The real current height.</param>
/// <returns>True if the height can be directly assigned, false otherwise.</returns>
public bool SetHeight (int desiredHeight, out int resultHeight, out int currentHeight)
bool CanSetHeight (int desiredHeight, out int resultHeight, out int currentHeight)
{
int h = desiredHeight;
currentHeight = Height != null ? Height.Anchor (0) : 0;
@@ -2255,5 +2241,47 @@ namespace Terminal.Gui {
return canSetHeight;
}
/// <summary>
/// Calculate the width based on the <see cref="Width"/> settings.
/// </summary>
/// <param name="desiredWidth">The desired width.</param>
/// <param name="resultWidth">The real result width.</param>
/// <returns><c>true</c> if the width can be directly assigned, <c>false</c> otherwise.</returns>
public bool SetWidth (int desiredWidth, out int resultWidth)
{
return CanSetWidth (desiredWidth, out resultWidth, out _);
}
/// <summary>
/// Calculate the height based on the <see cref="Height"/> settings.
/// </summary>
/// <param name="desiredHeight">The desired height.</param>
/// <param name="resultHeight">The real result height.</param>
/// <returns><c>true</c> if the height can be directly assigned, <c>false</c> otherwise.</returns>
public bool SetHeight (int desiredHeight, out int resultHeight)
{
return CanSetHeight (desiredHeight, out resultHeight, out _);
}
/// <summary>
/// Gets the current width based on the <see cref="Width"/> settings.
/// </summary>
/// <param name="currentWidth">The real current width.</param>
/// <returns><c>true</c> if the width can be directly assigned, <c>false</c> otherwise.</returns>
public bool GetCurrentWidth (out int currentWidth)
{
return CanSetWidth (0, out _, out currentWidth);
}
/// <summary>
/// Calculate the height based on the <see cref="Height"/> settings.
/// </summary>
/// <param name="currentHeight">The real current height.</param>
/// <returns><c>true</c> if the height can be directly assigned, <c>false</c> otherwise.</returns>
public bool GetCurrentHeight (out int currentHeight)
{
return CanSetHeight (0, out _, out currentHeight);
}
}
}

View File

@@ -146,7 +146,8 @@ namespace Terminal.Gui {
base.Text = ustring.Make (_leftBracket) + " " + text + " " + ustring.Make (_rightBracket);
int w = base.Text.RuneCount - (base.Text.Contains (HotKeySpecifier) ? 1 : 0);
var canSetWidth = SetWidth (w, out int rWidth, out int cWidth);
GetCurrentWidth (out int cWidth);
var canSetWidth = SetWidth (w, out int rWidth);
if (canSetWidth && (cWidth < rWidth || AutoSize)) {
Width = rWidth;
w = rWidth;