wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Incorrect value return type for input device coordinates

Open dnlsndr opened this issue 4 years ago • 9 comments

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

  1. Clone this repo: https://github.com/onmyflow/wasm_bindgend_event_coordinates_issue
  2. npm intall & npm start
  3. open the website on a device with a input device like a pen
  4. open the developer console
  5. click somewhere on the blank page and look at the output
  6. 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: image

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.

dnlsndr avatar Aug 13 '20 12:08 dnlsndr