Don't drag draggables on scroll events by dstansby · Pull Request #29842 · matplotlib/matplotlib · GitHub
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

@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

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