--- original +++ modified @@ -59,6 +59,17 @@ pub id: InputEventId, } +impl InputEventAndId { + /// Scale the event's point coordinates by the given factor (divides by scale). + /// Used for converting coordinates to account for page zoom in embedded webviews. + pub fn scale_point_by(self, scale: f32) -> Self { + Self { + event: self.event.scale_point_by(scale), + id: self.id, + } + } +} + impl From for InputEventAndId { fn from(event: InputEvent) -> Self { Self { @@ -92,6 +103,31 @@ InputEvent::Scroll(..) => None, } } + + /// Scale the point coordinates by the given factor (divides by scale). + /// Used for converting coordinates to account for page zoom in embedded webviews. + pub fn scale_point_by(self, scale: f32) -> Self { + match self { + InputEvent::MouseButton(mut event) => { + event.point = event.point.scale_by(scale); + InputEvent::MouseButton(event) + }, + InputEvent::MouseMove(mut event) => { + event.point = event.point.scale_by(scale); + InputEvent::MouseMove(event) + }, + InputEvent::Touch(mut event) => { + event.point = event.point.scale_by(scale); + InputEvent::Touch(event) + }, + InputEvent::Wheel(mut event) => { + event.point = event.point.scale_by(scale); + InputEvent::Wheel(event) + }, + // Events without coordinates pass through unchanged + other => other, + } + } } #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -226,7 +262,7 @@ } /// The type of input represented by a multi-touch event. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub enum TouchEventType { /// A new touch point came in contact with the screen. Down,