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?
Additionally, I would really like a way to give keyboard focus to a specific text field...
xythobuz: separate issue/thread please.
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?
Yes, thanks for the information! This setup sounds good to me, since I just need to know when to block input to my code.
Most helpful comment
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?