Fix UI Controls layout auto-resizing to always use pivot-relative logic

#3031
This commit is contained in:
Wojtek Figat
2025-03-16 22:57:18 +01:00
parent 87e423ed48
commit fa68a5f572
5 changed files with 18 additions and 6 deletions

View File

@@ -337,9 +337,7 @@ namespace FlaxEngine.GUI
size.X = _textSize.X + Margin.Width;
if (_autoHeight)
size.Y = _textSize.Y + Margin.Height;
var pivotRelative = PivotRelative;
Size = size;
PivotRelative = pivotRelative;
Resize(ref size);
}
}
}

View File

@@ -419,6 +419,19 @@ namespace FlaxEngine.GUI
}
}
/// <summary>
/// Resizes the control based on where the pivot is rather than just the top-left.
/// </summary>
[NoAnimate]
public void Resize(ref Float2 value)
{
if (_bounds.Size.Equals(ref value))
return;
var bounds = new Rectangle(_bounds.Location, value);
bounds.Location += (_bounds.Size - value) * Pivot; // Pivot-relative resizing
SetBounds(ref bounds);
}
/// <summary>
/// Updates the control cached bounds (based on anchors and offsets).
/// </summary>

View File

@@ -585,7 +585,8 @@ namespace FlaxEngine.GUI
_cachedHeight = height;
if (_animationProgress >= 1.0f && _isClosed)
y = minHeight;
Height = Mathf.Max(minHeight, y);
var size = new Float2(Width, Mathf.Max(minHeight, y));
Resize(ref size);
}
/// <inheritdoc />

View File

@@ -78,7 +78,7 @@ namespace FlaxEngine.GUI
size.X = left + right;
if (!ControlChildSize)
size.Y = maxHeight;
Size = size;
Resize(ref size);
}
else if (_alignment != TextAlignment.Near && hasAnyLeft)
{

View File

@@ -78,7 +78,7 @@ namespace FlaxEngine.GUI
size.Y = top + bottom;
if (!ControlChildSize)
size.X = maxWidth;
Size = size;
Resize(ref size);
}
else if (_alignment != TextAlignment.Near && hasAnyTop)
{