Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

enomado
Copy link
Contributor

@enomado enomado commented May 10, 2022

This can enhance usability of DragValue much. #1611

2022-05-10.19-27-13.mp4

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

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?

egui-winit/src/lib.rs Outdated Show resolved Hide resolved
egui/src/data/input.rs Show resolved Hide resolved
@enomado
Copy link
Contributor Author

enomado commented May 11, 2022

Also: should this be implemented for eframe web?

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

@enomado
Copy link
Contributor Author

enomado commented May 11, 2022

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.

@enomado enomado requested a review from emilk May 11, 2022 16:43
Copy link
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.

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.

Comment on lines 180 to 183
/// 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),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// 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),

Copy link
Owner

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.

egui/src/input_state.rs Outdated Show resolved Hide resolved
@enomado
Copy link
Contributor Author

enomado commented May 11, 2022

perhaps add a separate motion: Vec2 for these unspecified units
Great idea. I'll do it. And change DragValue to use them.

@enomado
Copy link
Contributor Author

enomado commented May 20, 2022

Squashed and rebased

Comment on lines 180 to 183
/// 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),
Copy link
Owner

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.

egui/src/response.rs Outdated Show resolved Hide resolved
@enomado enomado requested a review from emilk May 21, 2022 15:02
@enomado
Copy link
Contributor Author

enomado commented May 22, 2022

Sorry. Is any changes still needed? I was trying to document my best, but there is long story behind this stuff

res
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

It's not eguis 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.

Comment on lines +293 to +294
// in a case of touchscreen or whatever
self.ctx.input().pointer.delta()
Copy link
Owner

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.

@emilk emilk marked this pull request as draft January 7, 2024 15:56
emilk pushed a commit that referenced this pull request Feb 20, 2024
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
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
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
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.

2 participants