Skip to content

Callback on node translation #168

@kiranshila

Description

@kiranshila

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions