diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index 6d3256a00..7b16f95e3 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -22,6 +22,8 @@ namespace FlaxEngine.GUI base.PerformLayoutBeforeChildren(); // Pre-set height of all controls + if (!ControlChildSize) + return; float h = Height - _margin.Height; for (int i = 0; i < _children.Count; i++) { @@ -47,16 +49,17 @@ namespace FlaxEngine.GUI if (c.Visible) { var w = c.Width; + var ch = ControlChildSize ? h : c.Height; if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X)) { - c.Bounds = new Rectangle(left + _offset.X, _margin.Top + _offset.Y, w, h); + c.Bounds = new Rectangle(left + _offset.X, _margin.Top + _offset.Y, w, ch); left = c.Right + _spacing; hasAnyLeft = true; } else if (Mathf.IsOne(c.AnchorMin.X) && Mathf.IsOne(c.AnchorMax.X)) { right += w + _spacing; - c.Bounds = new Rectangle(Width - right + _offset.X, _margin.Top + _offset.Y, w, h); + c.Bounds = new Rectangle(Width - right + _offset.X, _margin.Top + _offset.Y, w, ch); hasAnyRight = true; } } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 62e41bcd3..071f0ccf2 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -1,5 +1,7 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using System.ComponentModel; + namespace FlaxEngine.GUI { /// @@ -133,7 +135,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the value indicating whenever the panel size will be based on a children dimensions. /// - [EditorOrder(30), Tooltip("If checked, the panel size will be based on a children dimensions.")] + [EditorOrder(30), DefaultValue(true), Tooltip("If checked, the panel size will be based on a children dimensions.")] public bool AutoSize { get => _autoSize; @@ -147,6 +149,12 @@ namespace FlaxEngine.GUI } } + /// + /// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height). + /// + [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 panel area margin. /// diff --git a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs index b2fcdeae9..7a8785f4c 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -22,6 +22,8 @@ namespace FlaxEngine.GUI base.PerformLayoutBeforeChildren(); // Pre-set width of all controls + if (!ControlChildSize) + return; float w = Width - _margin.Width; for (int i = 0; i < _children.Count; i++) { @@ -47,16 +49,17 @@ namespace FlaxEngine.GUI if (c.Visible) { var h = c.Height; + var cw = ControlChildSize ? w : c.Width; if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y)) { - c.Bounds = new Rectangle(_margin.Left + _offset.X, top + _offset.Y, w, h); + c.Bounds = new Rectangle(_margin.Left + _offset.X, top + _offset.Y, cw, h); top = c.Bottom + _spacing; hasAnyTop = true; } else if (Mathf.IsOne(c.AnchorMin.Y) && Mathf.IsOne(c.AnchorMax.Y)) { bottom += h + _spacing; - c.Bounds = new Rectangle(_margin.Left + _offset.X, Height - bottom + _offset.Y, w, h); + c.Bounds = new Rectangle(_margin.Left + _offset.X, Height - bottom + _offset.Y, cw, h); hasAnyBottom = true; } }