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 left to right
|
||||
float x = _margin.Left;
|
||||
// Sort controls horizontally
|
||||
float left = _margin.Left;
|
||||
float right = _margin.Right;
|
||||
float h = Height - _margin.Height;
|
||||
bool hasAnyItem = false;
|
||||
bool hasAnyLeft = false, hasAnyRight = false;
|
||||
for (int i = 0; i < _children.Count; i++)
|
||||
{
|
||||
Control c = _children[i];
|
||||
if (c.Visible && Mathf.IsZero(c.AnchorMax.X))
|
||||
if (c.Visible)
|
||||
{
|
||||
var w = c.Width;
|
||||
c.Bounds = new Rectangle(x + _offset.X, _margin.Top + _offset.Y, w, h);
|
||||
x = c.Right + _spacing;
|
||||
hasAnyItem = true;
|
||||
if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X))
|
||||
{
|
||||
c.Bounds = new Rectangle(left + _offset.X, _margin.Top + _offset.Y, w, h);
|
||||
left = c.Right + _spacing;
|
||||
hasAnyLeft = true;
|
||||
}
|
||||
else if (Mathf.IsOne(c.AnchorMin.X) && Mathf.IsOne(c.AnchorMax.X))
|
||||
{
|
||||
right += w + _spacing;
|
||||
c.Bounds = new Rectangle(Width - right + _offset.X, _margin.Top + _offset.Y, w, h);
|
||||
hasAnyRight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasAnyItem)
|
||||
x -= _spacing;
|
||||
x += _margin.Right;
|
||||
if (hasAnyLeft)
|
||||
left -= _spacing;
|
||||
if (hasAnyRight)
|
||||
right -= _spacing;
|
||||
|
||||
// Update size
|
||||
if (_autoSize)
|
||||
Width = x;
|
||||
Width = left + right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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