Fattorino / ImNodeFlow

Node based editor/blueprints for ImGui
MIT License
119 stars 15 forks source link

no input apart zooming in-out #20

Closed Paolo-Oliverio closed 2 months ago

Paolo-Oliverio commented 3 months ago

tested your simple example but i cannot move nodes around or make connections I can just zoom in and any other input is ignored.

the fact that zooming works makes me guess my imgui implementation is ok as it also works correctly if I make normal imgui widgets.

I probably I forgot to initialize something... does it ring some bells?

this is the nodeflow related code just as in the example

#pragma once
#include <ImNodeFlow.h>

namespace Node_Editor {

    using namespace ImFlow;

    ImNodeFlow* nodeFlow;

    class SimpleSum : public BaseNode
    {
    public:
        SimpleSum()
        {
            setTitle("Simple sum");
            setStyle(NodeStyle::green());
            addIN<int>("IN_VAL", 0, ConnectionFilter_Int);
            addOUT<int>("OUT_VAL", ConnectionFilter_Int)
                ->behaviour([this]() { return getInVal<int>("IN_VAL") + m_valB; });
        }

        void draw() override
        {
            ImGui::SetNextItemWidth(100.f);
            ImGui::InputInt("##ValB", &m_valB);
        }
    private:
        int m_valB = 0;
    };

    void init() {
        nodeFlow = new ImNodeFlow("node Editor");
        nodeFlow->addNode<SimpleSum>(ImVec2(0,0));
        nodeFlow->addNode<SimpleSum>(ImVec2(100, 100));
    }

    void shutdown() {
        delete nodeFlow;
    }

    void Exec() {
        nodeFlow->update();
    }
}
Fattorino commented 3 months ago

That's weird, did you clone the master branch or the latest stable release?

Paolo-Oliverio commented 3 months ago

tried both

Fattorino commented 3 months ago

Very strange, I'll look into it today

Fattorino commented 3 months ago

I cannot reproduce the issue, I suggest you try implementing a basic setup in the demo Imgui project to make sure it's not a problem caused by the "framework" you are using. Also keep in mind to move around the grid, by default the middle_mouse_click must be used

Paolo-Oliverio commented 3 months ago

I forgot to say it, but moving around also works, but not moving nodes or linking or pressing buttons on them. I'll try in another project with a different framework I'm actually using kinc and did the imgui port mostly from scratch. however I use it regularly for other imgui task especially in conjunction with implot where input works well i have also tryed to just run node editor window to exclude some other imgui widgets consume the input. I'm actually compiling with cpp latest specs in visual studio.

Fattorino commented 3 months ago

after you try in another project let me know, and we'll go from there

Paolo-Oliverio commented 3 months ago

in ImNodeFlow::update() I tryed to do auto mousepos = ImGui::GetMousePos(); Kiss::log::info("mouse pos: %f %f", mousepos.x, mousepos.y); // just my log function it reports right mouse positions if called before m_context.begin(); and huge negative number if called between your context.

there is something in m_context.begin() that breaks it i need to investigate further. same for Cursor that I probably don't set properly( I have to check this) as it gives a fixed vector(8 , 27) before context begin and (0,0) after for any mouse movement.

Clicks get captured properly but giving bad mouse pos I cannot interact with nodes as any rect test fails.

also addedd mouse events so now they get found during context begin when copied from src to dest but still no interaction possible, but I'm nearer to sort this out.

Fattorino commented 3 months ago

What backend do you use? Because I do all my testing with OpenGL

Paolo-Oliverio commented 2 months ago

my backend uses a common graphic and input layer for every api so d3d11 12 gl or vulkan or any input api don't make any difference for me and indeed all result in the same issue. Possibly my backend doesn't implement something required from your library that is at least optional in the general imgui use. I suspect that imgui has multiple way to pass it input that doesn't totally overlap so one way makes it break in some edge cases. Having isolated mouse position as the main cause of the lack of interaction I should be able to make it work. It is indeed strange that panning still works even if mouse position goes bananas entering your context. I'll get you updated it I found something weird in your implementation that prevent the use of more "uncommon" backends.

Paolo-Oliverio commented 2 months ago

Fixed it ... it was indeed strange as I never seen it in any backend

//original version: just imgui works nodes don't
void move(int x, int y, int movement_x, int movement_y)
{
    auto &io = ImGui::GetIO();
    io.MousePos = ImVec2((float)x, (float)y);
}

//Second version: just imgui works nodes don't
void move(int x, int y, int movement_x, int movement_y)
{
    auto &io = ImGui::GetIO();
    io.MousePos = ImVec2((float)x, (float)y);
    io.AddMousePosEvent((float)x, (float)y); // added this
}

//third version : Node editor works but every other imgui thing doesn't
void move(int x, int y, int movement_x, int movement_y)
{
    auto &io = ImGui::GetIO();
    // io.MousePos = ImVec2((float)x, (float)y); // commented out this line
    io.AddMousePosEvent((float)x, (float)y);
}

//Final version that works in all cases.
void move(int x, int y, int movement_x, int movement_y)
{
    auto &io = ImGui::GetIO();
    // inverted line order.
    io.AddMousePosEvent((float)x, (float)y);
    io.MousePos = ImVec2((float)x, (float)y);
}

Final version works flawlessly but checking out other backends them uses just one or the other way.

Fattorino commented 2 months ago

I must admit I'm still very puzzled by all this. I would like to do some testing of my own to better understand the issue. Is there a way I could have a minimal example of your code that reproduces the issue?

Paolo-Oliverio commented 2 months ago

It depends on my own framework actually on a local repo . I don't update github one since years.I realized it was too much efforts to document and maintain something not so popular even because also it's dependencies are lacking major documentation.I'll remember to contact you in case I manage to update it in a usable form.

Fattorino commented 2 months ago

since a solution was found, I'll close this issue for now