Thread
#compose
    l

    loloof64

    1 year ago
    Hi ! Is there a simple way to convert size (is given as dp) to sp unit ?
    val cellsSize = with(DensityAmbient.current) {
       (size.toIntPx() * 0.1111) // Can I convert this result (which is px in Int) into an Sp unit, for a text ?
    }
    I've been searching at https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary. But did not find which one could be useful.
    André Kindwall

    André Kindwall

    1 year ago
    val cellsSize = with(DensityAmbient.current) {
        (size.toPx() * 0.1111f).toSp()
    }
    l

    loloof64

    1 year ago
    Thank you very much 😃 I've done a CTRL+F though.
    In fact I should even write
    val cellsSize = with(DensityAmbient.current) {
            Dp((size.toIntPx() * 0.1111).toFloat()).toSp()
        }
    Because toSp() is available from a Dp unit.
    André Kindwall

    André Kindwall

    1 year ago
    val cellsSize = with(DensityAmbient.current) {
        (size * 0.1111f).toSp()
    }
    This is even better
    l

    loloof64

    1 year ago
    Yes, thank you