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; } } }