Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback on node translation #168

Open
kiranshila opened this issue Oct 3, 2022 · 2 comments · May be fixed by #186
Open

Callback on node translation #168

kiranshila opened this issue Oct 3, 2022 · 2 comments · May be fixed by #186

Comments

@kiranshila
Copy link

Hey! First off, thanks for the great library!

I'm storing node data, including the positions in my own data structure and am a little stuck on how to update my representation of the positions.

When I draw the editor, I'm calling ImNodes::SetNodeScreenSpacePosition from a "realized" graph that contains its positions. Something in the background must be overwriting this behavior as I can drag a node around, but once I release a node - it of course snaps back to the position stored in my data structure.

My question is, how can I intercept the result of node translation in order to update my representation? I tried something the likes of

int num_selected_nodes = ImNodes::NumSelectedNodes();
if (num_selected_nodes > 0 && ImGui::IsMouseReleased(0)) {
  int *mod_ids = (int *)malloc(num_selected_nodes * sizeof(int));
  ImNodes::GetSelectedNodes(mod_ids);
  for (int i = 0; i < num_selected_nodes; i++) {
    int mod_id = mod_ids[i];
    ImVec2 pos = ImNodes::GetNodeScreenSpacePos(mod_id);
    rs::set_module_position(mod_id, pos[0], pos[1]);
  }
  free(mod_ids);
}

But GetNodeScreenSpacePos doesn't seem to be set by the time my if block runs, as it still contains the original position.

Any help would be appreciated.

@kiranshila
Copy link
Author

Ah, it seems the positioning of SetNodeScreenSpace matters here. If I set the position before the call to BeginNode I can no longer move nodes around

@xahon
Copy link

xahon commented May 27, 2023

@kiranshila I just encountered the same problem as well, you can test my implementation of this feature
It works in my project, I'm able now to save positions of nodes between save/load sessions
If you have any questions on it, feel free to ask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants