Constraints

class Constraints(val minWidth: Int = 0, val maxWidth: Int = Int.MAX_VALUE, val minHeight: Int = 0, val maxHeight: Int = Int.MAX_VALUE)

The extents a parent offers a child: the least it must occupy along each axis and the most it may.

A container computes these for each of its children and measures the child under them; the child answers with an extent inside them. Int.MAX_VALUE as a maximum means the axis is unbounded - the parent imposes no ceiling there, which is what a container asked for the extent it prefers offers, and what maximumLayoutSize already reports for a row.

The extents are plain Ints, the unit every other geometry in this library is written in.

Throws

if either minimum is negative or greater than its own maximum

Constructors

Link copied to clipboard
constructor(minWidth: Int = 0, maxWidth: Int = Int.MAX_VALUE, minHeight: Int = 0, maxHeight: Int = Int.MAX_VALUE)

Types

Link copied to clipboard
object Companion

The standard constraints.

Properties

Link copied to clipboard

Whether the height has a finite maximum.

Link copied to clipboard

Whether the width has a finite maximum.

Link copied to clipboard

Whether the height can take exactly one value.

Link copied to clipboard

Whether the width can take exactly one value.

Link copied to clipboard
@Stable
val isZero: Boolean

Whether every size satisfying these constraints has zero area.

Link copied to clipboard

the most height the child may occupy, Int.MAX_VALUE for an unbounded axis

Link copied to clipboard

the most width the child may occupy, Int.MAX_VALUE for an unbounded axis

Link copied to clipboard

the least height the child must occupy

Link copied to clipboard

the least width the child must occupy

Functions

Link copied to clipboard

Takes a size and returns the closest size to it that satisfies the constraints.

Takes otherConstraints and returns the result of coercing them in the current constraints. Note this means that any size satisfying the resulting constraints will satisfy the current constraints, but they might not satisfy the otherConstraints when the two set of constraints are disjoint. Examples (showing only width, height works the same): (minWidth=2, maxWidth=10).constrain(minWidth=7, maxWidth=12) -> (minWidth = 7, maxWidth = 10) (minWidth=2, maxWidth=10).constrain(minWidth=11, maxWidth=12) -> (minWidth=10, maxWidth=10) (minWidth=2, maxWidth=10).constrain(minWidth=5, maxWidth=7) -> (minWidth=5, maxWidth=7)

Link copied to clipboard
@Stable
fun Constraints.constrainHeight(height: Int): Int

Takes a height and returns the closest size to it that satisfies the constraints.

Link copied to clipboard
@Stable
fun Constraints.constrainWidth(width: Int): Int

Takes a width and returns the closest size to it that satisfies the constraints.

Link copied to clipboard
fun copy(minWidth: Int = this.minWidth, maxWidth: Int = this.maxWidth, minHeight: Int = this.minHeight, maxHeight: Int = this.maxHeight): Constraints

A new constraint with every extent left unchanged unless this call supplies a replacement.

Link copied to clipboard

A copy with both minimum dimensions reset to zero.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Takes a size and returns whether it satisfies the current constraints.

Link copied to clipboard
@Stable
fun Constraints.offset(horizontal: Int = 0, vertical: Int = 0): Constraints

Returns the Constraints obtained by offsetting the current instance with the given values.

Link copied to clipboard
open override fun toString(): String