Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
1.97k stars 241 forks source link

Nodes can't be moved when multiple editors shown #112

Closed hoffstadt closed 3 years ago

hoffstadt commented 3 years ago

System Information

ImNodes 0.4
Dear ImGui 1.83
Operating System Windows 10
Graphics API Directx 11

Issue

Nodes can't be moved when multiple editors are used.

Minimal Example


        ImGui::Begin("Window 1");

        imnodes::BeginNodeEditor();

        imnodes::BeginNode(53);
        ImGui::Dummy(ImVec2(80.0f, 45.0f));
        imnodes::EndNode();

        imnodes::EndNodeEditor();

        ImGui::End();

        ImGui::Begin("Window 2");

        imnodes::BeginNodeEditor();

        imnodes::BeginNode(59);
        ImGui::Dummy(ImVec2(80.0f, 45.0f));
        imnodes::EndNode();

        imnodes::EndNodeEditor();

        ImGui::End();
Nelarius commented 3 years ago

I think my comment in this issue is relevant here, too. It should be possible, if a separate editor context instance is created. Let me know how it goes!

hoffstadt commented 3 years ago

Thanks for the help! This worked. For others who come across this, here is the solution:

        static auto context1 = imnodes::EditorContextCreate();
        static auto context2 = imnodes::EditorContextCreate();

        ImGui::Begin("Window 1");

        imnodes::EditorContextSet(context1);
        imnodes::BeginNodeEditor();

        imnodes::BeginNode(53);
        ImGui::Dummy(ImVec2(80.0f, 45.0f));
        imnodes::EndNode();

        imnodes::EndNodeEditor();

        ImGui::End();

        ImGui::Begin("Window 2");

        imnodes::EditorContextSet(context2);

        imnodes::BeginNodeEditor();

        imnodes::BeginNode(59);
        ImGui::Dummy(ImVec2(80.0f, 45.0f));
        imnodes::EndNode();

        imnodes::EndNodeEditor();

        ImGui::End();
TutajITeraz commented 3 years ago

Works great! Thank you!