Constraints

@Immutable data class Constraints
kotlin.Any
   ↳ androidx.ui.core.Constraints

Immutable constraints used for measuring child Layouts. A parent Layout can measure their children using the measure method on the corresponding Measurables, method which takes the Constraints the child has to follow. A measured child is then responsible to choose for themselves and return a size which satisfies the received set of Constraints:

  • minWidth <= chosenWidth <= maxWidth
  • minHeight <= chosenHeight <= maxHeight The parent can then access the child chosen size on the resulting Placeable. The parent is responsible of defining a valid positioning of the children according to their sizes, so the parent needs to measure the children with appropriate Constraints, such that whatever valid sizes children choose, they can be laid out in a way that also respects the parent's incoming Constraints. Note that different children can be measured with different Constraints. A set of Constraints can have infinite maxWidth and/or maxHeight. This is a trick often used by parents to ask their children for their preferred size: unbounded constraints force children whose default behavior is to fill the available space (always size to maxWidth/maxHeight) to have an opinion about their preferred size. Most commonly, when measured with unbounded Constraints, these children will fallback to size themselves to wrap their content, instead of expanding to fill the available space (this is not always true as it depends on the child layout model, but is a common behavior for core layout components).

Summary

Public constructors

<init>(minWidth: IntPx = IntPx.Zero, maxWidth: IntPx = IntPx.Infinity, minHeight: IntPx = IntPx.Zero, maxHeight: IntPx = IntPx.Infinity)

Immutable constraints used for measuring child Layouts.

Companion functions

Constraints
tightConstraints(width: IntPx, height: IntPx)

Creates constraints tight in both dimensions.

Constraints

Creates constraints with tight height and loose width.

Constraints

Creates constraints with tight width and loose height.

Extension functions

From androidx.ui.core
IntPxSize

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

Constraints
Constraints.enforce(otherConstraints: Constraints)

Returns the result of coercing the current constraints in a different set of constraints.

Constraints

Returns a copy of the current instance with no max constraints.

Constraints

Returns a copy of the current instance with no min constraints.

Constraints
Constraints.offset(horizontal: IntPx = 0.ipx, vertical: IntPx = 0.ipx)

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

Boolean

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

Constraints

Returns a copy of the current instance with the constraints tightened to their largest size.

Constraints

Returns a copy of the current instance with the constraints tightened to their smallest size.

Constraints
Constraints.withTight(width: IntPx? = null, height: IntPx? = null)

Returns a copy of the current instance, overriding the specified values to be tight.

Properties

IntPx

IntPx

IntPx

IntPx

Extension properties

From androidx.ui.core
Boolean

Whether or not the upper bound on the maximum height.

Boolean

Whether or not the upper bound on the maximum width.

Boolean

Whether there is exactly one height value that satisfies the constraints.

Boolean

Whether there is exactly one width value that satisfies the constraints.

Boolean

Whether there is exactly one size that satisfies the constraints.

Boolean

Whether there is exactly one height value that satisfies the constraints.

Public constructors

<init>

Constraints(
    minWidth: IntPx = IntPx.Zero,
    maxWidth: IntPx = IntPx.Infinity,
    minHeight: IntPx = IntPx.Zero,
    maxHeight: IntPx = IntPx.Infinity)

Immutable constraints used for measuring child Layouts. A parent Layout can measure their children using the measure method on the corresponding Measurables, method which takes the Constraints the child has to follow. A measured child is then responsible to choose for themselves and return a size which satisfies the received set of Constraints:

  • minWidth <= chosenWidth <= maxWidth
  • minHeight <= chosenHeight <= maxHeight The parent can then access the child chosen size on the resulting Placeable. The parent is responsible of defining a valid positioning of the children according to their sizes, so the parent needs to measure the children with appropriate Constraints, such that whatever valid sizes children choose, they can be laid out in a way that also respects the parent's incoming Constraints. Note that different children can be measured with different Constraints. A set of Constraints can have infinite maxWidth and/or maxHeight. This is a trick often used by parents to ask their children for their preferred size: unbounded constraints force children whose default behavior is to fill the available space (always size to maxWidth/maxHeight) to have an opinion about their preferred size. Most commonly, when measured with unbounded Constraints, these children will fallback to size themselves to wrap their content, instead of expanding to fill the available space (this is not always true as it depends on the child layout model, but is a common behavior for core layout components).

Properties

maxHeight

val maxHeight: IntPx

maxWidth

val maxWidth: IntPx

minHeight

val minHeight: IntPx

minWidth

val minWidth: IntPx

Companion functions

tightConstraints

fun tightConstraints(
    width: IntPx,
    height: IntPx
): Constraints

Creates constraints tight in both dimensions.

tightConstraintsForHeight

fun tightConstraintsForHeight(height: IntPx): Constraints

Creates constraints with tight height and loose width.

tightConstraintsForWidth

fun tightConstraintsForWidth(width: IntPx): Constraints

Creates constraints with tight width and loose height.