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) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
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<uint32_t> s_positioned;
|
||||
|
||||
// ── ID encoding ──────────────────────────────────────────────────────────────
|
||||
// node id = editor_uid
|
||||
@@ -213,6 +215,18 @@ bool dag_node_editor(std::vector<DagStep>& 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<float>(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<DagStep>& 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<float>(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 ──────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user