api: remove ::dummy from Id types
`::dummy` was used for testing purposes and became redundant after adding e.g. `from_raw` and `into_raw` methods on `Id` types.
This commit is contained in:
parent
6e1b9fa24d
commit
32cd1ad9a7
35 changed files with 219 additions and 352 deletions
|
|
@ -1,13 +1,16 @@
|
|||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(i32);
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(u32);
|
||||
|
||||
impl DeviceId {
|
||||
pub fn new(pointer_id: i32) -> Self {
|
||||
Self(pointer_id)
|
||||
}
|
||||
|
||||
pub const fn dummy() -> Self {
|
||||
Self(-1)
|
||||
pub fn new(pointer_id: i32) -> Option<Self> {
|
||||
if let Ok(pointer_id) = u32::try_from(pointer_id) {
|
||||
Some(Self(pointer_id))
|
||||
} else if pointer_id == -1 {
|
||||
None
|
||||
} else {
|
||||
tracing::error!("found unexpected negative `PointerEvent.pointerId`: {pointer_id}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +25,7 @@ impl FingerId {
|
|||
Self { pointer_id, primary }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub const fn dummy() -> Self {
|
||||
Self { pointer_id: -1, primary: false }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::{backend, event, window, HasMonitorPermissionFuture, MonitorPermissionFuture};
|
||||
use super::{backend, window, HasMonitorPermissionFuture, MonitorPermissionFuture};
|
||||
use crate::application::ApplicationHandler;
|
||||
use crate::error::{EventLoopError, NotSupportedError};
|
||||
use crate::event::Event;
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ impl Shared {
|
|||
}
|
||||
|
||||
// chorded button event
|
||||
let device_id = RootDeviceId(DeviceId::new(event.pointer_id()));
|
||||
let device_id = DeviceId::new(event.pointer_id()).map(RootDeviceId);
|
||||
|
||||
if let Some(button) = backend::event::mouse_button(&event) {
|
||||
let state = if backend::event::mouse_buttons(&event).contains(button.into()) {
|
||||
|
|
@ -327,7 +327,7 @@ impl Shared {
|
|||
|
||||
if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) {
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId::dummy()),
|
||||
device_id: None,
|
||||
event: DeviceEvent::MouseWheel { delta },
|
||||
});
|
||||
}
|
||||
|
|
@ -344,7 +344,7 @@ impl Shared {
|
|||
|
||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId::new(event.pointer_id())),
|
||||
device_id: DeviceId::new(event.pointer_id()).map(RootDeviceId),
|
||||
event: DeviceEvent::Button {
|
||||
button: button.to_id(),
|
||||
state: ElementState::Pressed,
|
||||
|
|
@ -363,7 +363,7 @@ impl Shared {
|
|||
|
||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId::new(event.pointer_id())),
|
||||
device_id: DeviceId::new(event.pointer_id()).map(RootDeviceId),
|
||||
event: DeviceEvent::Button {
|
||||
button: button.to_id(),
|
||||
state: ElementState::Released,
|
||||
|
|
@ -381,7 +381,7 @@ impl Shared {
|
|||
}
|
||||
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId::dummy()),
|
||||
device_id: None,
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
physical_key: backend::event::key_code(&event),
|
||||
state: ElementState::Pressed,
|
||||
|
|
@ -399,7 +399,7 @@ impl Shared {
|
|||
}
|
||||
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId::dummy()),
|
||||
device_id: None,
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
physical_key: backend::event::key_code(&event),
|
||||
state: ElementState::Released,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use web_sys::Element;
|
|||
|
||||
use super::super::monitor::MonitorPermissionFuture;
|
||||
use super::super::{lock, KeyEventExtra};
|
||||
use super::event::DeviceId;
|
||||
use super::runner::{EventWrapper, WeakShared};
|
||||
use super::window::WindowId;
|
||||
use super::{backend, runner, EventLoopProxy};
|
||||
|
|
@ -144,13 +143,11 @@ impl ActiveEventLoop {
|
|||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(DeviceId::dummy());
|
||||
|
||||
runner.send_events(
|
||||
iter::once(Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::KeyboardInput {
|
||||
device_id,
|
||||
device_id: None,
|
||||
event: KeyEvent {
|
||||
physical_key,
|
||||
logical_key,
|
||||
|
|
@ -180,13 +177,11 @@ impl ActiveEventLoop {
|
|||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(DeviceId::dummy());
|
||||
|
||||
runner.send_events(
|
||||
iter::once(Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::KeyboardInput {
|
||||
device_id,
|
||||
device_id: None,
|
||||
event: KeyEvent {
|
||||
physical_key,
|
||||
logical_key,
|
||||
|
|
@ -221,7 +216,7 @@ impl ActiveEventLoop {
|
|||
|
||||
let pointer = pointer_id.map(|device_id| Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::CursorLeft { device_id: RootDeviceId(device_id) },
|
||||
event: WindowEvent::CursorLeft { device_id: device_id.map(RootDeviceId) },
|
||||
});
|
||||
|
||||
if focus.is_some() || pointer.is_some() {
|
||||
|
|
@ -246,7 +241,7 @@ impl ActiveEventLoop {
|
|||
|
||||
let pointer = pointer_id.map(|device_id| Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::CursorEntered { device_id: RootDeviceId(device_id) },
|
||||
event: WindowEvent::CursorEntered { device_id: device_id.map(RootDeviceId) },
|
||||
});
|
||||
|
||||
if focus.is_some() || pointer.is_some() {
|
||||
|
|
@ -272,7 +267,7 @@ impl ActiveEventLoop {
|
|||
});
|
||||
|
||||
runner.send_events(modifiers.into_iter().chain(events.flat_map(|position| {
|
||||
let device_id = RootDeviceId(pointer_id);
|
||||
let device_id = pointer_id.map(RootDeviceId);
|
||||
|
||||
iter::once(Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
|
|
@ -301,7 +296,7 @@ impl ActiveEventLoop {
|
|||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Touch(Touch {
|
||||
finger_id: RootFingerId(finger_id),
|
||||
device_id: RootDeviceId(device_id),
|
||||
device_id: device_id.map(RootDeviceId),
|
||||
phase: TouchPhase::Moved,
|
||||
force: Some(force),
|
||||
location,
|
||||
|
|
@ -329,7 +324,7 @@ impl ActiveEventLoop {
|
|||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(device_id);
|
||||
let device_id = device_id.map(RootDeviceId);
|
||||
|
||||
let state = if buttons.contains(button.into()) {
|
||||
ElementState::Pressed
|
||||
|
|
@ -368,7 +363,7 @@ impl ActiveEventLoop {
|
|||
}
|
||||
});
|
||||
|
||||
let device_id: RootDeviceId = RootDeviceId(pointer_id);
|
||||
let device_id = pointer_id.map(RootDeviceId);
|
||||
|
||||
// A mouse down event may come in without any prior CursorMoved events,
|
||||
// therefore we should send a CursorMoved event to make sure that the
|
||||
|
|
@ -407,7 +402,7 @@ impl ActiveEventLoop {
|
|||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Touch(Touch {
|
||||
finger_id: RootFingerId(finger_id),
|
||||
device_id: RootDeviceId(device_id),
|
||||
device_id: device_id.map(RootDeviceId),
|
||||
phase: TouchPhase::Started,
|
||||
force: Some(force),
|
||||
location,
|
||||
|
|
@ -434,7 +429,7 @@ impl ActiveEventLoop {
|
|||
}
|
||||
});
|
||||
|
||||
let device_id: RootDeviceId = RootDeviceId(pointer_id);
|
||||
let device_id = pointer_id.map(RootDeviceId);
|
||||
|
||||
// A mouse up event may come in without any prior CursorMoved events,
|
||||
// therefore we should send a CursorMoved event to make sure that the
|
||||
|
|
@ -475,7 +470,7 @@ impl ActiveEventLoop {
|
|||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Touch(Touch {
|
||||
finger_id: RootFingerId(finger_id),
|
||||
device_id: RootDeviceId(device_id),
|
||||
device_id: device_id.map(RootDeviceId),
|
||||
phase: TouchPhase::Ended,
|
||||
force: Some(force),
|
||||
location,
|
||||
|
|
@ -502,7 +497,7 @@ impl ActiveEventLoop {
|
|||
Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::MouseWheel {
|
||||
device_id: RootDeviceId(DeviceId::dummy()),
|
||||
device_id: None,
|
||||
delta,
|
||||
phase: TouchPhase::Moved,
|
||||
},
|
||||
|
|
@ -516,7 +511,7 @@ impl ActiveEventLoop {
|
|||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Touch(Touch {
|
||||
finger_id: RootFingerId(finger_id),
|
||||
device_id: RootDeviceId(device_id),
|
||||
device_id: device_id.map(RootDeviceId),
|
||||
phase: TouchPhase::Cancelled,
|
||||
force: Some(force),
|
||||
location,
|
||||
|
|
|
|||
|
|
@ -330,22 +330,23 @@ impl Canvas {
|
|||
|
||||
pub fn on_cursor_leave<F>(&self, handler: F)
|
||||
where
|
||||
F: 'static + FnMut(ModifiersState, Option<DeviceId>),
|
||||
F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_cursor_leave(&self.common, handler)
|
||||
}
|
||||
|
||||
pub fn on_cursor_enter<F>(&self, handler: F)
|
||||
where
|
||||
F: 'static + FnMut(ModifiersState, Option<DeviceId>),
|
||||
F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_cursor_enter(&self.common, handler)
|
||||
}
|
||||
|
||||
pub fn on_mouse_release<M, T>(&self, mouse_handler: M, touch_handler: T)
|
||||
where
|
||||
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_mouse_release(
|
||||
&self.common,
|
||||
|
|
@ -356,8 +357,9 @@ impl Canvas {
|
|||
|
||||
pub fn on_mouse_press<M, T>(&self, mouse_handler: M, touch_handler: T)
|
||||
where
|
||||
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_mouse_press(
|
||||
&self.common,
|
||||
|
|
@ -370,16 +372,22 @@ impl Canvas {
|
|||
pub fn on_cursor_move<M, T, B>(&self, mouse_handler: M, touch_handler: T, button_handler: B)
|
||||
where
|
||||
M: 'static
|
||||
+ FnMut(ModifiersState, DeviceId, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||
T: 'static
|
||||
+ FnMut(
|
||||
ModifiersState,
|
||||
DeviceId,
|
||||
Option<DeviceId>,
|
||||
FingerId,
|
||||
&mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>,
|
||||
),
|
||||
B: 'static
|
||||
+ FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, ButtonsState, MouseButton),
|
||||
+ FnMut(
|
||||
ModifiersState,
|
||||
Option<DeviceId>,
|
||||
PhysicalPosition<f64>,
|
||||
ButtonsState,
|
||||
MouseButton,
|
||||
),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_cursor_move(
|
||||
&self.common,
|
||||
|
|
@ -392,7 +400,7 @@ impl Canvas {
|
|||
|
||||
pub fn on_touch_cancel<F>(&self, handler: F)
|
||||
where
|
||||
F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
F: 'static + FnMut(Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
self.handlers.borrow_mut().pointer_handler.on_touch_cancel(&self.common, handler)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl PointerHandler {
|
|||
|
||||
pub fn on_cursor_leave<F>(&mut self, canvas_common: &Common, mut handler: F)
|
||||
where
|
||||
F: 'static + FnMut(ModifiersState, Option<DeviceId>),
|
||||
F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
|
||||
{
|
||||
self.on_cursor_leave =
|
||||
Some(canvas_common.add_event("pointerout", move |event: PointerEvent| {
|
||||
|
|
@ -54,7 +54,7 @@ impl PointerHandler {
|
|||
|
||||
pub fn on_cursor_enter<F>(&mut self, canvas_common: &Common, mut handler: F)
|
||||
where
|
||||
F: 'static + FnMut(ModifiersState, Option<DeviceId>),
|
||||
F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
|
||||
{
|
||||
self.on_cursor_enter =
|
||||
Some(canvas_common.add_event("pointerover", move |event: PointerEvent| {
|
||||
|
|
@ -76,8 +76,9 @@ impl PointerHandler {
|
|||
mut mouse_handler: M,
|
||||
mut touch_handler: T,
|
||||
) where
|
||||
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
let window = canvas_common.window.clone();
|
||||
self.on_pointer_release =
|
||||
|
|
@ -112,8 +113,9 @@ impl PointerHandler {
|
|||
mut touch_handler: T,
|
||||
prevent_default: Rc<Cell<bool>>,
|
||||
) where
|
||||
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
|
||||
T: 'static
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
let window = canvas_common.window.clone();
|
||||
let canvas = canvas_common.raw().clone();
|
||||
|
|
@ -172,16 +174,22 @@ impl PointerHandler {
|
|||
prevent_default: Rc<Cell<bool>>,
|
||||
) where
|
||||
M: 'static
|
||||
+ FnMut(ModifiersState, DeviceId, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||
+ FnMut(ModifiersState, Option<DeviceId>, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||
T: 'static
|
||||
+ FnMut(
|
||||
ModifiersState,
|
||||
DeviceId,
|
||||
Option<DeviceId>,
|
||||
FingerId,
|
||||
&mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>,
|
||||
),
|
||||
B: 'static
|
||||
+ FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, ButtonsState, MouseButton),
|
||||
+ FnMut(
|
||||
ModifiersState,
|
||||
Option<DeviceId>,
|
||||
PhysicalPosition<f64>,
|
||||
ButtonsState,
|
||||
MouseButton,
|
||||
),
|
||||
{
|
||||
let window = canvas_common.window.clone();
|
||||
let canvas = canvas_common.raw().clone();
|
||||
|
|
@ -237,7 +245,7 @@ impl PointerHandler {
|
|||
|
||||
pub fn on_touch_cancel<F>(&mut self, canvas_common: &Common, mut handler: F)
|
||||
where
|
||||
F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition<f64>, Force),
|
||||
F: 'static + FnMut(Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
|
||||
{
|
||||
let window = canvas_common.window.clone();
|
||||
self.on_touch_cancel =
|
||||
|
|
|
|||
|
|
@ -433,10 +433,6 @@ impl Drop for Inner {
|
|||
pub struct WindowId(pub(crate) u64);
|
||||
|
||||
impl WindowId {
|
||||
pub const fn dummy() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
|
||||
pub const fn into_raw(self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue