Add Alignment option to Vertical and Horizonal Panels

#2599
This commit is contained in:
Wojtek Figat
2024-10-22 21:55:25 +02:00
parent 0b1263a9e2
commit e5289931c6
3 changed files with 58 additions and 0 deletions

View File

@@ -80,6 +80,24 @@ namespace FlaxEngine.GUI
size.Y = maxHeight;
Size = size;
}
else if (_alignment != TextAlignment.Near && hasAnyLeft)
{
// Apply layout alignment
var offset = Width - left - _margin.Right;
if (_alignment == TextAlignment.Center)
offset *= 0.5f;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
if (c.Visible)
{
if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X))
{
c.X += offset;
}
}
}
}
}
}
}

View File

@@ -30,6 +30,11 @@ namespace FlaxEngine.GUI
/// </summary>
protected Float2 _offset;
/// <summary>
/// The child controls alignment within layout area.
/// </summary>
protected TextAlignment _alignment = TextAlignment.Near;
/// <summary>
/// Gets or sets the left margin.
/// </summary>
@@ -172,6 +177,23 @@ namespace FlaxEngine.GUI
}
}
/// <summary>
/// Gets or sets the child controls alignment within layout area.
/// </summary>
[EditorOrder(50), VisibleIf(nameof(AutoSize), true)]
public TextAlignment Alignment
{
get => _alignment;
set
{
if (_alignment != value)
{
_alignment = value;
PerformLayout();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PanelWithMargins"/> class.
/// </summary>

View File

@@ -80,6 +80,24 @@ namespace FlaxEngine.GUI
size.X = maxWidth;
Size = size;
}
else if (_alignment != TextAlignment.Near && hasAnyTop)
{
// Apply layout alignment
var offset = Height - top - _margin.Bottom;
if (_alignment == TextAlignment.Center)
offset *= 0.5f;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
if (c.Visible)
{
if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y))
{
c.Y += offset;
}
}
}
}
}
}
}