From e91e80bfcfaa743efdad80a4cf2aec2dd96e5a92 Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Fri, 24 Apr 2026 22:04:07 +0200 Subject: [PATCH] fix(shaders_lab): node drag was overwritten by SetNodePosition each frame Previously SetNodePosition was called after EndNode every frame, which reset any drag the user had done. Now the initial position is set once per editor_uid (tracked in a static unordered_set), and the editor owns the position afterwards. GetNodePosition at end-of-frame keeps step state in sync for future persistence. Co-Authored-By: Claude Opus 4.7 (1M context) --- cpp/functions/gfx/dag_node_editor.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/cpp/functions/gfx/dag_node_editor.cpp b/cpp/functions/gfx/dag_node_editor.cpp index cf5a09ce..c57df7d7 100644 --- a/cpp/functions/gfx/dag_node_editor.cpp +++ b/cpp/functions/gfx/dag_node_editor.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace ed = ax::NodeEditor; @@ -15,8 +16,9 @@ namespace fn::gfx { static constexpr int MAX_NODES = 16; -static ed::EditorContext* s_ctx = nullptr; -static uint32_t s_next_uid = 1; +static ed::EditorContext* s_ctx = nullptr; +static uint32_t s_next_uid = 1; +static std::unordered_set s_positioned; // ── ID encoding ────────────────────────────────────────────────────────────── // node id = editor_uid @@ -213,6 +215,18 @@ bool dag_node_editor(std::vector& pipeline) { ImVec4 col = kind_color(def->kind); + // Initial position only — after that, the editor owns the node's position + // and user drags must not be overwritten. + if (s_positioned.find(step.editor_uid) == s_positioned.end()) { + if (step.editor_pos_x == 0.0f && step.editor_pos_y == 0.0f) { + step.editor_pos_x = 50.0f + static_cast(i) * 220.0f; + step.editor_pos_y = 100.0f; + } + ed::SetNodePosition(ed::NodeId(node_id(step.editor_uid)), + ImVec2(step.editor_pos_x, step.editor_pos_y)); + s_positioned.insert(step.editor_uid); + } + ed::BeginNode(ed::NodeId(node_id(step.editor_uid))); // Header @@ -272,14 +286,6 @@ bool dag_node_editor(std::vector& pipeline) { ed::EndPin(); ed::EndNode(); - - // Set initial position if not yet placed (both zero = first time) - if (step.editor_pos_x == 0.0f && step.editor_pos_y == 0.0f) { - step.editor_pos_x = 50.0f + static_cast(i) * 220.0f; - step.editor_pos_y = 100.0f; - } - ed::SetNodePosition(ed::NodeId(node_id(step.editor_uid)), - ImVec2(step.editor_pos_x, step.editor_pos_y)); } // ── Draw existing links ──────────────────────────────────────────────────