Size

open class Size : OffsetBase
kotlin.Any
   ↳ androidx.ui.engine.geometry.Size

Holds a 2D floating-point size.

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

Summary

Public constructors

<init>(width: Float, height: Float)

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)

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.

operator Size
div(operand: Float)

Division operator.

open Boolean
equals(other: Any?)

Size

A Size with the width and height swapped.

Float

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

Float

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

open Int

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.

open 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?
lerp(start: Size, stop: Size, fraction: Float)

Linearly interpolate between two sizes

Size
square(dimension: Float)

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

Inherited functions

Properties

open Float

open Float

Float

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(
    width: Float,
    height: Float)

Holds a 2D floating-point size.

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

Public methods

bottomCenter

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

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

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

fun center(origin: Offset): 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

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

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

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.

div

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).

equals

open fun equals(other: Any?): Boolean

getFlipped

fun getFlipped(): Size

A Size with the width and height swapped.

getLongestSide

fun getLongestSide(): Float

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

getShortestSide

fun getShortestSide(): Float

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

hashCode

open fun hashCode(): Int

isEmpty

fun isEmpty(): Boolean

Whether this size encloses a non-zero area.

Negative areas are considered empty.

minus

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.dx dimension of the right-hand-side operand, and a height consisting of the height of the left-hand-side operand minus the Offset.dy dimension of the right-hand-side operand.

minus

operator fun minus(other: Size): Offset

plus

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.dx 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.dy dimension of the right-hand-side operand.

rem

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

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

open fun toString(): String

topCenter

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

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

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

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

dx

open val dx: Float

dy

open val dy: Float

height

val height: Float

width

val width: Float

Companion functions

copy

fun copy(source: Size): Size

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.

lerp

fun lerp(
    start: Size,
    stop: Size,
    fraction: Float
): Size?

Linearly interpolate between two sizes

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 Animation, such as an AnimationController.

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

infinite

val infinite: 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

val zero: Size

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