Skip to content

Add raw mouse wheel event#2782

Merged
emilk merged 6 commits intoemilk:masterfrom
YgorSouza:mouse-wheel-event
Apr 18, 2023
Merged

Add raw mouse wheel event#2782
emilk merged 6 commits intoemilk:masterfrom
YgorSouza:mouse-wheel-event

Conversation

@YgorSouza
Copy link
Copy Markdown
Contributor

The event is sent as it comes from the backend, so it will follow different conventions depending on the target, and it is up to the user code to deal with that. The goal is to allow advanced users to implement alternative UI controls, e.g., using Ctrl to scroll the plot horizontally instead of zooming, or use Shift to scroll faster instead of changing direction.

Closes #2718.

The event is sent as it comes from the backend, so it will follow
different conventions depending on the target, and it is up to the user
code to deal with that. The goal is to allow advanced users to implement
alternative UI controls, e.g., using Ctrl to scroll the plot
horizontally instead of zooming, or use Shift to scroll faster instead
of changing direction.
@YgorSouza
Copy link
Copy Markdown
Contributor Author

This implementation provides maximum information and flexibility to the user of egui, but it also gives them the burden of having to know the specifics of the backend/target they're building for. For example, in winit, scrolling down one step produces a delta of (0.0, -1.0) lines, whereas in web the delta is (0.0, 6.0) lines. Also, the x and y coordinates are swapped when holding down shift on macOS (both winit and web), but not on other targets.

An alternative would be to create a universal convention, similar to how the Scroll event is handled currently, while still providing a specific MouseWheel event in addition to the opinionated conversion to Zoom/Scroll, so the user can handle the wheel event as they prefer but still get consistent behavior across all platforms without having to know the specifics of each one.

But this convention would end up being very similar to the Scroll event itself, so maybe an easier solution would be to just not convert the mouse wheel to Zoom automatically, or allow the user to opt out of this conversion and always get a Scroll event even when Ctrl is down.

Copy link
Copy Markdown
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Good idea, but let's use the same unit (points) for both web and native

Apply suggestions from code review by emilk

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
It was meant only to be able to use the same variable names without
shadowing the rest of the code, but a simple block accomplishes the same
thing.
YgorSouza and others added 3 commits March 30, 2023 19:53
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
To avoid doing the same match and sign conversion twice.
@emilk emilk merged commit 8326fff into emilk:master Apr 18, 2023
@emilk
Copy link
Copy Markdown
Owner

emilk commented Apr 18, 2023

This is great; thank you!

TicClick pushed a commit to TicClick/egui that referenced this pull request Apr 18, 2023
* Add raw mouse wheel event

The event is sent as it comes from the backend, so it will follow
different conventions depending on the target, and it is up to the user
code to deal with that. The goal is to allow advanced users to implement
alternative UI controls, e.g., using Ctrl to scroll the plot
horizontally instead of zooming, or use Shift to scroll faster instead
of changing direction.

* Change Pixel to Point for consistency

Apply suggestions from code review by emilk

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* Inline mouse wheel raw event closure

It was meant only to be able to use the same variable names without
shadowing the rest of the code, but a simple block accomplishes the same
thing.

* Use wildcard on wheel event match

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* Flip mouse wheel delta sign on web to match native

* Use wheel event data to generate scroll event

To avoid doing the same match and sign conversion twice.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
@emilk emilk added feature New feature or request egui labels Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

egui feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose raw mouse wheel delta to allow alternative input

2 participants