• Cmn
    value class Size

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.

Summary

Nested types

Public companion properties

Size

A size whose width and height are unspecified.

Cmn
Size

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

Cmn

Public constructors

Size(packedValue: Long)
Cmn

Public functions

inline operator Float
Cmn
inline operator Float
Cmn
Size
copy(width: Float, height: Float)

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

Cmn
operator Size
div(operand: Float)

Division operator.

Cmn
Boolean

Whether this size encloses a non-zero area.

Cmn
operator Size
times(operand: Float)

Multiplication operator.

Cmn
open String
Cmn

Public properties

Float
Cmn
Float

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

Cmn
Float

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

Cmn
Long

Long value encoding the width and height components of the Size.

Cmn
Float
Cmn

Extension functions

IntSize

Convert a Size to an IntSize.

Cmn
IntSize

Convert a Size to an IntSize.

Cmn
operator Size
Size.div(scaleFactor: ScaleFactor)

Division operator with Size

Cmn
operator Size
Size.times(scaleFactor: ScaleFactor)

Multiplication operator with Size.

Cmn
inline Size
Size.takeOrElse(block: () -> Size)

If this Size isSpecified then this is returned, otherwise block is executed and its result is returned.

Cmn
Rect

Convert a Size to a Rect.

Cmn

Extension properties

Offset

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

Cmn
Boolean

false when this is Size.Unspecified.

Cmn
Boolean

true when this is Size.Unspecified.

Cmn

Public companion properties

Unspecified

val UnspecifiedSize

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.

Zero

val ZeroSize

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

Public constructors

Size

Size(packedValue: Long)
Parameters
packedValue: Long

Long value encoding the width and height components of the Size. Encoded values can be obtained by using the packedValue property of existing Size instances.

Public functions

component1

inline operator fun component1(): Float

component2

inline operator 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

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

isEmpty

fun isEmpty(): Boolean

Whether this size encloses a non-zero area.

Negative areas are considered empty.

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

Public properties

height

val heightFloat

maxDimension

val maxDimensionFloat

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

minDimension

val minDimensionFloat

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

packedValue

val packedValueLong

Long value encoding the width and height components of the Size. Encoded values can be obtained by using the packedValue property of existing Size instances.

width

val widthFloat

Extension functions

roundToIntSize

fun Size.roundToIntSize(): IntSize

Convert a Size to an IntSize. This rounds Size.width and Size.height to the nearest integer.

toIntSize

fun Size.toIntSize(): IntSize

Convert a Size to an IntSize. This rounds the width and height values down to the nearest integer.

operator fun Size.div(scaleFactor: ScaleFactor): Size

Division operator with Size

Return a new Size with the width and height divided by ScaleFactor.scaleX and ScaleFactor.scaleY respectively

times

operator fun Size.times(scaleFactor: ScaleFactor): Size

Multiplication operator with Size.

Return a new Size with the width and height multiplied by the ScaleFactor.scaleX and ScaleFactor.scaleY respectively

takeOrElse

inline fun Size.takeOrElse(block: () -> Size): Size

If this Size isSpecified then this is returned, otherwise block is executed and its result is returned.

fun Size.toRect(): Rect

Convert a Size to a Rect.

Extension properties

val Size.centerOffset

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

isSpecified

val Size.isSpecifiedBoolean

false when this is Size.Unspecified.

isUnspecified

val Size.isUnspecifiedBoolean

true when this is Size.Unspecified.