Merge branch 'Swiggies-control-child-size-update'
This commit is contained in:
@@ -44,6 +44,15 @@ namespace FlaxEngine.GUI
|
||||
float h = Height - _margin.Height;
|
||||
float maxHeight = h;
|
||||
bool hasAnyLeft = false, hasAnyRight = false;
|
||||
|
||||
float itemWidth = 0;
|
||||
if (_children.Count > 0)
|
||||
{
|
||||
float totalGaps = (_children.Count - 1) * Spacing;
|
||||
float availableWidth = Width - totalGaps - _margin.Width;
|
||||
itemWidth = availableWidth / _children.Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _children.Count; i++)
|
||||
{
|
||||
Control c = _children[i];
|
||||
@@ -64,6 +73,11 @@ namespace FlaxEngine.GUI
|
||||
hasAnyRight = true;
|
||||
}
|
||||
maxHeight = Mathf.Max(maxHeight, ch);
|
||||
|
||||
if (ExpandChildSize && !AutoSize)
|
||||
{
|
||||
c.Width = itemWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasAnyLeft)
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace FlaxEngine.GUI
|
||||
protected TextAlignment _alignment = TextAlignment.Near;
|
||||
|
||||
private bool _controlChildSize = true;
|
||||
private bool _expandChildSize = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the left margin.
|
||||
@@ -173,6 +174,23 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If checked, the panel will expand all children in the relevant direction with even spacing and size (horizontally for Horizontal Panel, vertically for Vertical Panel).
|
||||
/// </summary>
|
||||
[EditorOrder(36), DefaultValue(false), VisibleIf(nameof(AutoSize), true)]
|
||||
public bool ExpandChildSize
|
||||
{
|
||||
get => _expandChildSize;
|
||||
set
|
||||
{
|
||||
if (_expandChildSize != value)
|
||||
{
|
||||
_expandChildSize = value;
|
||||
PerformLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the panel area margin.
|
||||
/// </summary>
|
||||
|
||||
@@ -44,6 +44,15 @@ namespace FlaxEngine.GUI
|
||||
float w = Width - _margin.Width;
|
||||
float maxWidth = w;
|
||||
bool hasAnyTop = false, hasAnyBottom = false;
|
||||
|
||||
float itemHeight = 0;
|
||||
if (_children.Count > 0)
|
||||
{
|
||||
float totalGaps = (_children.Count - 1) * Spacing;
|
||||
float availableHeight = Height - totalGaps - _margin.Height;
|
||||
itemHeight = availableHeight / _children.Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _children.Count; i++)
|
||||
{
|
||||
Control c = _children[i];
|
||||
@@ -64,6 +73,11 @@ namespace FlaxEngine.GUI
|
||||
hasAnyBottom = true;
|
||||
}
|
||||
maxWidth = Mathf.Max(maxWidth, cw);
|
||||
|
||||
if (ExpandChildSize && !AutoSize)
|
||||
{
|
||||
c.Height = itemHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasAnyTop)
|
||||
|
||||
Reference in New Issue
Block a user