Merge remote-tracking branch 'origin/master' into sdl_platform

This commit is contained in:
2025-06-02 18:15:16 +03:00
124 changed files with 1244 additions and 436 deletions

View File

@@ -51,6 +51,11 @@ namespace FlaxEngine.GUI
/// </summary>
protected float _cachedHeight = 16.0f;
/// <summary>
/// The items spacing.
/// </summary>
protected float _itemsSpacing = 2.0f;
/// <summary>
/// The items margin.
/// </summary>
@@ -168,9 +173,9 @@ namespace FlaxEngine.GUI
}
/// <summary>
/// Gets or sets the item slots margin (the space between items).
/// Gets or sets the item slots margin (the space around items).
/// </summary>
[EditorOrder(10), Tooltip("The item slots margin (the space between items).")]
[EditorOrder(10)]
public Margin ItemsMargin
{
get => _itemsMargin;
@@ -184,6 +189,23 @@ namespace FlaxEngine.GUI
}
}
/// <summary>
/// Gets or sets the item slots spacing (the margin between items).
/// </summary>
[EditorOrder(11)]
public float ItemsSpacing
{
get => _itemsSpacing;
set
{
if (!Mathf.NearEqual(_itemsSpacing, value))
{
_itemsSpacing = value;
PerformLayout();
}
}
}
/// <summary>
/// Gets or sets the panel close/open animation duration (in seconds).
/// </summary>
@@ -563,25 +585,27 @@ namespace FlaxEngine.GUI
var slotsLeft = clientArea.Left + slotsMargin.Left;
var slotsWidth = clientArea.Width - slotsMargin.Width;
float minHeight = HeaderHeight;
float y = clientArea.Top;
float height = clientArea.Top + dropOffset;
float y = clientArea.Top + slotsMargin.Top;
bool anyAdded = false;
for (int i = 0; i < _children.Count; i++)
{
Control c = _children[i];
if (c.IsScrollable && c.Visible)
{
var h = c.Height;
y += slotsMargin.Top;
c.Bounds = new Rectangle(slotsLeft, y, slotsWidth, h);
h += slotsMargin.Bottom;
h += _itemsSpacing;
y += h;
height += h + slotsMargin.Top;
anyAdded = true;
}
}
// Update panel height
if (anyAdded)
y -= _itemsSpacing;
if (anyAdded)
y += slotsMargin.Bottom;
float height = dropOffset + y;
_cachedHeight = height;
if (_animationProgress >= 1.0f && _isClosed)
y = minHeight;

View File

@@ -20,6 +20,7 @@ namespace FlaxEngine.GUI
private Color _scrollbarTrackColor;
private Color _scrollbarThumbColor;
private Color _scrollbarThumbSelectedColor;
private Rectangle _controlsBoundsBeforeLayout;
/// <summary>
/// The cached scroll area bounds. Used to scroll contents of the panel control. Cached during performing layout.
@@ -530,8 +531,25 @@ namespace FlaxEngine.GUI
{
// Arrange controls and get scroll bounds
ArrangeAndGetBounds();
UpdateScrollBars();
_controlsBoundsBeforeLayout = _controlsBounds;
}
// Update scroll bars
/// <inheritdoc />
protected override void PerformLayoutAfterChildren()
{
// If controls area changed during layout then update scroll bars again
ArrangeAndGetBounds();
if (_controlsBoundsBeforeLayout != _controlsBounds)
{
UpdateScrollBars();
}
base.PerformLayoutAfterChildren();
}
private void UpdateScrollBars()
{
var controlsBounds = _controlsBounds;
var scrollBounds = controlsBounds;
_scrollMargin.ExpandRectangle(ref scrollBounds);
@@ -689,7 +707,7 @@ namespace FlaxEngine.GUI
}
viewOffset.Y = Mathf.Clamp(viewOffset.Y, VScrollBar.Minimum, VScrollBar.Maximum);
VScrollBar.Value = viewOffset.Y;
VScrollBar.TargetValue = viewOffset.Y;
}
if (HScrollBar != null && HScrollBar.Enabled && width > MinSize)
@@ -704,7 +722,7 @@ namespace FlaxEngine.GUI
}
viewOffset.X = Mathf.Clamp(viewOffset.X, HScrollBar.Minimum, HScrollBar.Maximum);
HScrollBar.Value = viewOffset.X;
HScrollBar.TargetValue = viewOffset.X;
}
viewOffset *= -1;

