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

Size

@Immutable inline class Size
kotlin.Any
   ↳ androidx.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.

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
minus(other: Offset)

Binary subtraction operator for Size.

operator Offset
minus(other: Size)

operator Size
plus(other: Offset)

Binary addition operator for adding an Offset to a Size.

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.

Companion functions
Size
copy(source: Size)

Creates an instance of Size that has the same values as another.

Size
fromHeight(height: Float)

Creates a Size with the given height and an infinite width.

Size
fromRadius(radius: Float)

Creates a square Size whose width and height are twice the given dimension.

Size
fromWidth(width: Float)

Creates a Size with the given width and an infinite height.

Size
square(dimension: Float)

Creates a square Size whose width and height are the given dimension.

Extension functions
From androidx.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.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.

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.

minus

@Stable operator fun minus(other: Offset): Size

Binary subtraction operator for Size.

Subtracting a Size from a Size returns the Offset that describes how much bigger the left-hand-side operand is than the right-hand-side operand. Adding that resulting Offset to the Size that was the right-hand-side operand would return a Size equal to the Size that was the left-hand-side operand. (i.e. if sizeA - sizeB -> offsetA, then offsetA + sizeB -> sizeA)

Subtracting an Offset from a Size returns the Size that is smaller than the Size operand by the difference given by the Offset operand. In other words, the returned Size has a width consisting of the width of the left-hand-side operand minus the Offset.x dimension of the right-hand-side operand, and a height consisting of the height of the left-hand-side operand minus the Offset.y dimension of the right-hand-side operand.

minus

@Stable operator fun minus(other: Size): Offset

plus

@Stable operator fun plus(other: Offset): Size

Binary addition operator for adding an Offset to a Size.

Returns a Size whose width is the sum of the width of the left-hand-side operand, a Size, and the Offset.x dimension of the right-hand-side operand, an Offset, and whose height is the sum of the height of the left-hand-side operand and the Offset.y dimension of the right-hand-side operand.

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 functions

copy

fun copy(source: Size): Size

Deprecated.

Creates an instance of Size that has the same values as another.

fromHeight

fun fromHeight(height: Float): Size

Creates a Size with the given height and an infinite width.

fromRadius

fun fromRadius(radius: Float): Size

Creates a square Size whose width and height are twice the given dimension.

This is a square that contains a circle with the given radius.

See also:

fromWidth

fun fromWidth(width: Float): Size

Creates a Size with the given width and an infinite height.

square

fun square(dimension: Float): Size

Creates a square Size whose width and height are the given dimension.

See also:

  • new Size.fromRadius, which is more convenient when the available size is the radius of a circle.

Companion properties

UnspecifiedSize

@Stable val UnspecifiedSize: 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.