Marcin Wisniowski
02/22/2025, 5:28 PMModifier.onClick
, you don't get the position, and when using Modifier.onPointerEvent(PointerEventType.Release)
you do get a position, but that won't detect clicks correctly, as it will also fire for drags.Winson Chiu
02/22/2025, 5:34 PMdetectTapGestures
? You can manually wait for release if that's critical.Skaldebane
02/22/2025, 5:40 PMclickable
and detectTapGestures
(which is the correct behavior), and detectTapGestures
will give you the offset when the cursor was released, not when it was first pressed.Marcin Wisniowski
02/22/2025, 5:45 PMdetectTapGestures
works but now I can only detect left clicks. I am interested in both left clicks and right clicks (and need to know which is which). In onPointerEvent
I could check the button.Skaldebane
02/22/2025, 7:48 PMModifier.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
if (event.type == PointerEventType.Release) {
val position = event.changes.lastOrNull()?.position
if (position != null && position in size.toIntRect().toRect()) {
val button = event.button
println("released at position $position using button $button!")
}
}
}
}
}
TL;DR: check event type, if it's Release
, make sure that we're inside the bounds of the clickable (unsure if there's a better way, but I just check if the position is inside the size
converted into a Rect
).Skaldebane
02/22/2025, 7:49 PMMarcin Wisniowski
02/22/2025, 7:55 PMSkaldebane
02/22/2025, 7:56 PMWinson Chiu
02/22/2025, 7:57 PMdetectTapGestures
but have it intercept right click instead.