Fattorino / ImNodeFlow

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

Mouse click on other window causes node selection to be cancelled #27

Closed eminor1988 closed 4 weeks ago

eminor1988 commented 1 month ago

I am not sure if it is the expected behavior for everyone or just in my usage scenarios.

By the design of my game engine, the user first selects some nodes in the graph, then the inspector window shows all properties of the selected nodes.

But when the user wants to click a button on the inspector window, suddenly the nodes are not selected anymore, and the inspector window does not show any properties of the nodes anymore (because the selection is canceled).

I added the IsWindowHovered() condition when selecting the node in "void BaseNode::update()", which fixes the problem:

// Orig:
if (!ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ...)
    selected(false);

// My check:
if (ImGui::IsWindowHovered() && !ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ...)
    selected(false);

And for the destroy(), I added the IsWindowFocused() condition

// Orig:
if (ImGui::IsKeyPressed(ImGuiKey_Delete) && !ImGui::IsAnyItemActive() && isSelected())
    destroy();

// My check:
if (IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_Delete) && !ImGui::IsAnyItemActive() && isSelected())
    destroy();

But I am not sure if it is a bug or the expected behavior, so I am just reporting it here.

Fattorino commented 4 weeks ago

Fixed in commit 6a28db5