mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-31 13:50:05 -04:00
Web: increase cursor position accuracy (#3380)
This commit is contained in:
committed by
Kirill Chibisov
parent
87f44ecffb
commit
978ec7dfec
@@ -12,6 +12,7 @@ Unreleased` header.
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- On Web, account for canvas being focused already before event loop starts.
|
- On Web, account for canvas being focused already before event loop starts.
|
||||||
|
- On Web, increase cursor position accuracy.
|
||||||
|
|
||||||
# 0.29.9
|
# 0.29.9
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,22 @@ impl MouseButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn mouse_position(event: &MouseEvent) -> LogicalPosition<f64> {
|
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 {
|
LogicalPosition {
|
||||||
x: event.offset_x() as f64,
|
x: event.offset_x(),
|
||||||
y: event.offset_y() as f64,
|
y: event.offset_y(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user