Make recorder widget produce Interaction

This commit is contained in:
Héctor Ramón Jiménez 2025-08-20 15:31:12 +02:00
parent 2532099efc
commit 8ca25d627f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 45 additions and 53 deletions

View file

@ -33,18 +33,20 @@ pub enum Interaction {
}
impl Interaction {
pub fn from_event(event: Event) -> Option<Self> {
pub fn from_event(event: &Event) -> Option<Self> {
Some(match event {
Event::Mouse(mouse) => Self::Mouse(match mouse {
mouse::Event::CursorMoved { position } => {
Mouse::Move(Target::Point(position))
}
mouse::Event::ButtonPressed(button) => {
Mouse::Press { button, at: None }
}
mouse::Event::ButtonReleased(button) => {
Mouse::Release { button, at: None }
Mouse::Move(Target::Point(*position))
}
mouse::Event::ButtonPressed(button) => Mouse::Press {
button: *button,
at: None,
},
mouse::Event::ButtonReleased(button) => Mouse::Release {
button: *button,
at: None,
},
_ => None?,
}),
Event::Keyboard(keyboard) => Self::Keyboard(match keyboard {
@ -61,7 +63,7 @@ impl Interaction {
keyboard::Key::Named(keyboard::key::Named::Backspace) => {
Keyboard::Press(Key::Backspace)
}
_ => Keyboard::Typewrite(text?.to_string()),
_ => Keyboard::Typewrite(text.as_ref()?.to_string()),
},
keyboard::Event::KeyReleased { key, .. } => match key {
keyboard::Key::Named(keyboard::key::Named::Enter) => {