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.
AwaitPointerEventScopeuiCacheDrawScopeuiCustomStyleScopefoundationDrawScopeui-graphicsCanvasDrawScopeui-graphicsContentDrawScopeui-graphics
FlexBoxConfigScopefoundation-layoutFlexConfigScopefoundation-layoutGraphicsLayerScopeuiGridConfigurationScopefoundation-layoutIntrinsicMeasureScopeuiPlacementScopeuiPointerInputScopeuiPressGestureScopefoundationRulerScopeuiShadowScopeuiTextAutoSizeLayoutScopefoundation
How to get one
Create it
Density(density: Float, fontScale: Float)
Or create one of the kinds listed above.
Used by
Parameters that take a Density.
absoluteOffset(offset)CacheDrawScope.record(density)CanvasDrawScope.draw(density)CornerSize.toPx(density)offset(offset)Shape.createOutline(density)WindowInsets.getBottom(density)WindowInsets.getLeft(density)WindowInsets.getRight(density)WindowInsets.getTop(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
toDpSize
fun Size.toDpSize(): DpSize
Library docs
A density of the screen. Used for the conversions between pixels, Dp, Int and TextUnit.