Google is committed to advancing racial equity for Black communities. See how.

Size

@Immutable inline class Size
kotlin.Any
   ↳ androidx.compose.ui.geometry.Size

Holds a 2D floating-point size.

You can think of this as an Offset from the origin.

Summary

Public constructors
<init>(packedValue: Long)

Holds a 2D floating-point size.

Public methods
Offset

The offset to the center of the bottom edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset
bottomLeft(origin: Offset)

The offset to the intersection of the bottom and left edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset

The offset to the intersection of the bottom and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset
center(origin: Offset = Offset.Zero)

The offset to the point halfway between the left and right and the top and bottom edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset
centerLeft(origin: Offset)

The offset to the center of the left edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset

The offset to the center of the right edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

operator Float

operator Float

Boolean
contains(offset: Offset)

Whether the point specified by the given offset (which is assumed to be relative to the top left of the size) lies between the left and right and the top and bottom edges of a rectangle of this size.

Size
copy(width: Float = this.width, height: Float = this.height)

Returns a copy of this Size instance optionally overriding the width or height parameter

operator Size
div(operand: Float)

Division operator.

Size

A Size with the width and height swapped.

Boolean

Whether this size encloses a non-zero area.

operator Size
rem(operand: Float)

Modulo (remainder) operator.

operator Size
times(operand: Float)

Multiplication operator.

String

Offset
topCenter(origin: Offset)

The offset to the center of the top edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Offset
topLeft(origin: Offset)

The offset to the intersection of the top and left edges of the rectangle described by the given Offset (which is interpreted as the top-left corner) and this Size.

Offset
topRight(origin: Offset)

The offset to the intersection of the top and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

Size
truncDiv(operand: Float)

Integer (truncating) division operator.

Extension functions
From androidx.compose.ui.unit
Offset

Returns the Offset of the center of the rect from the point of 0,0 with this Size.

PxBounds

Convert a Size to a PxBounds.

From androidx.compose.ui.geometry
Rect

Convert a Size to a Rect.

Properties
Float

Float

The greater of the magnitudes of the width and the height.

Float

The lesser of the magnitudes of the width and the height.

Float

Companion properties
Size

A size whose width and height are infinite.

Size

An empty size, one with a zero width and a zero height.

Public constructors

<init>

Size(packedValue: Long)

Holds a 2D floating-point size.

You can think of this as an Offset from the origin.

Public methods

bottomCenter

@Stable fun bottomCenter(origin: Offset): Offset

The offset to the center of the bottom edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.bottomLeft.

bottomLeft

@Stable fun bottomLeft(origin: Offset): Offset

The offset to the intersection of the bottom and left edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.bottomLeft.

bottomRight

@Stable fun bottomRight(origin: Offset): Offset

The offset to the intersection of the bottom and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.bottomRight.

center

@Stable fun center(origin: Offset = Offset.Zero): Offset

The offset to the point halfway between the left and right and the top and bottom edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.center.

centerLeft

@Stable fun centerLeft(origin: Offset): Offset

The offset to the center of the left edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.centerLeft.

centerRight

@Stable fun centerRight(origin: Offset): Offset

The offset to the center of the right edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.centerLeft.

component1

@Stable inline operator fun component1(): Float

component2

@Stable inline operator fun component2(): Float

contains

@Stable fun contains(offset: Offset): Boolean

Whether the point specified by the given offset (which is assumed to be relative to the top left of the size) lies between the left and right and the top and bottom edges of a rectangle of this size.

Rectangles include their top and left edges but exclude their bottom and right edges.

copy

fun copy(
    width: Float = this.width,
    height: Float = this.height
): Size

Returns a copy of this Size instance optionally overriding the width or height parameter

div

@Stable operator fun div(operand: Float): Size

Division operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) divided by the scalar right-hand-side operand (a Float).

getFlipped

@Stable fun getFlipped(): Size

A Size with the width and height swapped.

isEmpty

@Stable fun isEmpty(): Boolean

Whether this size encloses a non-zero area.

Negative areas are considered empty.

rem

@Stable operator fun rem(operand: Float): Size

Modulo (remainder) operator.

Returns a Size whose dimensions are the remainder of dividing the left-hand-side operand (a Size) by the scalar right-hand-side operand (a Float).

times

@Stable operator fun times(operand: Float): Size

Multiplication operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) multiplied by the scalar right-hand-side operand (a Float).

toString

fun toString(): String

topCenter

@Stable fun topCenter(origin: Offset): Offset

The offset to the center of the top edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.topCenter.

topLeft

@Stable fun topLeft(origin: Offset): Offset

The offset to the intersection of the top and left edges of the rectangle described by the given Offset (which is interpreted as the top-left corner) and this Size.

See also Rect.topLeft.

topRight

@Stable fun topRight(origin: Offset): Offset

The offset to the intersection of the top and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect.topRight.

truncDiv

@Stable fun truncDiv(operand: Float): Size

Integer (truncating) division operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) divided by the scalar right-hand-side operand (a Float), rounded towards zero.

Properties

height

@Stable val height: Float

maxDimension

@Stable val maxDimension: Float

The greater of the magnitudes of the width and the height.

minDimension

@Stable val minDimension: Float

The lesser of the magnitudes of the width and the height.

width

@Stable val width: Float

Companion properties

Unspecified

@Stable val Unspecified: Size

A size whose width and height are infinite.

See also:

  • isInfinite, which checks whether either dimension is infinite.
  • isFinite, which checks whether both dimensions are finite.

Zero

@Stable val Zero: Size

An empty size, one with a zero width and a zero height.