Add support for vertical and horizontal panels to arrange children based on the child anchor
#385
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user