isl-org / isl-org/Open3D

ImageWidget mouse events do not work inside ScrollableVert after scrolling

Open
#5,995 0 comments 0 reactions 1 assignee Claimed by @errissa View on GitHub
bug
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### Describe the issue

It seems that the `ImageWidget` mouse events do not work when they are inside a `ScrollableVert` and after the user has scrolled the content. The mouse events triggered are not those of the widget that is currently in that location, but those of the widget that would be displayed there without scrolling.

I quickly wrote a test script to show the problem by adding several ImageWidget with a mouse-down event to a ScrollableVert. When clicking on one of these images, the correct number is output to the console. However, after scrolling, the indices no longer match the clicked image. Picture 8 and 9, which are not visible without scrolling, can never be clicked.

Since the implementation is similar to how the events are implemented in the `SceneWidget`, I would guess that the same problem can occur there as well.

### Steps to reproduce the bug

```python
# pip install opencv-python numpy open3d

from functools import partial

import cv2
import numpy as np
from open3d.cpu.pybind.geometry import Image
from open3d.cpu.pybind.visualization import gui

app = gui.Application.instance
app.initialize()

window: gui.Window = gui.Application.instance.create_window("Demo Window", 200, 400)
vert = gui.ScrollableVert()

for i in range(10):
image_widget = gui.ImageWidget()
image = np.zeros((100, 400, 3), dtype=np.uint8)

cv2.line(image, (0, 100 - 1), (400 - 1, 100 - 1), (255, 255, 255), 2)

cv2.putText(
img=image,
text=f"Image {i}",
org=(0, 50),
fontFace=cv2.FONT_HERSHEY_DUPLEX,
fontScale=2.0,
color=(255, 255, 255),
thickness=3
)

def mouse_event(id: int, e: gui.MouseEvent) -> gui.Widget.EventCallbackResult:
if e.type == gui.MouseEvent.BUTTON_DOWN:
print(f"clicked on {id}")
return gui.Widget.EventCallbackResult.IGNORED

image_widget.update_image(Image(image))
image_widget.set_on_mouse(partial(mouse_event, i))
vert.add_child(image_widget)

window.add_child(vert)

app.run()
```

### Error message

There is no error message.

### Expected behavior

It is possible to scroll an `ImageWidget` and still be able to fire mouse events.

### Open3D, Python and System information

```markdown
- Operating system: macOS 12.6
- Python version: Python 3.9
- Open3D version: 0.17.0
- System architecture: apple-silicon
- Is this a remote workstation?: no
- How did you install Open3D?: pip
```

### Additional information

ImageWidget events implementation: https://github.com/isl-org/Open3D/pull/4939

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.