androidx.compose.ui.geometry
Size
Value class · from org.jetbrains.compose.ui:ui-geometry:1.12.2
No hand-written docs yet.
Holds a 2D floating-point size.
value class Size(
packedValue: Long,
)
How to get one
Create it
Size(packedValue)constructorSize(width: Float, height: Float)
Ready-made values and functions that return it
AwaitPointerEventScope:extendedTouchPaddingBrush:intrinsicSizeCacheDrawScope:sizeDensity:toSize()DrawScope:sizeGraphicsLayerScope:sizePainter:intrinsicSizePointerInputScope:extendedTouchPaddingRect:sizeVisibilityThreshold
Used by
Parameters that take a Size.
Brush.applyTo(size)CanvasDrawScope.draw(size)ContentScale.computeScaleFactor(srcSize, dstSize)CornerBasedShape.createOutline(size)CornerSize.toPx(shapeSize)DrawScope.drawArc(size)DrawScope.drawOval(size)DrawScope.drawRect(size)DrawScope.drawRoundRect(size)Painter.draw(size)Rect(size)ShaderBrush.createShader(size)Shape.createOutline(size)
Properties
width
val width: Float
height
val height: Float
Zero
val Zero: Size
An empty size, one with a zero width and a zero height.
Unspecified
val Unspecified: Size
A size whose width and height are unspecified. This is a sentinel value used to initialize a non-null parameter. Access to width or height on an unspecified size is not allowed.
minDimension
val minDimension: Float
The lesser of the magnitudes of the width and the height.
maxDimension
val maxDimension: Float
The greater of the magnitudes of the width and the height.
packedValue
val packedValue: Long
Functions
component1
fun component1(): Float
component2
fun component2(): Float
copy
fun copy(
width: Float = unpackFloat1(packedValue),
height: Float = unpackFloat2(packedValue),
): Size
Returns a copy of this Size instance optionally overriding the width or height parameter
isEmpty
fun isEmpty(): Boolean
Whether this size encloses a non-zero area.
times
fun times(operand: Float): Size
Multiplication operator.
div
fun div(operand: Float): Size
Division operator.
Library docs
Holds a 2D floating-point size.
You can think of this as an Offset from the origin.
To create a Size, call the top-level function that accepts a width/height pair of dimensions:
val size = Size(width, height)
The primary constructor of Size is intended to be used with the packedValue property to allow
storing sizes in arrays or collections of primitives without boxing.