Web: increase cursor position accuracy (#3380)

This commit is contained in:
daxpedda 2024-01-10 13:38:32 +01:00 committed by GitHub
parent 816798bfd1
commit 4fe38d8067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -28,6 +28,7 @@ Unreleased` header.
- **Breaking:** Rename `VideoMode` to `VideoModeHandle` to represent that it doesn't hold static data.
- **Breaking:** No longer export `platform::x11::XNotSupported`.
- **Breaking:** Renamed `platform::x11::XWindowType` to `platform::x11::WindowType`.
- On Web, increase cursor position accuracy.
# 0.29.9

View file

@ -81,9 +81,22 @@ impl MouseButton {
}
pub fn mouse_position(event: &MouseEvent) -> LogicalPosition<f64> {
#[wasm_bindgen]
extern "C" {
type MouseEventExt;
#[wasm_bindgen(method, getter, js_name = offsetX)]
fn offset_x(this: &MouseEventExt) -> f64;
#[wasm_bindgen(method, getter, js_name = offsetY)]
fn offset_y(this: &MouseEventExt) -> f64;
}
let event: &MouseEventExt = event.unchecked_ref();
LogicalPosition {
x: event.offset_x() as f64,
y: event.offset_y() as f64,
x: event.offset_x(),
y: event.offset_y(),
}
}