Skip to content

Don't drag draggables on scroll events #29842

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

Merged
merged 3 commits into from
Apr 2, 2025
Merged

Conversation

dstansby
Copy link
Member

PR summary

Fixes #29142; replaces #29270. The solution here is to set a custom picker on DraggableBase that doesn't fire if the event is a scroll event.

PR checklist

@tacaswell tacaswell added this to the v3.10.2 milestone Mar 31, 2025
@timhoffm
Copy link
Member

timhoffm commented Apr 1, 2025

Why do we need a custom picker / why does the regular picker fire on scroll events? Should it be fixed generally on the regular picker?

@tacaswell
Copy link
Member

A scroll event comes in looking just like a button press (but with a higher number). It does not seem unreasonable to allow these to trigger pick events in general but to disable them for draggable things specifically.

@timhoffm
Copy link
Member

timhoffm commented Apr 1, 2025

I don't think I understand this: "Pick" is logically selecting an element by clicking on it. No matter the technical implementation, why should scrolling ever be interpreted as pick? In what use case would that make sense?

@dstansby
Copy link
Member Author

dstansby commented Apr 1, 2025

pick is possibly an unfortunate choice of language. As an example of a picker that uses scroll, if I wanted to make an artist change size if the mouse is over it and scrolled, then giving a custom function to Artist.set_picker() would be the way to do this.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anybody can merge after adding the suggested documentation.

@@ -1500,6 +1500,10 @@ def __init__(self, ref_artist, use_blit=False):
]
]

@staticmethod
def _picker(artist, mouseevent):
return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {}
"""
A custom picker to prevent dragging on scroll events.
Dragging is initialized through a pick events, which is typically a
mouse click. However, mouse scrolling also fires pick events and
we need to filter them out so that scrolling does not initalize
dragging.
"""
return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to adding a comment - I thought this was a bit verbose for a private helper function, so I added a one-liner instead - what do you think?

@timhoffm timhoffm merged commit a364dc5 into matplotlib:main Apr 2, 2025
40 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 2, 2025
@dstansby dstansby deleted the scroll-drag branch April 2, 2025 18:42
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

Successfully merging this pull request may close these issues.

[MNT]: Draggable legend gets stuck on cursor after scroll event
3 participants