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

Opening a popup only when the mouse hasn't dragged #2419

Closed
rick-de-water opened this issue Mar 13, 2019 · 6 comments
Closed

Opening a popup only when the mouse hasn't dragged #2419

rick-de-water opened this issue Mar 13, 2019 · 6 comments
Labels
drag drop drag and drop inputs

Comments

@rick-de-water
Copy link

Version/Branch of Dear ImGui:

Version: 1.69 WIP (16899)
Branch: docking

My Issue/Question:

I want to open a popup when the user right clicks with the mouse, but ONLY if the user hasn't dragged the mouse while holding the right mouse button.

I have tried combining ImGui::IsMouseReleased(1) with a check to see if ImGui::GetMouseDragDelta(1) returned a zero length vector, but the drag delta seems to already have been reset at that point.

Is there a way to check if the mouse was dragging when it was released? I would like to avoid keeping track of this myself.

@ocornut
Copy link
Owner

ocornut commented Mar 13, 2019 via email

@rick-de-water
Copy link
Author

The context is a node graph. I use the left mouse button for selecting nodes, and the right mouse drag to scroll. But I also want the right mouse button to open a popup menu when all the user did was right click without scrolling. So that is why I need to know if the right mouse button was dragging when it was released.

@rick-de-water
Copy link
Author

io.MouseDragMaxDistanceSqr seems to do the job, but it does completely ignore MouseDragThreshold.

I would prefer it if GetMouseDragDelta returned a non zero value on g.IO.MouseDown[button] || g.IO.MouseReleased[button] instead of just g.IO.MouseDown[button], but I don't know if that breaks anything.

@ocornut ocornut added drag drop drag and drop inputs labels Mar 15, 2019
ocornut added a commit that referenced this issue Mar 15, 2019
…sed frame. Verify that mouse positions are valid otherwise returns zero. Removed obsolete comment. Tweaked demo. (#2419)
@ocornut
Copy link
Owner

ocornut commented Mar 15, 2019

I made that change, it makes sense to me.

(I wish I had access to more large codebase to better study how people use functions xx and xx, but a quick survey of users of this on public github repo confirms the side-effect seem harmless).

Let me know if that indeeed solve your issue!

@ocornut ocornut closed this as completed Mar 15, 2019
@rick-de-water
Copy link
Author

It works great! But I just noticed that it is now inconsistent with IsMouseDragging, since that still returns false on the release frame. Should that function be updated as well?

@ocornut
Copy link
Owner

ocornut commented Mar 17, 2019 via email

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

No branches or pull requests

2 participants