Skip to content

Commit

Permalink
Web: increase cursor position accuracy (#3380)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored and kchibisov committed Jan 15, 2024
1 parent 87f44ec commit 978ec7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased` header.
# Unreleased

- On Web, account for canvas being focused already before event loop starts.
- On Web, increase cursor position accuracy.

# 0.29.9

Expand Down
17 changes: 15 additions & 2 deletions src/platform_impl/web/web_sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down

0 comments on commit 978ec7d

Please sign in to comment.