Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.WantCaptureMouse possible bug because of the way rllmGui is implemented #49

Closed
Andi7891 opened this issue Dec 23, 2023 · 4 comments
Closed

Comments

@Andi7891
Copy link

Andi7891 commented Dec 23, 2023

I have a simulator for point charges and I have implemented a function that allows charges to be dragged while holding mouse left button. I want to block dragging charges function under the ImGui windows.
I have succeeded to block all other functions under ImGui windows like (Add Charge, Remove Charge, Select Charge), but all these functions have in common IsMouseButtonPressed function.
For the dragging charges function I used IsMouseButtonDown and I observed that the dragging is still working under the ImGui windows, and after a bit of debugging I found out that the io.WantCaptureMouse variable is not changed If I hold the left button, and I think that these lines are the reason, because they are taking into consideration only the Pressed function, but the Down function has a different behavior.

auto setMouseEvent = [&io](int rayMouse, int imGuiMouse) { if (IsMouseButtonPressed(rayMouse)) io.AddMouseButtonEvent(imGuiMouse, true); else if (IsMouseButtonReleased(rayMouse)) io.AddMouseButtonEvent(imGuiMouse, false); };

How could I fix the problem?
Changing the approach maybe, or is there an alternative for the rllImGui Process Event function that would fix the problem?
Maybe I am missing something.
Thank you.

@Andi7891
Copy link
Author

Andi7891 commented Dec 23, 2023

I reproduced the same thing with SDL as the backend and I got the same problem, the io.WantCaptureMouse is updated only after you release the mouse left button. Which means that my approach of detecting this kind of overlapping while holding the button is wrong.
Do you have suggestions of how should I implement this behavior of disable dragging if the mouse is over an imgui window?

A bit older issue related to this problem is this one: ocornut/imgui#1392

@JeffM2501
Copy link
Contributor

I'm not sure what you are talking about here.

setMouseEvent looks for state changes in the mouse button and passes them as events to ImGui. IsMouseButtonPressed detects when the button goes from up to down and sends a down event to ImGui. IsMouseButtonReleased does the opposite. ImGui detects the down state by these events. You can see the state is correct in the ImGui demo window's input section.
We don't need to check raylib's down state because the length of the down state should always start with a press and end with a release.

if you want to know if ImGui is using the mouse you can look at WantCaptureMouse in the io structure. When that is true, your application should ignore the mouse input because ImGui is using it.

@Andi7891
Copy link
Author

Andi7891 commented Jan 3, 2024

I was not clear enough. I am sorry.
My problem is that if I HOLD the mouse's left button pressed anywhere on the main window(not on an Imgui panel) and then I move the cursor on any Imgui window while holding the left button pressed the io.WantCaptureMouse is updated only after releasing the left button. Now, I understand why is working the way it does. When I created the issue I was not sure how I could
have fixed the problem or what was the problem exactly, and still, I do not have a solution to this problem. Is there a different approach that could mitigate this limitation of io.WantCaptureMouse?
Because is clear that io.WantCaptureMouse is not appropriate in this situation, and I need something that checks if the cursor position is inside of an Imgui panel.
The main problem is because the mouse left button is not released the imgui doesn't receive the event so there are no checkings done for io.WantCaptureMouse.
Thank you for your response and your time.

@JeffM2501
Copy link
Contributor

I think this is by design and not something that rlImGui can control.

When you click outside of an ImGui element, ImGui knows that the app has focus. During the drag, the focus does not change until that focused event ends. Basically if you start a drag outside of ImGui, it stays alive even if it goes 'under' ImGui, so your drag is not interrupted.

Changing capture during the drag would break the expected behavior of the drag staying in the app's context. WantCapture is only true when ImGui knows 100% that it wants the input. In the middle of a background drag, it doesn't know if it can or should take over that drag, so it can't return true there. There is no change that can be made to rlImGui that will change this behavior.

If you want to break your drag when you go over an element, then I think you may need to check the hover state of your windows and set your own flag. You would then have to pick up your drag again when you leave a hover state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants