Web touch event (#2188)
* feat: add pointer events to web * feat: remove PointerType for touch events * Remove duplicate * Changelog and features * Remove PointerType * feat: renamed events, added touch type guard * Rename * Flip the y axis * Fix physical position and add force * Update comment * Update features * Use normalized force * Remove unnecessary todos * Update comment * Refactor add touch_handler * Rephrase by Liamolucko * Update CHANGELOG.md * Fix duplicate mouse and touch events * Removed workaround for scale factor * Flip the y axis * Fix * Fmt * Replace `match` with a single pattern with `if let` * Update documentation * Have one callback per event * Remove a comment * Fix * Remove y-axis flip * Update src/event.rs Co-authored-by: Mads Marquart <mads@marquart.dk> * Fix platform specific comment * Fix extra argument to `touch_position` function Co-authored-by: Dany Sluijk <me@dany.dev> Co-authored-by: Johan Klokkhammer Helsing <johanhelsing@gmail.com> Co-authored-by: oscrim <oscar@widefind.se> Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
402cbd55f9
commit
f43ce2a131
7 changed files with 272 additions and 95 deletions
|
|
@ -2,7 +2,7 @@ use crate::dpi::LogicalPosition;
|
|||
use crate::event::{ModifiersState, MouseButton, MouseScrollDelta, ScanCode, VirtualKeyCode};
|
||||
|
||||
use std::convert::TryInto;
|
||||
use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, WheelEvent};
|
||||
use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, PointerEvent, WheelEvent};
|
||||
|
||||
pub fn mouse_button(event: &MouseEvent) -> MouseButton {
|
||||
match event.button() {
|
||||
|
|
@ -246,3 +246,11 @@ pub fn codepoint(event: &KeyboardEvent) -> char {
|
|||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
|
||||
event.key().chars().next().unwrap()
|
||||
}
|
||||
|
||||
pub fn touch_position(event: &PointerEvent, _canvas: &HtmlCanvasElement) -> LogicalPosition<f64> {
|
||||
// TODO: Should this handle more, like `mouse_position_by_client` does?
|
||||
LogicalPosition {
|
||||
x: event.client_x() as f64,
|
||||
y: event.client_y() as f64,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue