Hi everyone ! Is there a simple way to write somet...
# compose
l
Hi everyone ! Is there a simple way to write something like this
Copy code
60.dp.toPx()
Inside a composable ?
s
Do you mean simpler than that: val px = with(DensityAmbient.current) { 60.dp.toIntPx() }?
m
maybe an extension function for Dp not scoped to Density that uses the density from the ambient
a
We have a few API changes in progress that should reduce the need to do this using the ambient density. Can you give an example of where you are doing this so that we can consider it in those changes?
Generally we want to keep things simpler by working in dp during composition and pixels in layout, drawing, and touch input handling. In those pixel cases the density should already be available and this will just work
🙌 4
a
Looking forward to seeing what the api changes are like!
a
a lot of them are likely to be moving pixel-based computations to post-composition with
Density
-based receiver scopes
things like
Modifier.offset
, for example
some of the new suspend-based input modifiers already do this
layout and drawing already do, etc.
l
Hi, sorry for the late answer, and thank you for your suggestions. In fact I wanted to use this syntax for creating a Picasso element (the famous image loading library), as I have to give the size in Pixels in the constructor.
👍 1