Turn Touch into a struct and add finger id
This commit is contained in:
parent
e19a07d400
commit
d3572e1b81
13 changed files with 151 additions and 112 deletions
|
|
@ -5,9 +5,9 @@
|
|||
use crate::{
|
||||
input::{
|
||||
keyboard::{self, KeyCode, ModifiersState},
|
||||
mouse, touch, ButtonState,
|
||||
mouse, touch, ButtonState, Touch,
|
||||
},
|
||||
window, Event, Mode, MouseCursor,
|
||||
window, Event, Mode, MouseCursor, Point,
|
||||
};
|
||||
|
||||
/// Converts a winit window event into an iced event.
|
||||
|
|
@ -31,8 +31,7 @@ pub fn window_event(
|
|||
let position = position.to_logical::<f64>(scale_factor);
|
||||
|
||||
Some(Event::Mouse(mouse::Event::CursorMoved {
|
||||
x: position.x as f32,
|
||||
y: position.y as f32,
|
||||
position: Point::new(position.x as f32, position.y as f32),
|
||||
}))
|
||||
}
|
||||
WindowEvent::MouseInput { button, state, .. } => {
|
||||
|
|
@ -84,9 +83,7 @@ pub fn window_event(
|
|||
WindowEvent::HoveredFileCancelled => {
|
||||
Some(Event::Window(window::Event::FilesHoveredLeft))
|
||||
}
|
||||
WindowEvent::Touch(touch) => {
|
||||
Some(Event::Touch(touch_event(touch)))
|
||||
}
|
||||
WindowEvent::Touch(touch) => Some(Event::Touch(touch_event(touch))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -162,6 +159,25 @@ pub fn modifiers_state(
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event.
|
||||
///
|
||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
|
||||
pub fn touch_event(touch: winit::event::Touch) -> Touch {
|
||||
let phase = match touch.phase {
|
||||
winit::event::TouchPhase::Started => touch::Phase::Started,
|
||||
winit::event::TouchPhase::Moved => touch::Phase::Moved,
|
||||
winit::event::TouchPhase::Ended => touch::Phase::Ended,
|
||||
winit::event::TouchPhase::Cancelled => touch::Phase::Canceled,
|
||||
};
|
||||
|
||||
Touch {
|
||||
finger: touch::Finger(touch.id),
|
||||
position: Point::new(touch.location.x as f32, touch.location.y as f32),
|
||||
phase,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
|
||||
///
|
||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||
|
|
@ -345,24 +361,3 @@ pub(crate) fn is_private_use_character(c: char) -> bool {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
pub(crate) fn touch_event(touch: winit::event::Touch) -> touch::Touch {
|
||||
let location = touch.location;
|
||||
match touch.phase {
|
||||
winit::event::TouchPhase::Started => touch::Touch::Started {
|
||||
x: location.x as f32,
|
||||
y: location.y as f32,
|
||||
},
|
||||
winit::event::TouchPhase::Ended => touch::Touch::Ended {
|
||||
x: location.x as f32,
|
||||
y: location.y as f32,
|
||||
},
|
||||
winit::event::TouchPhase::Moved => touch::Touch::Moved {
|
||||
x: location.x as f32,
|
||||
y: location.y as f32,
|
||||
},
|
||||
winit::event::TouchPhase::Cancelled => touch::Touch::Cancelled {
|
||||
x: location.x as f32,
|
||||
y: location.y as f32,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue