Added 'Expand Children' Setting

This commit is contained in:
Olly Rybak
2026-08-16 12:57:44 +10:00
parent a0639e310a
commit c779ea1c22
3 changed files with 28 additions and 0 deletions
@@ -44,6 +44,11 @@ namespace FlaxEngine.GUI
float h = Height - _margin.Height;
float maxHeight = h;
bool hasAnyLeft = false, hasAnyRight = false;
float totalGaps = (_children.Count - 1) * Spacing;
float availableWidth = Width - totalGaps - LeftMargin - RightMargin;
float itemWidth = availableWidth / _children.Count;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
@@ -64,6 +69,11 @@ namespace FlaxEngine.GUI
hasAnyRight = true;
}
maxHeight = Mathf.Max(maxHeight, ch);
if (ExpandChildren)
{
c.Width = itemWidth;
}
}
}
if (hasAnyLeft)
@@ -160,6 +160,12 @@ namespace FlaxEngine.GUI
[EditorOrder(35), DefaultValue(true), Tooltip("If checked, the panel can resize children controls (eg. auto-fit width/height).")]
public bool ControlChildSize { get; set; } = true;
/// <summary>
/// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height).
/// </summary>
[EditorOrder(36), DefaultValue(false), Tooltip("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).")]
public bool ExpandChildren { get; set; } = false;
/// <summary>
/// Gets or sets the panel area margin.
/// </summary>
@@ -1,5 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System.Globalization;
namespace FlaxEngine.GUI
{
/// <summary>
@@ -44,6 +46,11 @@ namespace FlaxEngine.GUI
float w = Width - _margin.Width;
float maxWidth = w;
bool hasAnyTop = false, hasAnyBottom = false;
float totalGaps = (_children.Count - 1) * Spacing;
float availableHeight = Height - totalGaps - TopMargin - BottomMargin;
float itemHeight = availableHeight / _children.Count;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
@@ -64,6 +71,11 @@ namespace FlaxEngine.GUI
hasAnyBottom = true;
}
maxWidth = Mathf.Max(maxWidth, cw);
if (ExpandChildren)
{
c.Height = itemHeight;
}
}
}
if (hasAnyTop)