Hi! Do I miss some easier way to convert `dp` to p...
# compose
d
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
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
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
Which version of compose do you use? This .toPx() converts to float or .toIntPx() to int.
☝️ 1
d
This was on
dev13
. I've just upgraded to
dev17
and
.value
can go now 🙂 Thanks!