https://kotlinlang.org logo
d

dimsuz

08/22/2020, 11:06 PM
Hi! Do I miss some easier way to convert
dp
to pixels for Offsets? It's OK but I get a feeling that's a bit verbose.
Copy code
drawLine(
      color,
      size.bottomLeft(Offset(1.dp.toPx().value, -1.dp.toPx().value)),
      size.topLeft(Offset(0f, 1.dp.toPx().value)),
      Stroke(width = 2.dp.toPx().value)
    )
z

Zach Klippenstein (he/him) [MOD]

08/23/2020, 12:02 AM
In the last few versions of Compose, pixels don’t have their own type. They’re just raw floats or ints, so you don’t need to use any converter functions.
d

dimsuz

08/23/2020, 10:43 AM
but in this case I have to convert from dp to float. Conversion is needed. Or do you mean I can do
1.dp.toPx()
in newer versions?
t

Timo Drick

08/23/2020, 11:24 AM
Which version of compose do you use? This .toPx() converts to float or .toIntPx() to int.
☝️ 1
d

dimsuz

08/23/2020, 11:54 AM
This was on
dev13
. I've just upgraded to
dev17
and
.value
can go now 🙂 Thanks!
5 Views