I am constructing a UI with Compose, using .dp as ...
# compose
t
I am constructing a UI with Compose, using .dp as units. And I am also using detectTapGestures / onTap to get an offset, but it appears to be in pixels, not dp. Is there a Compose way to get the dp value from the offset value? Thank you!
c
Copy code
with(LocalDensity.current) { valueInpx.toDp() }
t
Perfect, works like a charm! Thank you!
g
Also,
PointerInputScope
is
Density
, so you can manipulate px<->dp within the gesture detectors.
👍 1
t
Well, that is certainly handy!
a
often you'll want to go the other direction, define in dp and convert to px for processing at the layers of layout, drawing, and input processing. It can somewhat depend on the use case but something to keep in mind
👍 1