Density

Known direct subclasses
AwaitPointerEventScope

Receiver scope for awaiting pointer events in a call to PointerInputScope.awaitPointerEventScope.

CacheDrawScope

Handle to a drawing environment that enables caching of content based on the resolved size.

DrawScope

Creates a scoped drawing environment with the provided Canvas.

GraphicsLayerScope

A scope which can be used to define the effects to apply for the content, such as scaling (scaleX, scaleY), rotation (rotationX, rotationY, rotationZ), opacity (alpha), shadow (shadowElevation, shape), and clipping (clip, shape).

InjectionScope

The receiver scope of all input injection lambdas offered in ui-test, such as performTouchInput and performMouseInput.

IntrinsicMeasureScope

The receiver scope of a layout's intrinsic measurements lambdas.

PointerInputScope

Receiver scope for Modifier.pointerInput that permits handling pointer input.

PressGestureScope

Receiver scope for detectTapGestures's onPress lambda.

RulerScope

A scope used in MeasureScope.layout for the rulers parameter to allow a layout to define Ruler values for children.

Known indirect subclasses
ApproachIntrinsicMeasureScope

The receiver scope of a layout's intrinsic approach measurements lambdas.

ApproachMeasureScope

ApproachMeasureScope provides access to lookahead results to allow ApproachLayoutModifierNode to leverage lookahead results to define how measurements and placements approach their destination.

CanvasDrawScope

Implementation of DrawScope that issues drawing commands into the specified canvas and bounds via CanvasDrawScope.draw

ContentDrawScope

Receiver scope for drawing content into a layout, where the content can be drawn between other canvas operations.

DragAndDropSourceScope

This interface is deprecated. Replaced by a callback for obtain a transfer data,start detection is performed by Compose itself

KeyInjectionScope

The receiver scope of the key input injection lambda from performKeyInput.

LazyLayoutMeasureScope

The receiver scope of a LazyLayout's measure lambda.

MeasureScope

The receiver scope of a layout's measure lambda.

MouseInjectionScope

The receiver scope of the mouse input injection lambda from performMouseInput.

MultiModalInjectionScope

The receiver scope of the multi-modal input injection lambda from performMultiModalInput.

RotaryInjectionScope

The receiver scope of rotary input injection lambda from performRotaryScrollInput.

SubcomposeMeasureScope

The receiver scope of a SubcomposeLayout's measure lambda which adds ability to dynamically subcompose a content during the measuring on top of the features provided by MeasureScope.

TouchInjectionScope

The receiver scope of the touch input injection lambda from performTouchInput.


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

import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp

val sizeInPx = with(LocalDensity.current) { 16.dp.toPx() }

Summary

Public functions

open Int

Convert Dp to Int by rounding

Cmn
open Int

Convert Sp to Int by rounding

Cmn
open Dp

Convert an Int pixel value to Dp.

Cmn
open Dp

Convert a Float pixel value to a Dp

Cmn
open DpSize

Convert a Size to a DpSize.

Cmn
open Float

Convert Dp to pixels.

Cmn
open Float

Convert Sp to pixels.

Cmn
open Rect

Convert a DpRect to a Rect.

Cmn
open Size

Convert a DpSize to a Size.

Cmn
open TextUnit

Convert an Int pixel value to Sp.

Cmn
open TextUnit

Convert a Float pixel value to a Sp

Cmn

Public properties

Float

The logical density of the display.

Cmn

Inherited functions

From androidx.compose.ui.unit.FontScaling
open Dp

Convert Sp to Dp.

Cmn
open TextUnit

Convert Dp to Sp.

Cmn

Inherited properties

From androidx.compose.ui.unit.FontScaling
Float

Current user preference for the scaling factor for fonts.

Cmn

Public functions

roundToPx

open fun Dp.roundToPx(): Int

Convert Dp to Int by rounding

roundToPx

open fun TextUnit.roundToPx(): Int

Convert Sp to Int by rounding

toDp

open fun Int.toDp(): Dp

Convert an Int pixel value to Dp.

toDp

open fun Float.toDp(): Dp

Convert a Float pixel value to a Dp

toDpSize

open fun Size.toDpSize(): DpSize

Convert a Size to a DpSize.

open fun Dp.toPx(): Float

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

open fun TextUnit.toPx(): Float

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

Throws
kotlin.IllegalStateException

if TextUnit other than SP unit is specified.

toRect

open fun DpRect.toRect(): Rect

Convert a DpRect to a Rect.

open fun DpSize.toSize(): Size

Convert a DpSize to a Size.

toSp

open fun Int.toSp(): TextUnit

Convert an Int pixel value to Sp.

toSp

open fun Float.toSp(): TextUnit

Convert a Float pixel value to a Sp

Public properties

density

val densityFloat

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