https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
n

Nuru Nabiyev

11/20/2023, 9:05 PM
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

Alexander Maryanovsky

11/21/2023, 10:31 AM
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

Nuru Nabiyev

11/21/2023, 10:42 AM
Yeah I assume that's the one way, thanks!
a

Alexander Maryanovsky

11/21/2023, 10:45 AM
Looking at your screenshot, I suggest putting the pointer listeners on the parent of the objects (the one drawing the grid).
n

Nuru Nabiyev

11/21/2023, 10:47 AM
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