ipyvtklink icon indicating copy to clipboard operation
ipyvtklink copied to clipboard

How to get the correct event position when object_fit='contain'?

Open GuillaumeFavelier opened this issue 3 years ago • 0 comments

In mne-python, we rely on ipywidgets and ipyvtklink to design apps for MEG and EEG processing and visualization.

AFAIK, ipyvtklink uses ipyevents to get the mouse event locations. Then it does a little bit of offset computation to adjust the given coordinates from the canvas size (which depends on the notebook) to the render window size (which is fixed by the Renderer at init), correct?

Well, in our last application, we embed the ViewInteractiveWidget in a HBox for a new design:

https://user-images.githubusercontent.com/18143289/152566076-9115d8d3-ba8f-44b5-b2c6-e1151c5b25c8.mp4

What happens when all the group boxes are folded, the values given by ipyevents for boundingRectHeight and boundingRectTop used for offset calculation are correct because the image and its bounding box have the same size.

But we use viewer.layout.object_fit='contain' to preserve the aspect ratio and when the group boxes are unfolded, the bounding box of the image is stretched with the accordion and now, I think the sizes sent by ipyevents do not match anymore.

This is a problem for us because we need the correct position of the event for picking:

https://user-images.githubusercontent.com/18143289/153018183-dc8a8950-4eb0-4489-8022-e65b6e0813d1.mp4

Is there a way to update the offset calculation so that GetEventPosition() returns the correct value when object_fit='contain'?

GuillaumeFavelier avatar Feb 08 '22 15:02 GuillaumeFavelier