Skip to content

Commit

Permalink
Implement touch events via winit
Browse files Browse the repository at this point in the history
Tested on iOS
  • Loading branch information
marysaka committed Jun 26, 2022
1 parent bede2a0 commit 2bc71ed
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tao::{
#[cfg(feature = "winit")]
use winit::{
dpi::PhysicalSize,
event::{ElementState, Event as WEvent, MouseButton as WMouseButton, WindowEvent, VirtualKeyCode},
event::{ElementState, Event as WEvent, MouseButton as WMouseButton, Touch, TouchPhase, WindowEvent, VirtualKeyCode},
event_loop::{ControlFlow, EventLoop, EventLoopProxy},
window::{Window, WindowBuilder},
};
Expand Down Expand Up @@ -416,6 +416,31 @@ pub fn rui(view: impl View) {
_ => {}
};
}
WEvent::WindowEvent {
window_id,
event: WindowEvent::Touch(Touch { phase, location, .. }),
} => {
// Do not handle events from other windows.
if window_id != window.id() {
return;
}

let scale = window.scale_factor() as f32;
let position = [
location.x as f32 / scale,
(config.height as f32 - location.y as f32) / scale,
]
.into();

// TODO: Multi-Touch management
let event = match phase {
TouchPhase::Started => Event::TouchBegin { id: 0, position },
TouchPhase::Moved => Event::TouchMove { id: 0, position },
TouchPhase::Ended | TouchPhase::Cancelled => Event::TouchEnd { id: 0, position }
};

cx.process(&view, &event, &mut vger);
}
WEvent::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
..
Expand Down

0 comments on commit 2bc71ed

Please sign in to comment.