wasm-bindgen
wasm-bindgen copied to clipboard
Incorrect value return type for input device coordinates
Describe the Bug
The Mouse input event defines four functions:
-
client_x()
-
screen_x()
-
x()
-
offset_x()
all of those return i32 values, which is not really correct.
Normal systems that work with a mouse or 'primitive' input device may only work on pixel basis, but newer input devices such as pen inputs, digitizers and such return high precision float values which are apparrently casted into i32 by the mentioned functions. And since other input event types such as PointerEvent
extend the normal MouseEvent
, they also have the same issue. This becomes extremely noticable for applications such as note writers that are maily used on tables with pen inputs.
Steps to Reproduce
- Clone this repo: https://github.com/onmyflow/wasm_bindgend_event_coordinates_issue
- npm intall & npm start
- open the website on a device with a input device like a pen
- open the developer console
- click somewhere on the blank page and look at the output
- notice that the log from JS has decimal numbers while the log from rust has casted the floats into integers
Here a picture for fast reference:
Expected Behavior
All input event device coordinates have to output a f64 value for full precision
Actual Behavior
The before mentioned functions cast input event device coordinates into i32 which is not correct
Additional Context
I'm still not alltoo familiar with the intricacies of wasm-bindgen, so I'm not sure how to fix this issue and create a PR by myself.