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

implicit debug window disturbs IsPosHoveringAnyWindow() #1237

Closed
acda opened this issue Jul 19, 2017 · 8 comments
Closed

implicit debug window disturbs IsPosHoveringAnyWindow() #1237

acda opened this issue Jul 19, 2017 · 8 comments
Labels

Comments

@acda
Copy link

acda commented Jul 19, 2017

Hi.

I am using the call to ImGui:: IsPosHoveringAnyWindow() to check if a user clicked a point not on any ImGui window, so I can interact with my gameview.

There is a debug-window created with the comment that it won't appear if it does not get any fields. But it still appears as a hit on IsPosHoveringAnyWindow(), creating a blind spot on my gamescreen.

Code in NewFrame() which creates it was this:

// Create implicit window - we will only render it if the user has added something to it.
ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiSetCond_FirstUseEver);
ImGui::Begin("Debug");

Right now, I am using a temporary fix inside FindHoveredWindow() , by not returning any hit which has the 'Accessed' flag false. Seems to work. But maybe there are conditions where this is not correct. Needs to be linked to the flag or condition which decides if the debug window is rendered or not.

Here is the diff of my workaround:

@@ -3110,7 +3110,7 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)

         // Using the clipped AABB so a child window will typically be clipped by its parent.
         ImRect bb(window->WindowRectClipped.Min - g.Style.TouchExtraPadding, window->WindowRectClipped.Max + g.Style.TouchExtraPadding);
-        if (bb.Contains(pos))
+        if (bb.Contains(pos) && window->Accessed)
             return window;
     }
     return NULL;
@ocornut
Copy link
Owner

ocornut commented Jul 19, 2017

Nice catch, it's an interesting bug and I'm surprised it hasn't been caught before (but then IsPosHoveringAnyWindow is rarely used).

Repro:

ImGui::Begin("Bug #1237");
ImGui::Text("%d", ImGui::IsPosHoveringAnyWindow(ImGui::GetIO().MousePos));
ImGui::End();

I'm looking into it now.

@ocornut ocornut added the bug label Jul 19, 2017
@ocornut
Copy link
Owner

ocornut commented Jul 19, 2017

IsPosHoveringAnyWindow is even more broken as Active is cleared in NewFrame so it will only work for windows created before the call to IsPosHoveringAnyWindow during the frame.

@ocornut
Copy link
Owner

ocornut commented Jul 19, 2017

I am using the call to ImGui:: IsPosHoveringAnyWindow() to check if a user clicked a point not on any ImGui window, so I can interact with my gameview.

By the way, even though I am going to fix this function, as outlined in the documentation you want to use io.WantCaptureMouse and NOT IsPosHoveringAnyWindow for that.

@ocornut
Copy link
Owner

ocornut commented Jul 19, 2017

Considering just removing this function:

  • I actually cannot think of a use for this function at the moment,
  • And it is misleading and every user of it I found on Google and some private repo I can access should have used io.WantCaptureMouse for the correct behaviour (it handles cases such as clicking a widget and dragging outside the window).
  • It's very broken as you and me just pointed out, which suggests that nobody was seriously relying on it.

Do anybody reading this as a legit use for this function?

@acda
Copy link
Author

acda commented Jul 19, 2017

wow you are quick to react.

I changed my code to use WantCaptureMouse, and it works. Missed that one. Thanks.

@acda
Copy link
Author

acda commented Jul 19, 2017

I think the function still does makes sense. Maybe not for mouse input, but just for determining if an item at some coordinate of the gameview is above/below/covered-by the Gui.

ocornut added a commit that referenced this issue Jul 20, 2017
…ding (most people want to use io.WantCaptureMouse). Added dummy function with assert for now. (#1237)
@ocornut
Copy link
Owner

ocornut commented Jul 20, 2017

I just removed it for now, because fixing it correctly isn't that trivial and as pointed above it's very unlikely people have been relying on a broken function.

Totally happy to add a fixed version if someone ever has a need for it but right now I'm not aware of anyone using it and it's not worth adding a feature without a user.

Thanks for your report!

@AnonN10
Copy link

AnonN10 commented May 8, 2022

@ocornut sad to find it's never been properly fixed as it would have been a very useful set of functions in my case.
Since ImGui does not implement drag and drop for files, I decided to implement it myself, but there is a problem in determining which window the file has been dropped to. I could use WantCaptureMouse and other states, however it's never set unless the application window has focus, and dropping a file over it does not give focus either. I could try to give the window focus, but it's too intrusive and doesn't guarantee that WantCaptureMouse will be set at the right time (it most likely won't be). All in all it seems that my only options here are to manually query window under a certain position.

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

No branches or pull requests

3 participants