rokups / ImNodes

Node graph implementation for Dear ImGui. Used in https://github.com/rokups/rbfx
MIT License
656 stars 57 forks source link

context menu on node content #40

Open sphaero opened 2 years ago

sphaero commented 2 years ago

Imagine I want to add a context menu on node content. In the sample.cpp:

                // Custom node content may go here
                ImGui::Text("Content of %s", node->Title);
                const char* names[5] = { "Label1", "Label2", "Label3", "Label4", "Label5" };
                for (int n = 0; n < 5; n++)
                {
                    ImGui::Selectable(names[n]);
                    if (ImGui::BeginPopupContextItem()) // <-- use last item id as popup id
                    {
                        ImGui::Text("This a popup for \"%s\"!", names[n]);
                        if (ImGui::Button("Close"))
                            ImGui::CloseCurrentPopup();
                        ImGui::EndPopup();
                    }
                    if (ImGui::IsItemHovered())
                        ImGui::SetTooltip("Right-click to open popup");
                }

This is just pasted from imgui_demo.cpp

This doesn't work. Only the context menu for adding nodes is opened.

sphaero commented 2 years ago

Probably has to do with using Set-/ClearActiveID

Not sure how that's handled correctly

https://github.com/rokups/ImNodes/blob/26c6dbc981da747eb49f2d9f29efe808bd22ab7a/ImNodes.cpp#L451-L454