thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.73k stars 550 forks source link

Question: Embedding editor within a window? #288

Closed SheridanR closed 6 months ago

SheridanR commented 7 months ago

Hi,

Sorry for the trivial question, but the examples and the documentation (sparse as it is) are not giving me any clues about this.

Whenever I try to embed the editor canvas in a window (ie ImGui::Begin() / ImGui::End()) the canvas is completely broken. Eg:

Screenshot 2024-04-18 at 12 09 05

Here is my code:

        if (ImGui::Begin("Node Graph")) {
            ed::SetCurrentEditor(imguiNodeEditorContext);
            ed::Begin("My Editor", ImVec2(1000.f, 750.f));
            int uniqueId = 1;
            // Start drawing nodes.
            ed::BeginNode(uniqueId++);
                ImGui::Text("Node A");
                ed::BeginPin(uniqueId++, ed::PinKind::Input);
                    ImGui::Text("-> In");
                ed::EndPin();
                ImGui::SameLine();
                ed::BeginPin(uniqueId++, ed::PinKind::Output);
                    ImGui::Text("Out ->");
                ed::EndPin();
            ed::EndNode();
            ed::End();
            ed::SetCurrentEditor(nullptr);
        }
        ImGui::End();

Changing the size of the canvas eg ed::Begin("My Editor", ImVec2{0.f, 0.f}) seems to make no difference.

Am I missing something??

thedmd commented 6 months ago

I did paste your example into simple-example.cpp and it does look fine.

If this is still issue for you please reopen with more details. Thanks!

image

fenix31415 commented 3 months ago

Looks like I have similar problem. The canvas doesn't fill available window. изображение Moreover, I can move it with scrolling (right button). изображение Zoom also have weird behavior: zoom in decreases canvas, while zoom out -- increases. изображение изображение

The code is simple, I even did't create any nodes.

On update:

if (ImGui::Begin("Info")) {
    ed::SetCurrentEditor(m_Context);
    ed::Begin("My Editor");
        ed::End();
        ed::SetCurrentEditor(nullptr);
}
ImGui::End();

m_Context is initialized this way: m_Context = ed::CreateEditor(); once, while initializing.

hitakiri commented 3 months ago

I have same problem. Is there any way to use node-editor in new window?

fenix31415 commented 3 months ago

I have recently built it by copying code in my project. I.e. without vcpkg. It works fine so far. I haven't enough time to investigate the problem though.

MacXxs commented 5 days ago

I'm using imgui v1.90 and NodeEditor v0.9.3, and this issue still persists ClippingIssue