androidx.compose.ui.unit
Interfaces
Density |
A density of the screen. |
Cmn
|
FontScaling |
Cmn
android
|
Classes
Constraints |
Immutable constraints for measuring layouts, used by |
Cmn
|
Dp |
Dimension value representing device-independent pixels (dp). |
Cmn
|
DpOffset |
A two-dimensional offset using |
Cmn
|
DpRect |
A four dimensional bounds using |
Cmn
|
DpSize |
A two-dimensional Size using |
Cmn
|
IntOffset |
A two-dimensional position using |
Cmn
|
IntRect |
An immutable, 2D, axis-aligned, integer bounds rectangle whose coordinates are relative to a given origin. |
Cmn
|
IntSize |
A two-dimensional size class used for measuring in |
Cmn
|
TextUnit |
The unit used for text related dimension value. |
Cmn
|
TextUnitType |
An enum class defining for type of |
Cmn
|
Velocity |
A two dimensional velocity in pixels per second. |
Cmn
|
Objects
ComposeUiUnitFlags |
This is a collection of flags which are used to guard against regressions in some of the "riskier" refactors or new feature support that is added to this module. |
Cmn
|
Dp.Companion |
Cmn
|
|
DpOffset.Companion |
Cmn
|
|
IntOffset.Companion |
Cmn
|
|
IntSize.Companion |
Cmn
|
Annotations
Enums
LayoutDirection |
A class for defining layout directions. |
Cmn
|
Top-level functions summary
Constraints |
Constraints(minWidth: Int, maxWidth: Int, minHeight: Int, maxHeight: Int)Create a |
Cmn
|
Density |
android
|
|
Density |
A density of the screen. |
Cmn
|
inline DpOffset |
Cmn
|
|
DpSize |
Cmn
|
|
inline IntOffset |
Cmn
|
|
IntRect |
Construct a rectangle that bounds the given circle |
Cmn
|
IntRect |
Construct a rectangle from its left and top edges as well as its width and height. |
Cmn
|
IntRect |
Construct the smallest rectangle that encloses the given offsets, treating them as vectors from the origin. |
Cmn
|
inline IntSize |
Cmn
|
|
TextUnit |
TextUnit(value: Float, type: TextUnitType)Construct a new TextUnit. |
Cmn
|
Velocity |
Constructs an Velocity from the given relative x and y velocities. |
Cmn
|
Dp |
Linearly interpolate between two |
Cmn
|
DpOffset |
Linearly interpolate between two |
Cmn
|
DpSize |
Linearly interpolate between two |
Cmn
|
IntOffset |
Linearly interpolate between two |
Cmn
|
IntRect |
Linearly interpolate between two rectangles. |
Cmn
|
TextUnit |
Linearly interpolate between two |
Cmn
|
inline Dp |
Cmn
|
|
inline Dp |
Cmn
|
Extension functions summary
inline Dp |
Dp.coerceAtLeast(minimumValue: Dp)Ensures that this value is not less than the specified |
Cmn
|
inline Dp |
Dp.coerceAtMost(maximumValue: Dp)Ensures that this value is not greater than the specified |
Cmn
|
inline Dp |
Ensures that this value lies in the specified range |
Cmn
|
Constraints |
Constraints.constrain(otherConstraints: Constraints)Takes |
Cmn
|
IntSize |
Constraints.constrain(size: IntSize)Takes a size and returns the closest size to it that satisfies the constraints. |
Cmn
|
Int |
Constraints.constrainHeight(height: Int)Takes a height and returns the closest size to it that satisfies the constraints. |
Cmn
|
Int |
Constraints.constrainWidth(width: Int)Takes a width and returns the closest size to it that satisfies the constraints. |
Cmn
|
Boolean |
Constraints.isSatisfiedBy(size: IntSize)Takes a size and returns whether it satisfies the current constraints. |
Cmn
|
operator Offset |
Cmn
|
|
operator Offset |
Cmn
|
|
Constraints |
Constraints.offset(horizontal: Int, vertical: Int)Returns the Constraints obtained by offsetting the current instance with the given values. |
Cmn
|
operator Offset |
Cmn
|
|
operator Offset |
Cmn
|
|
IntOffset |
Cmn
|
|
IntRect |
Cmn
|
|
IntSize |
Cmn
|
|
inline Dp |
Dp.takeOrElse(block: () -> Dp)If this |
Cmn
|
inline DpOffset |
DpOffset.takeOrElse(block: () -> DpOffset)If this |
Cmn
|
inline DpSize |
DpSize.takeOrElse(block: () -> DpSize)If this |
Cmn
|
inline TextUnit |
TextUnit.takeOrElse(block: () -> TextUnit)If this |
Cmn
|
inline operator Dp |
Cmn
|
|
inline operator Dp |
Cmn
|
|
inline operator Dp |
Cmn
|
|
inline operator TextUnit |
Multiply a |
Cmn
|
inline operator TextUnit |
Multiply a |
Cmn
|
inline operator TextUnit |
Multiply a |
Cmn
|
inline operator DpSize |
Cmn
|
|
inline operator DpSize |
Cmn
|
|
inline operator IntSize |
Returns an |
Cmn
|
IntRect |
Cmn
|
|
IntSize |
Cmn
|
|
inline Offset |
Cmn
|
|
Rect |
Cmn
|
|
Size |
Cmn
|
Extension properties summary
DpOffset |
Returns the |
Cmn
|
IntOffset |
Returns the |
Cmn
|
Dp |
Create a |
Cmn
|
Dp |
Create a |
Cmn
|
Dp |
Create a |
Cmn
|
TextUnit |
Creates an EM unit |
Cmn
|
TextUnit |
Creates an EM unit |
Cmn
|
TextUnit |
Creates an EM unit |
Cmn
|
Dp |
A height of this Bounds in |
Cmn
|
Boolean |
Return |
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
DpSize |
Returns the size of the |
Cmn
|
TextUnit |
Creates a SP unit |
Cmn
|
TextUnit |
Creates a SP unit |
Cmn
|
TextUnit |
Creates a SP unit |
Cmn
|
Dp |
A width of this Bounds in |
Cmn
|
Top-level functions
Constraints
fun Constraints(
minWidth: Int = 0,
maxWidth: Int = Infinity,
minHeight: Int = 0,
maxHeight: Int = Infinity
): Constraints
Create a Constraints. minWidth and minHeight must be positive and maxWidth and maxHeight must be greater than or equal to minWidth and minHeight, respectively, or Infinity.
Density
fun Density(density: Float, fontScale: Float = 1.0f): Density
A density of the screen. Used for convert Dp to pixels.
IntRect
fun IntRect(center: IntOffset, radius: Int): IntRect
Construct a rectangle that bounds the given circle
IntRect
fun IntRect(offset: IntOffset, size: IntSize): IntRect
Construct a rectangle from its left and top edges as well as its width and height.
| Parameters | |
|---|---|
offset: IntOffset |
Offset to represent the top and left parameters of the Rect |
size: IntSize |
Size to determine the width and height of this |
| Returns | |
|---|---|
IntRect |
Rect with |
IntRect
fun IntRect(topLeft: IntOffset, bottomRight: IntOffset): IntRect
Construct the smallest rectangle that encloses the given offsets, treating them as vectors from the origin.
TextUnit
fun TextUnit(value: Float, type: TextUnitType): TextUnit
Construct a new TextUnit.
| Parameters | |
|---|---|
value: Float |
of the dimension |
type: TextUnitType |
dimension |
Velocity
fun Velocity(x: Float, y: Float): Velocity
Constructs an Velocity from the given relative x and y velocities.
lerp
fun lerp(start: Dp, stop: Dp, fraction: Float): Dp
Linearly interpolate between two Dps.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.
lerp
fun lerp(start: DpOffset, stop: DpOffset, fraction: Float): DpOffset
Linearly interpolate between two DpOffsets.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.
lerp
fun lerp(start: DpSize, stop: DpSize, fraction: Float): DpSize
Linearly interpolate between two DpSizes.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start, 1.0 meaning that the interpolation has finished, returning stop, and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.
lerp
fun lerp(start: IntOffset, stop: IntOffset, fraction: Float): IntOffset
Linearly interpolate between two IntOffsets.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.
lerp
fun lerp(start: IntRect, stop: IntRect, fraction: Float): IntRect
Linearly interpolate between two rectangles.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves).
Values for fraction are usually obtained from an AnimationAnimationController.
lerp
fun lerp(start: TextUnit, stop: TextUnit, fraction: Float): TextUnit
Linearly interpolate between two TextUnits.
The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if |
Extension functions
coerceAtLeast
inline fun Dp.coerceAtLeast(minimumValue: Dp): Dp
Ensures that this value is not less than the specified minimumValue.
| Returns | |
|---|---|
Dp |
this value if it's greater than or equal to the |
coerceAtMost
inline fun Dp.coerceAtMost(maximumValue: Dp): Dp
Ensures that this value is not greater than the specified maximumValue.
| Returns | |
|---|---|
Dp |
this value if it's less than or equal to the |
coerceIn
inline fun Dp.coerceIn(minimumValue: Dp, maximumValue: Dp): Dp
Ensures that this value lies in the specified range minimumValue..maximumValue.
| Returns | |
|---|---|
Dp |
this value if it's in the range, or |
constrain
fun Constraints.constrain(otherConstraints: Constraints): Constraints
Takes otherConstraints and returns the result of coercing them in the current constraints. Note this means that any size satisfying the resulting constraints will satisfy the current constraints, but they might not satisfy the otherConstraints when the two set of constraints are disjoint. Examples (showing only width, height works the same): (minWidth=2, maxWidth=10).constrain(minWidth=7, maxWidth=12) -> (minWidth = 7, maxWidth = 10) (minWidth=2, maxWidth=10).constrain(minWidth=11, maxWidth=12) -> (minWidth=10, maxWidth=10) (minWidth=2, maxWidth=10).constrain(minWidth=5, maxWidth=7) -> (minWidth=5, maxWidth=7)
constrain
fun Constraints.constrain(size: IntSize): IntSize
Takes a size and returns the closest size to it that satisfies the constraints.
constrainHeight
fun Constraints.constrainHeight(height: Int): Int
Takes a height and returns the closest size to it that satisfies the constraints.
constrainWidth
fun Constraints.constrainWidth(width: Int): Int
Takes a width and returns the closest size to it that satisfies the constraints.
isSatisfiedBy
fun Constraints.isSatisfiedBy(size: IntSize): Boolean
Takes a size and returns whether it satisfies the current constraints.
offset
fun Constraints.offset(horizontal: Int = 0, vertical: Int = 0): Constraints
Returns the Constraints obtained by offsetting the current instance with the given values.
roundToIntSize
fun Size.roundToIntSize(): IntSize
Convert a Size to an IntSize. This rounds Size.width and Size.height to the nearest integer.
takeOrElse
inline fun Dp.takeOrElse(block: () -> Dp): Dp
If this Dp then this is returned, otherwise block is executed and its result is returned.
takeOrElse
inline fun DpOffset.takeOrElse(block: () -> DpOffset): DpOffset
If this DpOffset isSpecified then this is returned, otherwise block is executed and its result is returned.
takeOrElse
inline fun DpSize.takeOrElse(block: () -> DpSize): DpSize
If this DpSize isSpecified then this is returned, otherwise block is executed and its result is returned.
takeOrElse
inline fun TextUnit.takeOrElse(block: () -> TextUnit): TextUnit
If this TextUnit then this is returned, otherwise block is executed and its result is returned.
times
inline operator fun Float.times(other: TextUnit): TextUnit
Multiply a TextUnit by a scalar.
This operation works only if the right operand is not equal to TextUnit.Unspecified. The result of this operation is the same unit type of the given one.
times
inline operator fun Double.times(other: TextUnit): TextUnit
Multiply a TextUnit by a scalar.
This operation works only if the right operand is not equal to TextUnit.Unspecified. The result of this operation is the same unit type of the given one.
times
inline operator fun Int.times(other: TextUnit): TextUnit
Multiply a TextUnit by a scalar.
This operation works only if the right operand is not equal to TextUnit.Unspecified. The result of this operation is the same unit type of the given one.
times
inline operator fun Int.times(size: IntSize): IntSize
Returns an IntSize with size's IntSize.width and IntSize.height multiplied by this.
toIntSize
fun Size.toIntSize(): IntSize
Convert a Size to an IntSize. This rounds the width and height values down to the nearest integer.
Extension properties
center
val DpSize.center: DpOffset
Returns the DpOffset of the center of the rect from the point of 0, 0 with this DpSize.
center
val IntSize.center: IntOffset
Returns the IntOffset of the center of the rect from the point of 0, 0 with this IntSize.
dp
val Double.dp: Dp
Create a Dp using a Double: val left = 10.0 val x = left.dp // -- or -- val y = 10.0.dp
dp
val Float.dp: Dp
Create a Dp using a Float: val left = 10f val x = left.dp // -- or -- val y = 10f.dp