androidx.compose.ui.unit

Density

Interface · from org.jetbrains.compose.ui:ui-unit:1.12.2

No hand-written docs yet.

A density of the screen. Used for the conversions between pixels, Dp, Int and TextUnit.

interface Density : FontScaling

Is a

Kinds of Density

Anywhere a Density is expected, you can pass any of these.

How to get one

Create it

Or create one of the kinds listed above.

Used by

Parameters that take a Density.

Properties

density

val density: Float

The logical density of the display. This is a scaling factor for the Dp unit.

Functions

toPx

fun Dp.toPx(): Float

Convert Dp to pixels. Pixels are used to paint to Canvas.

roundToPx

fun Dp.roundToPx(): Int

Convert Dp to Int by rounding

fun TextUnit.toPx(): Float

Convert Sp to pixels. Pixels are used to paint to Canvas.

fun TextUnit.roundToPx(): Int

Convert Sp to Int by rounding

toDp

fun Int.toDp(): Dp

Convert an Int pixel value to Dp.

toSp

fun Int.toSp(): TextUnit

Convert an Int pixel value to Sp.

fun Float.toDp(): Dp

Convert a Float pixel value to a Dp

fun Float.toSp(): TextUnit

Convert a Float pixel value to a Sp

toRect

fun DpRect.toRect(): Rect

Convert a DpRect to a Rect.

toSize

fun DpSize.toSize(): Size

Convert a DpSize to a Size.

toDpSize

fun Size.toDpSize(): DpSize

Convert a Size to a DpSize.

Library docs

A density of the screen. Used for the conversions between pixels, Dp, Int and TextUnit.