Density
@Immutable interface Density
androidx.compose.ui.unit.Density |
A density of the screen. Used for the conversions between Dp, Px, Int and TextUnit.
val sizeInPx = with(AmbientDensity.current) { 16.dp.toPx() }
Summary
Public methods | |
---|---|
open Dp |
Convert Sp to Dp. |
open Dp | |
open Dp |
Convert a Float pixel value to a Dp |
open Int | |
open Int |
Convert Sp to Int by rounding |
open Float |
Convert Dp to pixels. |
open Float |
Convert Sp to pixels. |
open Rect | |
open TextUnit |
Convert Dp to Sp. |
open TextUnit |
Convert an Int pixel value to Sp. |
open TextUnit |
Convert a Float pixel value to a Sp |
Properties | |
---|---|
abstract Float |
The logical density of the display. |
abstract Float |
Current user preference for the scaling factor for fonts. |
Public methods
toDp
@Stable open fun TextUnit.toDp(): Dp
Convert Sp to Dp.
Exceptions | |
---|---|
IllegalStateException |
if TextUnit other than SP unit is specified. |
toPx
@Stable open fun TextUnit.toPx(): Float
Convert Sp to pixels. Pixels are used to paint to Canvas.
Exceptions | |
---|---|
IllegalStateException |
if TextUnit other than SP unit is specified. |
Properties
density
@Stable abstract val density: Float
The logical density of the display. This is a scaling factor for the Dp unit.
fontScale
@Stable abstract val fontScale: Float
Current user preference for the scaling factor for fonts.