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

Added callback functions for Grab/Release Node events handling #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xahon
Copy link

@xahon xahon commented May 27, 2023

Fixes #168

Usage:

ImNodes::BeginNodeEditor();

// ...

// Creating nodes each frame from state arrays
for (int i = 0; i < graph.nodes.size(); i++)
{
    const int id = graph.nodes[i];
    const float node_x = graph.nodes_x[i];
    const float node_y = graph.nodes_y[i];

    ImNodes::BeginNode(id);
    ImNodes::SetNodeGridSpacePos(id, ImVec2(node_x, node_y));
    ImNodes::EndNode();
}

// ...

int num_selected_nodes;

if (ImNodes::IsNodesDragStarted(&num_selected_nodes))
{
    std::vector<int> selected_nodes(num_selected_nodes);
    ImNodes::GetSelectedNodes(selected_nodes.data());

    for (int i = 0; i < selected_nodes.size(); i++)
    {
        const int id = selected_nodes[i];
        printf("Node was just grabbed %d\n", id);
    }
}

if (ImNodes::IsNodesDragStopped(&num_selected_nodes))
{
    std::vector<int> selected_nodes(num_selected_nodes);
    ImNodes::GetSelectedNodes(selected_nodes.data());

    for (int i = 0; i < selected_nodes.size(); i++)
    {
        const int id = selected_nodes[i];
        printf("Node was just released %d\n", id);
        // Store nodes changed positions here
        // const ImVec2 &new_node_pos = ImNodes::GetNodeGridSpacePos(id);
    }
}

// ...

ImNodes::EndNodeEditor();

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 this pull request may close these issues.

Callback on node translation
1 participant