Is there a way to mask pointer input with a shape?...
# compose
t
Is there a way to mask pointer input with a shape? For example, what if I wanted to make a custom shape (Star) and have the onClick or other pointer inputs consumed by the Star, but outside of the Star boundaries, the events passed through to any nodes below?
r
Not out of the box. It’s not a trivial problem
An easy solution is to render the shape you want into a bitmap and test the pointer coordinates against the corresponding pixel in the bitmap and see if it’s transparent
If it’s for android I could build an API in my pathway library to do this
(Without going through a bitmap that is)
t
My use case is indeed for Android
r
Then use a bitmap for now :/
c
Would clipping with the star shape on a clickable not work?
r
Clipping doesn't affect input events does it?
Besides we don't expose APIs to do hit testing on shapes
t
Just read through https://developer.android.com/jetpack/compose/touch-input/handling-interactions and https://developer.android.com/jetpack/compose/touch-input/gestures (albeit probably a little faster than I should have). I was looking for the basic place where you can decide if you want to handle an event or not, like I'm familiar with in other view systems, but didn't see it yet...
An even simpler example than the star would be "what if I wanted to make a BIG round button". Big enough that touch events and ripple effects outside of the circle would look weird to the user.
m
@Travis Griggs Is it intentional that the two links above are identical?
I like to do any non-trivial hit-testing on the model side via the https://github.com/locationtech/jts library. This has the advantage that I can stay independent of the GUI technology (AWT, JavaFX, Compose, …)
t
Fixed @Michael Paus, thx