How to make sure `onPointerEvent(PointerEventType....
# compose-desktop
n
How to make sure
onPointerEvent(PointerEventType._*Press*_)
and
onPointerEvent(PointerEventType._*Release*_)
are triggered in different elements? I am trying to draw arrows from one place (ImageView) to another (also ImageView), but as you can see in the logs: the same initial element release is registered, instead of another.
a
This is by design.
You’ll need to arrange for the source and target to communicate and pass events to each other. You can get the coordinates relative to the window with something like
Copy code
Modifier.onGloballyPositioned {
    val size = it.size
    val offsetInWindow = it.localToWindow(Offset.Zero)
}
n
Yeah I assume that's the one way, thanks!
a
Looking at your screenshot, I suggest putting the pointer listeners on the parent of the objects (the one drawing the grid).
n
Yes, I will just loop through all targets in my canvas and calculate the difference between the current pointer offset to target arrow Rect. The closest one will be triggered to accept the arrow