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

Detect mouse over any ImGUI window #52

Closed
mattiasljungstrom opened this issue Sep 30, 2014 · 5 comments
Closed

Detect mouse over any ImGUI window #52

mattiasljungstrom opened this issue Sep 30, 2014 · 5 comments

Comments

@mattiasljungstrom
Copy link

This is more of a question. How do I detect if the mouse is currently over any ImGui window? Is this supported? Also, how do I detect if any input box currently has focus?

@xythobuz
Copy link
Contributor

Additionally, I would really like a way to give keyboard focus to a specific text field...

@ocornut
Copy link
Owner

ocornut commented Sep 30, 2014

xythobuz: separate issue/thread please.

@ocornut
Copy link
Owner

ocornut commented Sep 30, 2014

Mattias: I suspect that your underlying question is that you'd like to know when to pass your inputs to ImGui, i am right ?

In the IO structure you can find:
bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)

This is updated by NewFrame() so the idea is that you pass your raw inputs to ImGui but it doesn't necessary use them. If the flag aren't set you can pass the inputs back to the rest of your application.

Now, through various feedbacks it appears that this was confusing to some engine architecture, e.g. if you are trying to dispatch inputs events directly to the right target. My suggestion would be to just store data and pass it to ImGui before NewFrame().

You can set io.MousePos and call ImGui::IsMouseHoveringAnyWindow() to test if a position is over a window. Detect if a widget has focus for keyboard is IO.WantCaptureKeyboard.

I think I need to revamp those API to be a little more clear. Perhaps adding an explicit WidgetHasFocus thing?

@mattiasljungstrom
Copy link
Author

Yes, thanks for the information! This setup sounds good to me, since I just need to know when to block input to my code.

@Bonkt
Copy link

Bonkt commented May 6, 2022

I want to do something similar to this. (using sfml) i render my main application to a sf::RenderTexture that i then display on ImGui::Image(). So basically my dockspace and my whole window is at all times completely covered by ImGui windows.

So when i try to dispatch mouse clicks to my application i want to check if io.WantCaptureMouse.
The problem is that i also want to be able to move my "application" window around. So setting the flag ImGuiWindowFlags_NoMouseInputs does not work.

I read at many places that io.WantCaptureMouse is prefered over IsWindowHovered().
Is this still the case for my use case? Or would a new flag with a name like
ImGuiWindowFlags_OnlyMouseInputsOnTitlebar be a useful addition to the API?

Edit:
Basically i want to create something similiar looking to the "Canvas" demo. But instead of rendering the canvas in ImGui i want to render in SFML to a texture and then display that on a ImGui windows.

@ocornut

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

4 participants