mwcraig / ipyevents

A custom widget for returning mouse and keyboard events to Python. Documentation:
https://ipyevents.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
112 stars 27 forks source link

Consider returning normalized coordinates #14

Open mwcraig opened 6 years ago

mwcraig commented 6 years ago

Would need to decide whether these are normalized in the current view of the widget or normalized in the "natural" coordinates of the widget, if any.

pbugnion commented 6 years ago

Do you mean generalizing what you currently do for image widgets? ie, for each click, we would get the dimensions of the widget and return where the click was as a fraction of the total size?

mwcraig commented 6 years ago

I hadn't thought about it that way, but yes. I think the only question really is whether the size of the widget includes the border and padding (if any) or not. For images, those are excluded because they aren't part of the image....so I suppose for consistency's sake they should also be excluded for others too.

The original suggestion was made at the end here:

Also, I'd think normalize versions (between 0 and 1) would be useful.

@maartenbreddels -- were you thinking normalized versions of all of the coordinates returned?

mwcraig commented 6 years ago

For reference, the coordinates currently returned are:

Location of the mouse event

These attributes are standard properties of HTML mouse events.

Additional location for some types of widgets

For widgets (like Label) for which there is no underlying array object these properties are not returned.

maartenbreddels commented 6 years ago

Normalized would be nice, since there may be a scale associated to the image that does not correspond to pixels. And you never know the try image size in the browser right?

mwcraig commented 6 years ago

Normalized would be nice

Just to be clear, you mean one normalized coordinate pair, or do you mean normalized versions of each of the x,y coordinates listed above? (screen, client, page, etc).

My leaning would be to provide normalized coordinates only for things like an image that have an intrinsic size).

mwcraig commented 6 years ago

And you never know the try image size in the browser right?

The only in-browser image size I really trust is the naturalWidth/naturalHeight. My understanding is that the <img width/height> properties are completely meaningless...