Thread
#compose
    d

    dimsuz

    2 years ago
    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.
    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)
        )
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    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

    2 years ago
    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?
    Timo Drick

    Timo Drick

    2 years ago
    Which version of compose do you use? This .toPx() converts to float or .toIntPx() to int.
    d

    dimsuz

    2 years ago
    This was on
    dev13
    . I've just upgraded to
    dev17
    and
    .value
    can go now 🙂 Thanks!