Constraints

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

Immutable constraints used for measuring child Layouts or LayoutModifiers. 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 set of Constraints received from their parent:

  • 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 child is allowed to choose a size that does not satisfy its constraints. However, when this happens, the parent will not read from the Placeable the real size of the child, but rather one that was coerced in the child's constraints; therefore, a parent can assume that its children will always respect the constraints in their layout algorithm. When this does not happen in reality, the position assigned to the child will be automatically offset to be centered on the space assigned by the parent under the assumption that constraints were respected. 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 or LayoutModifiers.

Companion functions

Constraints
fixed(width: IntPx, height: IntPx)

Creates constraints for fixed size in both dimensions.

Constraints
fixedHeight(height: IntPx)

Creates constraints for fixed height and unspecified width.

Constraints
fixedWidth(width: IntPx)

Creates constraints for fixed width and unspecified 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
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.

Properties

IntPx

The maximum height of a layout satisfying the constraints.

IntPx

The maximum width of a layout satisfying the constraints.

IntPx

The minimum height of a layout satisfying the constraints.

IntPx

The minimum width of a layout satisfying the constraints.

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 the area of a component respecting these constraints will definitely be 0.

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 or LayoutModifiers. 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 set of Constraints received from their parent:

  • 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 child is allowed to choose a size that does not satisfy its constraints. However, when this happens, the parent will not read from the Placeable the real size of the child, but rather one that was coerced in the child's constraints; therefore, a parent can assume that its children will always respect the constraints in their layout algorithm. When this does not happen in reality, the position assigned to the child will be automatically offset to be centered on the space assigned by the parent under the assumption that constraints were respected. 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).
Parameters
minWidth: IntPx = IntPx.Zero The minimum width of a layout satisfying the constraints.
maxWidth: IntPx = IntPx.Infinity The maximum width of a layout satisfying the constraints.
minHeight: IntPx = IntPx.Zero The minimum height of a layout satisfying the constraints.
maxHeight: IntPx = IntPx.Infinity The maximum height of a layout satisfying the constraints.

Properties

maxHeight

val maxHeight: IntPx

The maximum height of a layout satisfying the constraints.

maxWidth

val maxWidth: IntPx

The maximum width of a layout satisfying the constraints.

minHeight

val minHeight: IntPx

The minimum height of a layout satisfying the constraints.

minWidth

val minWidth: IntPx

The minimum width of a layout satisfying the constraints.

Companion functions

fixed

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

Creates constraints for fixed size in both dimensions.

fixedHeight

fun fixedHeight(height: IntPx): Constraints

Creates constraints for fixed height and unspecified width.

fixedWidth

fun fixedWidth(width: IntPx): Constraints

Creates constraints for fixed width and unspecified height.