Move UseFixedSize property from node archetype to flags and optimize unnecessary layouts during node loading

#3866
This commit is contained in:
Wojtek Figat
2026-03-31 22:47:10 +02:00
parent ea5e7f1416
commit ebb4ff1dc2
6 changed files with 24 additions and 34 deletions

View File

@@ -71,7 +71,7 @@ namespace FlaxEditor.Surface.Archetypes
return;
_assetSelect.Visible = !box.HasAnyConnection;
if (!Archetype.UseFixedSize)
if (!Archetype.Flags.HasFlag(NodeFlags.FixedSize))
ResizeAuto();
}
}
@@ -934,8 +934,7 @@ namespace FlaxEditor.Surface.Archetypes
TypeID = 27,
Title = "Copy Node",
Description = "Copies the skeleton node transformation data (in local space)",
Flags = NodeFlags.AnimGraph,
UseFixedSize = true,
Flags = NodeFlags.AnimGraph | NodeFlags.FixedSize,
Size = new Float2(260, 140),
DefaultValues = new object[]
{

View File

@@ -340,8 +340,7 @@ namespace FlaxEditor.Surface.Archetypes
Create = (id, context, arch, groupArch) => new ParticleEmitterNode(id, context, arch, groupArch),
Title = "Particle Emitter",
Description = "Main particle emitter node. Contains a set of modules per emitter context. Modules are executed in order from top to bottom of the stack.",
Flags = NodeFlags.ParticleEmitterGraph | NodeFlags.NoRemove | NodeFlags.NoSpawnViaGUI | NodeFlags.NoSpawnViaPaste | NodeFlags.NoCloseButton,
UseFixedSize = true,
Flags = NodeFlags.ParticleEmitterGraph | NodeFlags.NoRemove | NodeFlags.NoSpawnViaGUI | NodeFlags.NoSpawnViaPaste | NodeFlags.NoCloseButton | NodeFlags.FixedSize,
Size = new Float2(300, 600),
DefaultValues = new object[]
{

View File

@@ -1526,9 +1526,8 @@ namespace FlaxEditor.Surface.Archetypes
Title = "Color Gradient",
Create = (id, context, arch, groupArch) => new ColorGradientNode(id, context, arch, groupArch),
Description = "Linear color gradient sampler",
Flags = NodeFlags.AllGraphs,
Flags = NodeFlags.AllGraphs | NodeFlags.FixedSize,
Size = new Float2(400, 150.0f),
UseFixedSize = true,
DefaultValues = new object[]
{
// Stops count
@@ -1846,9 +1845,8 @@ namespace FlaxEditor.Surface.Archetypes
Title = "Reroute",
Create = (id, context, arch, groupArch) => new RerouteNode(id, context, arch, groupArch),
Description = "Reroute a connection.",
Flags = NodeFlags.NoCloseButton | NodeFlags.NoSpawnViaGUI | NodeFlags.AllGraphs,
Flags = NodeFlags.NoCloseButton | NodeFlags.NoSpawnViaGUI | NodeFlags.AllGraphs | NodeFlags.FixedSize,
Size = RerouteNode.DefaultSize,
UseFixedSize = true,
ConnectionsHints = ConnectionsHint.All,
IndependentBoxes = new int[] { 0 },
DependentBoxes = new int[] { 1 },

View File

@@ -129,11 +129,6 @@ namespace FlaxEditor.Surface
/// </summary>
public NodeFlags Flags;
/// <summary>
/// If the node should use the <see cref="Size"/> as node size. If false, the node will auto resize based on its elements.
/// </summary>
public bool UseFixedSize = false;
/// <summary>
/// Title text.
/// </summary>

View File

@@ -78,6 +78,11 @@ namespace FlaxEditor.Surface
/// </summary>
VariableValuesSize = 2048,
/// <summary>
/// Node has fixed size defined and should not use automatic layout.
/// </summary>
FixedSize = 4096,
/// <summary>
/// Node can be used in the all visual graphs.
/// </summary>

View File

@@ -348,10 +348,8 @@ namespace FlaxEditor.Surface
if (element is Control control)
AddChild(control);
if (!Archetype.UseFixedSize)
ResizeAuto();
else
Resize(Archetype.Size.X, Archetype.Size.Y);
if (!IsLayoutLocked)
UpdateSize();
}
/// <summary>
@@ -912,6 +910,14 @@ namespace FlaxEditor.Surface
return sb.ToString();
}
private void UpdateSize()
{
if (Archetype.Flags.HasFlag(NodeFlags.FixedSize))
Resize(Archetype.Size.X, Archetype.Size.Y);
else
ResizeAuto();
}
/// <inheritdoc />
protected override bool ShowTooltip => base.ShowTooltip && _headerRect.Contains(ref _mousePosition) && !Surface.IsLeftMouseButtonDown && !Surface.IsRightMouseButtonDown && !Surface.IsPrimaryMenuOpened;
@@ -965,10 +971,7 @@ namespace FlaxEditor.Surface
box.OnConnectionsChanged();
}
if (!Archetype.UseFixedSize)
ResizeAuto();
else
Resize(Archetype.Size.X, Archetype.Size.Y);
UpdateSize();
}
/// <inheritdoc />
@@ -1007,10 +1010,7 @@ namespace FlaxEditor.Surface
_isDuringValuesEditing = false;
if (!Archetype.UseFixedSize)
ResizeAuto();
else
Resize(Archetype.Size.X, Archetype.Size.Y);
UpdateSize();
}
/// <summary>
@@ -1046,10 +1046,7 @@ namespace FlaxEditor.Surface
_isDuringValuesEditing = false;
if (!Archetype.UseFixedSize)
ResizeAuto();
else
Resize(Archetype.Size.X, Archetype.Size.Y);
UpdateSize();
}
internal void SetIsDuringValuesEditing(bool value)
@@ -1082,10 +1079,7 @@ namespace FlaxEditor.Surface
public virtual void ConnectionTick(Box box)
{
UpdateBoxesTypes();
if (!Archetype.UseFixedSize)
ResizeAuto();
else
Resize(Archetype.Size.X, Archetype.Size.Y);
UpdateSize();
}
/// <inheritdoc />