Skip to content

Don't drag draggables on scroll events#29842

Merged
timhoffm merged 3 commits into
matplotlib:mainfrom
dstansby:scroll-drag
Apr 2, 2025
Merged

Don't drag draggables on scroll events#29842
timhoffm merged 3 commits into
matplotlib:mainfrom
dstansby:scroll-drag

Conversation

@dstansby

Copy link
Copy Markdown
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

timhoffm commented Apr 1, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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

timhoffm commented Apr 1, 2025

Copy link
Copy Markdown
Member

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

dstansby commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

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.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

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.


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

Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread lib/matplotlib/offsetbox.py
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