Cleanup code and fix layout after option toggle #4219
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace FlaxEngine.GUI
|
||||
protected TextAlignment _alignment = TextAlignment.Near;
|
||||
|
||||
private bool _controlChildSize = true;
|
||||
private bool _expandChildSize = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the left margin.
|
||||
@@ -174,10 +175,21 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
[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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the panel area margin.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user