View File

@@ -72,8 +72,11 @@ namespace FlaxEngine.GUI
get => _slotSpacing;
set
{
_slotSpacing = value;
PerformLayout();
if (!Float2.NearEqual(ref _slotSpacing, ref value))
{
_slotSpacing = value;
PerformLayout();
}
}
}
@@ -89,11 +92,11 @@ namespace FlaxEngine.GUI
/// Initializes a new instance of the <see cref="UniformGridPanel"/> class.
/// </summary>
/// <param name="slotPadding">The slot padding.</param>
public UniformGridPanel(float slotPadding = 0)
public UniformGridPanel(float slotPadding)
{
AutoFocus = false;
SlotPadding = new Margin(slotPadding);
SlotSpacing = new Float2(2);
_slotPadding = new Margin(slotPadding);
_slotSpacing = new Float2(2);
_slotsH = _slotsV = 5;
}
@@ -105,25 +108,32 @@ namespace FlaxEngine.GUI
int slotsV = _slotsV;
int slotsH = _slotsH;
Float2 slotSize;
Float2 size = Size;
bool applySpacing = true;
APPLY_SPACING:
if (_slotsV + _slotsH == 0)
{
slotSize = HasChildren ? Children[0].Size : new Float2(32);
slotsH = Mathf.CeilToInt(Width / slotSize.X);
slotsV = Mathf.CeilToInt(Height / slotSize.Y);
slotsH = Mathf.CeilToInt(size.X / slotSize.X);
slotsV = Mathf.CeilToInt(size.Y / slotSize.Y);
}
else if (slotsH == 0)
{
float size = Height / slotsV;
slotSize = new Float2(size);
slotSize = new Float2(size.Y / slotsV);
}
else if (slotsV == 0)
{
float size = Width / slotsH;
slotSize = new Float2(size);
slotSize = new Float2(size.X / slotsH);
}
else
{
slotSize = new Float2(Width / slotsH, Height / slotsV);
slotSize = new Float2(size.X / slotsH, size.Y / slotsV);
}
if (applySpacing && _slotSpacing != Float2.Zero)
{
applySpacing = false;
size -= _slotSpacing * new Float2(slotsH > 1 ? slotsH - 1 : 0, slotsV > 1 ? slotsV - 1 : 0);
goto APPLY_SPACING;
}
int i = 0;
@@ -135,45 +145,9 @@ namespace FlaxEngine.GUI
for (int x = 0; x < end; x++)
{
var slotBounds = new Rectangle(slotSize.X * x, slotSize.Y * y, slotSize.X, slotSize.Y);
var slotBounds = new Rectangle((slotSize + _slotSpacing) * new Float2(x, y), slotSize);
_slotPadding.ShrinkRectangle(ref slotBounds);
if (slotsV > 1)
{
if (y == 0)
{
slotBounds.Height -= _slotSpacing.Y * 0.5f;
}
else if (y == slotsV - 1)
{
slotBounds.Height -= _slotSpacing.Y * 0.5f;
slotBounds.Y += _slotSpacing.Y * 0.5f;
}
else
{
slotBounds.Height -= _slotSpacing.Y;
slotBounds.Y += _slotSpacing.Y * 0.5f;
}
}
if (slotsH > 1)
{
if (x == 0)
{
slotBounds.Width -= _slotSpacing.X * 0.5f;
}
else if (x == slotsH - 1)
{
slotBounds.Width -= _slotSpacing.X * 0.5f;
slotBounds.X += _slotSpacing.X * 0.5f;
}
else
{
slotBounds.Width -= _slotSpacing.X;
slotBounds.X += _slotSpacing.X * 0.5f;
}
}
var c = _children[i++];
c.Bounds = slotBounds;
}