https://kotlinlang.org logo
#compose
Title
# compose
a

alexhelder

10/16/2023, 6:36 PM
Hi, I would like to create a custom Layout like a Pizza. Drawing is easy but I am not sure how to handle the tap gestures - when the user taps a slice, how can I know which slice was tapped? I was hoping Compose may have some tools to help before I roll my sleeves up with computational geometry algo.
r

romainguy

10/16/2023, 6:44 PM
It’s a feature I’ve been wanting to add to
Path
👍 2
but right now you’d need to do it yourself
a

alexhelder

10/16/2023, 6:57 PM
Thank you
r

romainguy

10/16/2023, 7:06 PM
FWIW it’s pretty easy in your case
You will need to convert the x/y touch coordinate to an angle, which can be done with
atan2
and from that angle you can find the corresponding slice
Something like this:
Copy code
const val RadToDeg = (180.0 / PI).toFloat()
val angleInRad = atan2(y, x)
val angleInDeg = angleInRad * RadToDeg
angleRad
will be in the
-PI..PI
range so you might want to account for that
(btw here I assume that
x
and
y
are offsets from the center of the pizza)
a

alexhelder

10/16/2023, 7:36 PM
Thanks Romain. The Pizza was a simplification of my actual problem, but your tips will help. I am working on a goniophotometer-like app; the phone and illuminant rotate on same axis. The UI rotates with the phone as samples are taken so that user always sees things level and can remove erroneous samples. The UI looks like a starburst chart (kinda pizza like :D) The actual sensor data is read from another device that is stationary.
r

romainguy

10/16/2023, 7:43 PM
Sounds like a fun project 😀
a

alexhelder

10/16/2023, 8:20 PM
Ha thanks. This is for an enthusiast community that tests flashlights. A real integrating sphere is $$$$. Ideally there would be a spectrometer where the lux sensor is, to get CCT/dUV shift vs angle, but I have not found an affordable, semi-accurate one yet. Beaded TIRs solve most tint shift problems but it can be very pronounced with certain domed emitters + reflector setups. The last part, out of scope, is flicker and driver dynamic range; many flashlight drivers are unstable at their lowest settings - but that also requires special hardware / photosensors with fast response times.
r

romainguy

10/16/2023, 8:24 PM
I'm familiar with stuff like this :)
a

alexhelder

10/16/2023, 8:37 PM
I bet, you are pretty famous in the photography circles ... not sure if you do any light painting photography, but this fellow is pretty active in our circles https://www.stephenknightphotography.com/
r

romainguy

10/17/2023, 3:59 PM
Oh nice! I should check that out. That said most of the lighting work I’ve done was through building Filament and writing: https://google.github.io/filament/Filament.html
Got to spend a lot of quality time with light meters 😄
2 Views