From ebb4ff1dc2f3e69ea198d425f3b2b5fc4a6e55c5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 31 Mar 2026 22:47:10 +0200 Subject: [PATCH] Move `UseFixedSize` property from node archetype to flags and optimize unnecessary layouts during node loading #3866 --- Source/Editor/Surface/Archetypes/Animation.cs | 5 ++- Source/Editor/Surface/Archetypes/Particles.cs | 3 +- Source/Editor/Surface/Archetypes/Tools.cs | 6 ++-- Source/Editor/Surface/NodeArchetype.cs | 5 --- Source/Editor/Surface/NodeFlags.cs | 5 +++ Source/Editor/Surface/SurfaceNode.cs | 34 ++++++++----------- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index c8d45cc5f..9d045185f 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -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[] { diff --git a/Source/Editor/Surface/Archetypes/Particles.cs b/Source/Editor/Surface/Archetypes/Particles.cs index d5848a8e4..e0d7f2eb3 100644 --- a/Source/Editor/Surface/Archetypes/Particles.cs +++ b/Source/Editor/Surface/Archetypes/Particles.cs @@ -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[] { diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs index ee335d01d..7e9f5cd9d 100644 --- a/Source/Editor/Surface/Archetypes/Tools.cs +++ b/Source/Editor/Surface/Archetypes/Tools.cs @@ -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 }, diff --git a/Source/Editor/Surface/NodeArchetype.cs b/Source/Editor/Surface/NodeArchetype.cs index 006bd2fb6..b29dd0956 100644 --- a/Source/Editor/Surface/NodeArchetype.cs +++ b/Source/Editor/Surface/NodeArchetype.cs @@ -129,11 +129,6 @@ namespace FlaxEditor.Surface /// public NodeFlags Flags; - /// - /// If the node should use the as node size. If false, the node will auto resize based on its elements. - /// - public bool UseFixedSize = false; - /// /// Title text. /// diff --git a/Source/Editor/Surface/NodeFlags.cs b/Source/Editor/Surface/NodeFlags.cs index 27900bdb3..4201d9da1 100644 --- a/Source/Editor/Surface/NodeFlags.cs +++ b/Source/Editor/Surface/NodeFlags.cs @@ -78,6 +78,11 @@ namespace FlaxEditor.Surface /// VariableValuesSize = 2048, + /// + /// Node has fixed size defined and should not use automatic layout. + /// + FixedSize = 4096, + /// /// Node can be used in the all visual graphs. /// diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 2d440160f..e1dbeab90 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -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(); } /// @@ -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(); + } + /// 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(); } /// @@ -1007,10 +1010,7 @@ namespace FlaxEditor.Surface _isDuringValuesEditing = false; - if (!Archetype.UseFixedSize) - ResizeAuto(); - else - Resize(Archetype.Size.X, Archetype.Size.Y); + UpdateSize(); } /// @@ -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(); } ///