Introduce subscription::Event

... and remove `PlatformSpecific` from `Event`
This commit is contained in:
Héctor Ramón Jiménez 2024-06-11 19:41:05 +02:00
parent 83296a73eb
commit 5d7dcf417c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
13 changed files with 156 additions and 129 deletions

View file

@ -1,5 +1,6 @@
//! Listen to keyboard events.
use crate::core;
use crate::core::event;
use crate::core::keyboard::{Event, Key, Modifiers};
use crate::subscription::{self, Subscription};
use crate::MaybeSend;
@ -18,16 +19,14 @@ where
#[derive(Hash)]
struct OnKeyPress;
subscription::filter_map((OnKeyPress, f), move |event, status, _window| {
match (event, status) {
(
core::Event::Keyboard(Event::KeyPressed {
key, modifiers, ..
}),
core::event::Status::Ignored,
) => f(key, modifiers),
_ => None,
}
subscription::filter_map((OnKeyPress, f), move |event| match event {
subscription::Event::Interaction {
event:
core::Event::Keyboard(Event::KeyPressed { key, modifiers, .. }),
status: event::Status::Ignored,
..
} => f(key, modifiers),
_ => None,
})
}
@ -45,18 +44,13 @@ where
#[derive(Hash)]
struct OnKeyRelease;
subscription::filter_map(
(OnKeyRelease, f),
move |event, status, _window| match (event, status) {
(
core::Event::Keyboard(Event::KeyReleased {
key,
modifiers,
..
}),
core::event::Status::Ignored,
) => f(key, modifiers),
_ => None,
},
)
subscription::filter_map((OnKeyRelease, f), move |event| match event {
subscription::Event::Interaction {
event:
core::Event::Keyboard(Event::KeyReleased { key, modifiers, .. }),
status: event::Status::Ignored,
..
} => f(key, modifiers),
_ => None,
})
}