-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Mouse delta from DeviceEvent #1614
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This needs a line in the egui
changelog so other integrations knows to use the new event.
Also: should this be implemented for eframe
web?
5cd6bde
to
8ffe94c
Compare
it could be, i think. web-event has delta already. anyway, as i said it should not break existing behavior, if there was no MouseDelta emmited |
Bad news. web just cant delta. I thought this numeric input works, I thought this works https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX But seems not. So in wasm it works the old way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with this approach: the units emitted by MouseMotion
is in unspecified units: https://docs.rs/winit/latest/winit/event/enum.DeviceEvent.html#variant.MouseMotion
For instance, these units may be ignoring mouse sensitivity or acceleration. Therefor it is not equivalent to comparing changes in pointer position. I think if you really want to use this in a UI we need to assign it to something else than PointerState::delta
, and keep that to mean "mosue movements in points", and perhaps add a separate motion: Vec2
for these unspecified units (which can still fall back to changes in pointer position for integrations that don't emit MosueDelta
events.
egui/src/data/input.rs
Outdated
/// The mouse delta from winit::DeviceEvent. MouseDelta and PointerMoved can be emmited simultaneously. | ||
/// If MouseDelta accumulated value is zero per frame, then `old_pos-new_pos` will be used as fallback. | ||
/// For now it used in situations when we need delta but mouse pointer is on screen edge. | ||
MouseDelta(Vec2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The mouse delta from winit::DeviceEvent. MouseDelta and PointerMoved can be emmited simultaneously. | |
/// If MouseDelta accumulated value is zero per frame, then `old_pos-new_pos` will be used as fallback. | |
/// For now it used in situations when we need delta but mouse pointer is on screen edge. | |
MouseDelta(Vec2), | |
/// Mouse movement in unspecified units. | |
/// | |
/// Both [`Self::MouseDelta`] and [`Self::PointerMoved`] can both be emitted for the same movement, | |
/// but when a pointer is grabbed or at the edge of the screen, only [`Self::MouseDelta`] is emitted. | |
/// | |
/// Some integrations do not emit any [`Self::MouseDelta`]. In these cases the change in [`Self::PointerMoved`] will be used for [`PointerState::delta`]. | |
MouseDelta(Vec2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The mouse delta from winit::DeviceEvent." is true for one of many backends, but not for all.
These docstrings have two targets: egui users, and people writing egui integrations.
|
6920558
to
40b3f10
Compare
33b6a5f
to
8e334d6
Compare
2984981
to
e401fa4
Compare
Squashed and rebased |
egui/src/data/input.rs
Outdated
/// The mouse delta from winit::DeviceEvent. MouseDelta and PointerMoved can be emmited simultaneously. | ||
/// If MouseDelta accumulated value is zero per frame, then `old_pos-new_pos` will be used as fallback. | ||
/// For now it used in situations when we need delta but mouse pointer is on screen edge. | ||
MouseDelta(Vec2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The mouse delta from winit::DeviceEvent." is true for one of many backends, but not for all.
These docstrings have two targets: egui users, and people writing egui integrations.
Sorry. Is any changes still needed? I was trying to document my best, but there is long story behind this stuff |
res | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not egui
s responsibility to have platform-specific code like this. Instead it is up to the integrations to feed egui
with the correct input.
In this case the winit backend should feed different data than the web backend. Other integrations needs to do whats right for them.
So if this is called mtion_delta
then it should probably use self.ctx.input().pointer.motion()
regardless of what the compilation target is.
Also: 'wasm" doesn't mean "web". There are egui users who run egui in wasmtime on desktop.
// in a case of touchscreen or whatever | ||
self.ctx.input().pointer.delta() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe touch screens should set motion
too?
Better yet: RawInput
could have motion: Option<Vec2>
and then InputState::begin_frame
would use it if set, or else fall back to the pointer delta. That way it will work correctly for all existing backends.
Raw mouse movement is unaccelerated and unclamped by screen boundaries, and does not relate to any position on the screen. It is useful in certain situations such as draggable values and 3D cameras, where screen position does not matter. https://github.com/emilk/egui/assets/1700581/1400e6a6-0573-41b9-99a1-a9cd305aa1a3 Added `Event::MouseMoved` for integrations to supply raw mouse movement. Added `Response:drag_motion` to get the raw mouse movement, but will fall back to delta in case the integration does not supply it. Nothing should be breaking, but third-party integrations that can send `Event::MouseMoved` should be updated to do so. Based on #1614 but updated to the current version, and with better fallback behaviour. * Closes #1611 * Supersedes #1614
Raw mouse movement is unaccelerated and unclamped by screen boundaries, and does not relate to any position on the screen. It is useful in certain situations such as draggable values and 3D cameras, where screen position does not matter. https://github.com/emilk/egui/assets/1700581/1400e6a6-0573-41b9-99a1-a9cd305aa1a3 Added `Event::MouseMoved` for integrations to supply raw mouse movement. Added `Response:drag_motion` to get the raw mouse movement, but will fall back to delta in case the integration does not supply it. Nothing should be breaking, but third-party integrations that can send `Event::MouseMoved` should be updated to do so. Based on emilk#1614 but updated to the current version, and with better fallback behaviour. * Closes emilk#1611 * Supersedes emilk#1614
This can enhance usability of DragValue much. #1611
2022-05-10.19-27-13.mp4