Size
-
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 |
|---|
object Size.Companion |
Public companion properties |
||
|---|---|---|
Size |
Cmn
|
|
Size |
An empty size, one with a zero width and a zero height. |
Cmn
|
Public functions |
||
|---|---|---|
inline operator Float |
Cmn
|
|
inline operator Float |
Cmn
|
|
Size |
Returns a copy of this Size instance optionally overriding the width or height parameter |
Cmn
|
operator Size |
Division operator. |
Cmn
|
Boolean |
isEmpty()Whether this size encloses a non-zero area. |
Cmn
|
operator Size |
Multiplication operator. |
Cmn
|
open String |
toString() |
Cmn
|
Public properties |
||
|---|---|---|
Float |
Cmn
|
|
Float |
Cmn
|
|
Float |
Cmn
|
|
Long |
|
Cmn
|
Float |
Cmn
|
Extension functions |
||
|---|---|---|
IntSize |
Cmn
|
|
IntSize |
Cmn
|
|
operator Size |
Size.div(scaleFactor: ScaleFactor)Division operator with |
Cmn
|
operator Size |
Size.times(scaleFactor: ScaleFactor)Multiplication operator with |
Cmn
|
inline Size |
Size.takeOrElse(block: () -> Size)If this |
Cmn
|
Rect |
Cmn
|
Extension properties |
||
|---|---|---|
Offset |
Returns the |
Cmn
|
Boolean |
|
Cmn
|
Boolean |
|
Cmn
|
Public companion properties
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.
Public functions
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.
Public properties
packedValue
val 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.
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.
div
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.