Add ControlChildSize option to disable autosizing child controls in UI panel
#2511
This commit is contained in:
@@ -22,6 +22,8 @@ namespace FlaxEngine.GUI
|
|||||||
base.PerformLayoutBeforeChildren();
|
base.PerformLayoutBeforeChildren();
|
||||||
|
|
||||||
// Pre-set height of all controls
|
// Pre-set height of all controls
|
||||||
|
if (!ControlChildSize)
|
||||||
|
return;
|
||||||
float h = Height - _margin.Height;
|
float h = Height - _margin.Height;
|
||||||
for (int i = 0; i < _children.Count; i++)
|
for (int i = 0; i < _children.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -47,16 +49,17 @@ namespace FlaxEngine.GUI
|
|||||||
if (c.Visible)
|
if (c.Visible)
|
||||||
{
|
{
|
||||||
var w = c.Width;
|
var w = c.Width;
|
||||||
|
var ch = ControlChildSize ? h : c.Height;
|
||||||
if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X))
|
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;
|
left = c.Right + _spacing;
|
||||||
hasAnyLeft = true;
|
hasAnyLeft = true;
|
||||||
}
|
}
|
||||||
else if (Mathf.IsOne(c.AnchorMin.X) && Mathf.IsOne(c.AnchorMax.X))
|
else if (Mathf.IsOne(c.AnchorMin.X) && Mathf.IsOne(c.AnchorMax.X))
|
||||||
{
|
{
|
||||||
right += w + _spacing;
|
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;
|
hasAnyRight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace FlaxEngine.GUI
|
namespace FlaxEngine.GUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -133,7 +135,7 @@ namespace FlaxEngine.GUI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value indicating whenever the panel size will be based on a children dimensions.
|
/// Gets or sets the value indicating whenever the panel size will be based on a children dimensions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[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
|
public bool AutoSize
|
||||||
{
|
{
|
||||||
get => _autoSize;
|
get => _autoSize;
|
||||||
@@ -147,6 +149,12 @@ namespace FlaxEngine.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height).
|
||||||
|
/// </summary>
|
||||||
|
[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>
|
/// <summary>
|
||||||
/// Gets or sets the panel area margin.
|
/// Gets or sets the panel area margin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace FlaxEngine.GUI
|
|||||||
base.PerformLayoutBeforeChildren();
|
base.PerformLayoutBeforeChildren();
|
||||||
|
|
||||||
// Pre-set width of all controls
|
// Pre-set width of all controls
|
||||||
|
if (!ControlChildSize)
|
||||||
|
return;
|
||||||
float w = Width - _margin.Width;
|
float w = Width - _margin.Width;
|
||||||
for (int i = 0; i < _children.Count; i++)
|
for (int i = 0; i < _children.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -47,16 +49,17 @@ namespace FlaxEngine.GUI
|
|||||||
if (c.Visible)
|
if (c.Visible)
|
||||||
{
|
{
|
||||||
var h = c.Height;
|
var h = c.Height;
|
||||||
|
var cw = ControlChildSize ? w : c.Width;
|
||||||
if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y))
|
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;
|
top = c.Bottom + _spacing;
|
||||||
hasAnyTop = true;
|
hasAnyTop = true;
|
||||||
}
|
}
|
||||||
else if (Mathf.IsOne(c.AnchorMin.Y) && Mathf.IsOne(c.AnchorMax.Y))
|
else if (Mathf.IsOne(c.AnchorMin.Y) && Mathf.IsOne(c.AnchorMax.Y))
|
||||||
{
|
{
|
||||||
bottom += h + _spacing;
|
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;
|
hasAnyBottom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user