SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.14k stars 172 forks source link

updateMouseCursor overrides SFML setMouseCursorVisible(false) call #177

Open ghost opened 3 years ago

ghost commented 3 years ago

I have an application which has a toggle for when I'm debugging & when I'm testing and I noticed a problem with the function:

void updateMouseCursor(sf::Window& window) 

I have my mouse cursor set to hidden when testing (and all ImGui windows not set to be created) but this function kept overriding the value. I narrowed it down to the following line:

if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None) {
    window.setMouseCursorVisible(false);
} else {
    window.setMouseCursorVisible(true);

    sf::Cursor& c = s_mouseCursorLoaded[cursor] ? *s_mouseCursors[cursor] :
                                                    *s_mouseCursors[ImGuiMouseCursor_Arrow];
    window.setMouseCursor(c);
}

With the above logic if you have your ImGui IO set to not draw the cursor it takes the else branch. Do I need to set both of these values in ImGui and disregard the SFML RenderWindow function?

ImGui::SetMouseCursor(ImGuiMouseCursor_None); // used this to get round the issue
io.MouseDrawCursor = false; // this was the line that made me aware of the issue
eliasdaler commented 3 years ago

Hello Yeah, I see no other way of handling this, unfortunately. When you set io.MouseDrawCursor to true, we definitely need to disable the cursor. And when users then set io.MouseDrawCursor to false, there's no way to recover from that properly without requiring users to manually call window.setMouseCursorVisible(true); afterwards which doesn't seem ideal to me.

If you have some idea of how changing the value io.MouseDrawCursor can be made invisible to the user (without requiring them to call window.setMouseCursorVisible(false/true); manually) , that'd be great.

ghost commented 3 years ago

I tried experimenting with it but I couldn't find a great alternative either, I guess for now calling it manually is the only way. May be worth leaving a comment about it somewhere just in case someone else runs into it. But aside from that, I can't see a better way to handle it either