diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index d6e98315a..fa322f641 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -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) diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 067fa72e5..eb2706e88 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -36,6 +36,7 @@ namespace FlaxEngine.GUI protected TextAlignment _alignment = TextAlignment.Near; private bool _controlChildSize = true; + private bool _expandChildSize = false; /// /// Gets or sets the left margin. @@ -173,6 +174,23 @@ namespace FlaxEngine.GUI } } + /// + /// 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). + /// + [EditorOrder(36), DefaultValue(false), VisibleIf(nameof(AutoSize), true)] + public bool ExpandChildSize + { + get => _expandChildSize; + set + { + if (_expandChildSize != value) + { + _expandChildSize = value; + PerformLayout(); + } + } + } + /// /// Gets or sets the panel area margin. /// diff --git a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs index 722da1fdc..00b849529 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -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)