From c779ea1c22793f945c6eec2487cead872863f35e Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Sun, 16 Aug 2026 12:57:44 +1000 Subject: [PATCH 1/3] Added 'Expand Children' Setting --- Source/Engine/UI/GUI/Panels/HorizontalPanel.cs | 10 ++++++++++ Source/Engine/UI/GUI/Panels/PanelWithMargins.cs | 6 ++++++ Source/Engine/UI/GUI/Panels/VerticalPanel.cs | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index d6e98315a..2145dc810 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -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) diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 52222946e..3223272ad 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -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; + /// + /// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height). + /// + [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; + /// /// 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..9036d88fb 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -1,5 +1,7 @@ // Copyright (c) Wojciech Figat. All rights reserved. +using System.Globalization; + namespace FlaxEngine.GUI { /// @@ -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) From 778974a738256bd4ef5dc526c82b6e499ad606bc Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 2 Oct 2026 14:35:57 +0200 Subject: [PATCH 2/3] Cleanup code and fix layout after option toggle #4219 --- Source/Engine/UI/GUI/Panels/HorizontalPanel.cs | 14 +++++++++----- .../Engine/UI/GUI/Panels/PanelWithMargins.cs | 18 +++++++++++++++--- Source/Engine/UI/GUI/Panels/VerticalPanel.cs | 16 +++++++++------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index 2145dc810..da6e747b3 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -45,9 +45,13 @@ namespace FlaxEngine.GUI 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; + 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++) { @@ -70,9 +74,9 @@ namespace FlaxEngine.GUI } maxHeight = Mathf.Max(maxHeight, ch); - if (ExpandChildren) + if (ExpandChildSize) { - c.Width = itemWidth; + c.Width = itemWidth; } } } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 8e66eb22e..773415d64 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. @@ -174,10 +175,21 @@ namespace FlaxEngine.GUI } /// - /// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height). + /// 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), 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; + [EditorOrder(36), DefaultValue(false)] + 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 9036d88fb..d54e6c203 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -1,7 +1,5 @@ // Copyright (c) Wojciech Figat. All rights reserved. -using System.Globalization; - namespace FlaxEngine.GUI { /// @@ -47,9 +45,13 @@ namespace FlaxEngine.GUI 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; + 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++) { @@ -72,9 +74,9 @@ namespace FlaxEngine.GUI } maxWidth = Mathf.Max(maxWidth, cw); - if (ExpandChildren) + if (ExpandChildSize) { - c.Height = itemHeight; + c.Height = itemHeight; } } } From 55a161d7d64335931a58f5308bfcd63736ce1988 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 2 Oct 2026 14:40:00 +0200 Subject: [PATCH 3/3] Dont resize children with `ExpandChildSize` when `AutoSize` is active to avoid broken layout --- Source/Engine/UI/GUI/Panels/HorizontalPanel.cs | 2 +- Source/Engine/UI/GUI/Panels/PanelWithMargins.cs | 2 +- Source/Engine/UI/GUI/Panels/VerticalPanel.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index da6e747b3..fa322f641 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -74,7 +74,7 @@ namespace FlaxEngine.GUI } maxHeight = Mathf.Max(maxHeight, ch); - if (ExpandChildSize) + if (ExpandChildSize && !AutoSize) { c.Width = itemWidth; } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 773415d64..eb2706e88 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -177,7 +177,7 @@ 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)] + [EditorOrder(36), DefaultValue(false), VisibleIf(nameof(AutoSize), true)] public bool ExpandChildSize { get => _expandChildSize; diff --git a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs index d54e6c203..00b849529 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -74,7 +74,7 @@ namespace FlaxEngine.GUI } maxWidth = Mathf.Max(maxWidth, cw); - if (ExpandChildSize) + if (ExpandChildSize && !AutoSize) { c.Height = itemHeight; }