Add support for vertical and horizontal panels to arrange children based on the child anchor

#385
This commit is contained in:
Wojtek Figat
2021-03-25 21:45:29 +01:00
parent d3bdc3cf8b
commit 9f79d0e3c4
2 changed files with 44 additions and 22 deletions

View File

@@ -35,28 +35,39 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
protected override void PerformLayoutAfterChildren()
{
// Sort controls from top to bottom
float y = _margin.Top;
// Sort controls vertically
float top = _margin.Top;
float bottom = _margin.Bottom;
float w = Width - _margin.Width;
bool hasAnyItem = false;
bool hasAnyTop = false, hasAnyBottom = false;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
if (c.Visible && Mathf.IsZero(c.AnchorMax.Y))
if (c.Visible)
{
var h = c.Height;
c.Bounds = new Rectangle(_margin.Left + _offset.X, y + _offset.Y, w, h);
y = c.Bottom + _spacing;
hasAnyItem = true;
if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y))
{
c.Bounds = new Rectangle(_margin.Left + _offset.X, top + _offset.Y, w, h);
top = c.Bottom + _spacing;
hasAnyTop = true;
}
else if (Mathf.IsOne(c.AnchorMin.Y) && Mathf.IsOne(c.AnchorMax.Y))
{
bottom += h + _spacing;
c.Bounds = new Rectangle(_margin.Left + _offset.X, Height - bottom + _offset.Y, w, h);
hasAnyBottom = true;
}
}
}
if (hasAnyItem)
y -= _spacing;
y += _margin.Bottom;
if (hasAnyTop)
top -= _spacing;
if (hasAnyBottom)
bottom -= _spacing;
// Update size
if (_autoSize)
Height = y;
Height = top + bottom;
}
}
}