Thread
#compose
    tylerwilson

    tylerwilson

    10 months ago
    I am constructing a UI with Compose, using .dp as units. And I am also using detectTapGestures / onTap to get an offset, but it appears to be in pixels, not dp. Is there a Compose way to get the dp value from the offset value? Thank you!
    Csaba Kozák

    Csaba Kozák

    10 months ago
    with(LocalDensity.current) { valueInpx.toDp() }
    tylerwilson

    tylerwilson

    10 months ago
    Perfect, works like a charm! Thank you!
    George Mount

    George Mount

    10 months ago
    Also,
    PointerInputScope
    is
    Density
    , so you can manipulate px<->dp within the gesture detectors.
    tylerwilson

    tylerwilson

    10 months ago
    Well, that is certainly handy!
    Adam Powell

    Adam Powell

    10 months ago
    often you'll want to go the other direction, define in dp and convert to px for processing at the layers of layout, drawing, and input processing. It can somewhat depend on the use case but something to keep in mind