Take IntoIterator in send_events()

This commit is contained in:
dAxpeDDa 2023-06-04 12:18:38 +02:00 committed by daxpedda
parent b4b2389d0a
commit 0786d534f4
2 changed files with 53 additions and 65 deletions

View file

@ -192,7 +192,7 @@ impl<T: 'static> Shared<T> {
// Add a series of events to the event loop runner // Add a series of events to the event loop runner
// //
// It will determine if the event should be immediately sent to the user or buffered for later // It will determine if the event should be immediately sent to the user or buffered for later
pub fn send_events(&self, events: impl Iterator<Item = Event<'static, T>>) { pub fn send_events(&self, events: impl IntoIterator<Item = Event<'static, T>>) {
// If the event loop is closed, it should discard any new events // If the event loop is closed, it should discard any new events
if self.is_closed() { if self.is_closed() {
return; return;

View file

@ -278,24 +278,21 @@ impl<T> EventLoopWindowTarget<T> {
let runner = self.runner.clone(); let runner = self.runner.clone();
move |pointer_id, position, delta| { move |pointer_id, position, delta| {
runner.send_events( runner.send_events([
[ Event::WindowEvent {
Event::WindowEvent { window_id: RootWindowId(id),
window_id: RootWindowId(id), event: WindowEvent::CursorMoved {
event: WindowEvent::CursorMoved {
device_id: RootDeviceId(DeviceId(pointer_id)),
position,
},
},
Event::DeviceEvent {
device_id: RootDeviceId(DeviceId(pointer_id)), device_id: RootDeviceId(DeviceId(pointer_id)),
event: DeviceEvent::MouseMotion { position,
delta: (delta.x, delta.y),
},
}, },
] },
.into_iter(), Event::DeviceEvent {
); device_id: RootDeviceId(DeviceId(pointer_id)),
event: DeviceEvent::MouseMotion {
delta: (delta.x, delta.y),
},
},
]);
} }
}, },
{ {
@ -341,19 +338,16 @@ impl<T> EventLoopWindowTarget<T> {
// A chorded button event may come in without any prior CursorMoved events, // A chorded button event may come in without any prior CursorMoved events,
// therefore we should send a CursorMoved event to make sure that the // therefore we should send a CursorMoved event to make sure that the
// user code has the correct cursor position. // user code has the correct cursor position.
runner.send_events( runner.send_events([
[ Event::WindowEvent {
Event::WindowEvent { window_id: RootWindowId(id),
window_id: RootWindowId(id), event: WindowEvent::CursorMoved {
event: WindowEvent::CursorMoved { device_id: RootDeviceId(DeviceId(pointer_id)),
device_id: RootDeviceId(DeviceId(pointer_id)), position,
position,
},
}, },
button_event, },
] button_event,
.into_iter(), ]);
);
} }
}, },
prevent_default, prevent_default,
@ -381,26 +375,23 @@ impl<T> EventLoopWindowTarget<T> {
// A mouse down event may come in without any prior CursorMoved events, // A mouse down event may come in without any prior CursorMoved events,
// therefore we should send a CursorMoved event to make sure that the // therefore we should send a CursorMoved event to make sure that the
// user code has the correct cursor position. // user code has the correct cursor position.
runner.send_events( runner.send_events([
[ Event::WindowEvent {
Event::WindowEvent { window_id: RootWindowId(id),
window_id: RootWindowId(id), event: WindowEvent::CursorMoved {
event: WindowEvent::CursorMoved { device_id: RootDeviceId(DeviceId(pointer_id)),
device_id: RootDeviceId(DeviceId(pointer_id)), position,
position,
},
}, },
Event::WindowEvent { },
window_id: RootWindowId(id), Event::WindowEvent {
event: WindowEvent::MouseInput { window_id: RootWindowId(id),
device_id: RootDeviceId(DeviceId(pointer_id)), event: WindowEvent::MouseInput {
state: ElementState::Pressed, device_id: RootDeviceId(DeviceId(pointer_id)),
button, state: ElementState::Pressed,
}, button,
}, },
] },
.into_iter(), ]);
);
} }
}, },
{ {
@ -445,26 +436,23 @@ impl<T> EventLoopWindowTarget<T> {
// A mouse up event may come in without any prior CursorMoved events, // A mouse up event may come in without any prior CursorMoved events,
// therefore we should send a CursorMoved event to make sure that the // therefore we should send a CursorMoved event to make sure that the
// user code has the correct cursor position. // user code has the correct cursor position.
runner.send_events( runner.send_events([
[ Event::WindowEvent {
Event::WindowEvent { window_id: RootWindowId(id),
window_id: RootWindowId(id), event: WindowEvent::CursorMoved {
event: WindowEvent::CursorMoved { device_id: RootDeviceId(DeviceId(pointer_id)),
device_id: RootDeviceId(DeviceId(pointer_id)), position,
position,
},
}, },
Event::WindowEvent { },
window_id: RootWindowId(id), Event::WindowEvent {
event: WindowEvent::MouseInput { window_id: RootWindowId(id),
device_id: RootDeviceId(DeviceId(pointer_id)), event: WindowEvent::MouseInput {
state: ElementState::Released, device_id: RootDeviceId(DeviceId(pointer_id)),
button, state: ElementState::Released,
}, button,
}, },
] },
.into_iter(), ]);
);
} }
}, },
{ {