Added initial touch events to support iOS

This commit is contained in:
Sebastian Imlay 2019-11-11 20:29:58 -08:00
parent 9da6ce474c
commit e19a07d400
13 changed files with 165 additions and 47 deletions

View file

@ -310,7 +310,6 @@ pub trait Application: Sized {
physical_size.width,
physical_size.height,
);
resized = false;
}

View file

@ -5,7 +5,7 @@
use crate::{
input::{
keyboard::{self, KeyCode, ModifiersState},
mouse, ButtonState,
mouse, touch, ButtonState,
},
window, Event, Mode, MouseCursor,
};
@ -84,6 +84,9 @@ pub fn window_event(
WindowEvent::HoveredFileCancelled => {
Some(Event::Window(window::Event::FilesHoveredLeft))
}
WindowEvent::Touch(touch) => {
Some(Event::Touch(touch_event(touch)))
}
_ => None,
}
}
@ -342,3 +345,24 @@ 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,
},
}
}