Google is committed to advancing racial equity for Black communities. See how.

androidx.compose.ui

Interfaces

Alignment

An interface to position a point inside a 2D box.

DrawLayerModifier

A Modifier.Element that makes content draw into a layer, allowing easily changing properties of the drawn contents.

DrawModifier

A Modifier.Element that draws into the space of the layout.

FocusObserverModifier

A modifier that can be used to observe focus state changes.

FocusRequesterModifier

A modifier that can be used to pass in a FocusRequester that can be used to request focus state changes.

LayoutModifier

A Modifier.Element that changes how its wrapped content is measured and laid out.

Measurable

A part of the composition that can be measured.

MeasureResult

Interface holding the size and alignment lines of the measured layout, as well as the children positioning logic.

Modifier

An ordered, immutable collection of modifier elements that decorate or add behavior to Compose UI elements.

OnPositionedModifier

A modifier whose onPositioned is called with the final LayoutCoordinates of the Layout after measuring.

ParentDataModifier

A Modifier that provides data to the parent Layout.

Remeasurement

This object is associated with a layout node and allows to execute some extra measure/layout actions which are needed for some complex layouts.

RemeasurementModifier

A Modifier.Element that provides a Remeasurement object associated with the layout node the modifier is applied to.

WithConstraintsScope

Receiver scope being used by the children parameter of WithConstraints

ZIndexModifier

A Modifier.Element that controls the drawing order for the children of the same layout parent.

Classes

AbsoluteAlignment

Represents an absolute positioning of a point inside a 2D box.

AlignmentLine

Defines an offset line that can be used by parent layouts to align and position their children.

CombinedModifier

A node in a Modifier chain.

ContentDrawScope

Receiver scope for drawing content into a layout, where the content can be drawn between other canvas operations.

HorizontalAlignmentLine

A horizontal AlignmentLine.

MeasureScope

The receiver scope of a layout's measure lambda.

Placeable

A Placeable corresponds to a child layout that can be positioned by its parent layout.

TransformOrigin

A two-dimensional position represented as a fraction of the Layer's width and height

VerticalAlignmentLine

A vertical AlignmentLine.

Type-aliases

MeasureBlock

A function for performing layout measurement.

Top-level functions summary

Unit
Layout(children: () -> Unit, minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, modifier: Modifier = Modifier, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: () -> Unit, modifier: Modifier = Modifier, measureBlock: MeasureBlock)

Layout is the main core component for layout.

Unit
Layout(children: () -> Unit, measureBlocks: LayoutNode.MeasureBlocks, modifier: Modifier = Modifier)

Layout is the main core component for layout.

LayoutNode.MeasureBlocks

Default LayoutNode.MeasureBlocks object implementation, providing intrinsic measurements that use the measure block replacing the measure calls with intrinsic measurement calls.

Unit
MultiMeasureLayout(modifier: Modifier = Modifier, children: () -> Unit, measureBlock: MeasureBlock)

TransformOrigin
TransformOrigin(pivotFractionX: Float, pivotFractionY: Float)

Constructs a TransformOrigin from the given fractional values from the Layer's width and height

Unit
WithConstraints(modifier: Modifier = Modifier, children: WithConstraintsScope.() -> Unit)

A composable that defines its own content according to the available space, based on the incoming constraints or the current LayoutDirection.

LayoutNode.MeasureBlocks
measureBlocksOf(minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock, maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock, measureBlock: MeasureBlock)

Creates an instance of LayoutNode.MeasureBlocks to pass to Layout given intrinsic measures and a measure block.

Modifier
onPositioned(onPositioned: (LayoutCoordinates) -> Unit)

Returns modifier whose onPositioned is called with the final LayoutCoordinates of the Layout after measuring.

Extension functions summary

For Modifier
Modifier
Modifier.composed(factory: Modifier.() -> Modifier)

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies.

Modifier
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

Draw into a Canvas behind the modified content.

Modifier
Modifier.drawLayer(scaleX: Float = 1f, scaleY: Float = 1f, alpha: Float = 1f, translationX: Float = 0f, translationY: Float = 0f, shadowElevation: Float = 0f, rotationX: Float = 0f, rotationY: Float = 0f, rotationZ: Float = 0f, transformOrigin: TransformOrigin = TransformOrigin.Center, shape: Shape = RectangleShape, clip: Boolean = false)

Draw the content into a layer.

Modifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents.

Modifier

Add this modifier to a component to make it focusable.

Modifier
Modifier.focusObserver(onFocusChange: (FocusState) -> Unit)

Add this modifier to a component to observe focus state changes.

Modifier

Add this modifier to a component to observe changes to focus state.

Modifier

Creates a LayoutModifier that allows changing how the wrapped element is measured and laid out.

Modifier

Invoke onPositioned with the LayoutCoordinates of the element after positioning.

Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent.

For Composer
Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node.

For AlignmentLine
Int
AlignmentLine.merge(position1: Int, position2: Int)

Merges two values of the current alignment line.

Top-level functions

Layout

@Composable fun Layout(
    children: () -> Unit,
    minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    modifier: Modifier = Modifier,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

Intrinsic measurement blocks define the intrinsic sizes of the current layout. These can be queried by the parent in order to understand, in specific cases, what constraints should the layout be measured with:

  • minIntrinsicWidthMeasureBlock defines the minimum width this layout can take, given a specific height, such that the content of the layout will be painted correctly
  • minIntrinsicHeightMeasureBlock defines the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly
  • maxIntrinsicWidthMeasureBlock defines the minimum width such that increasing it further will not decrease the minimum intrinsic height
  • maxIntrinsicHeightMeasureBlock defines the minimum height such that increasing it further will not decrease the minimum intrinsic width

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.unit.Constraints

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(
    children,
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic width of the layout.
minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic height of the layout.
maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic width of the layout.
maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic height of the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable fun Layout(
    children: () -> Unit,
    modifier: Modifier = Modifier,
    measureBlock: MeasureBlock
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

The intrinsic measurements of this layout will be calculated by running the measureBlock, while swapping measure calls with appropriate intrinsic measurements. Note that these provided implementations will not be accurate in all cases - when this happens, the other overload of Layout should be used to provide correct measurements.

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.unit.Constraints

// We build a layout that will occupy twice as much space as its children,
// and will position them to be bottom right aligned.
Layout(children) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

Layout

@Composable inline fun Layout(
    children: () -> Unit,
    measureBlocks: LayoutNode.MeasureBlocks,
    modifier: Modifier = Modifier
): Unit

Layout is the main core component for layout. It can be used to measure and position zero or more children.

The intrinsic measurements of this layout will be calculated by using the measureBlocks instance.

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Example usage:

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.measureBlocksOf
import androidx.compose.ui.unit.Constraints

val measureBlocks = measureBlocksOf(
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Layout(children = children, measureBlocks = measureBlocks)
Parameters
children: () -> Unit The children composable to be laid out.
modifier: Modifier = Modifier Modifiers to be applied to the layout.
measureBlocks: LayoutNode.MeasureBlocks An LayoutNode.MeasureBlocks instance defining the measurement and positioning of the layout.

MeasuringIntrinsicsMeasureBlocks

fun MeasuringIntrinsicsMeasureBlocks(measureBlock: MeasureBlock): LayoutNode.MeasureBlocks

Default LayoutNode.MeasureBlocks object implementation, providing intrinsic measurements that use the measure block replacing the measure calls with intrinsic measurement calls.

MultiMeasureLayout

@Composable fun MultiMeasureLayout(
    modifier: Modifier = Modifier,
    children: () -> Unit,
    measureBlock: MeasureBlock
): Unit

Deprecated.

TransformOrigin

inline fun TransformOrigin(
    pivotFractionX: Float,
    pivotFractionY: Float
): TransformOrigin

Constructs a TransformOrigin from the given fractional values from the Layer's width and height

WithConstraints

@Composable fun WithConstraints(
    modifier: Modifier = Modifier,
    children: WithConstraintsScope.() -> Unit
): Unit

A composable that defines its own content according to the available space, based on the incoming constraints or the current LayoutDirection. Example usage:

import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.ui.WithConstraints

WithConstraints {
    val rectangleHeight = 100.dp
    if (maxHeight < rectangleHeight * 2) {
        Box(Modifier.preferredSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
    } else {
        Column {
            Box(Modifier.preferredSize(50.dp, rectangleHeight), backgroundColor = Color.Blue)
            Box(Modifier.preferredSize(50.dp, rectangleHeight), backgroundColor = Color.Gray)
        }
    }
}
The composable will compose the given children, and will position the resulting layout composablesin a parent Layout. This layout will be as small as possible such that it can fit itschildren. If the composition yields multiple layout children, these will be all placed at thetop left of the WithConstraints, so consider wrapping them in an additional commonparent if different positioning is preferred.
Parameters
modifier: Modifier = Modifier Modifier to be applied to the introduced layout.

measureBlocksOf

fun measureBlocksOf(
    minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock,
    maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock,
    measureBlock: MeasureBlock
): LayoutNode.MeasureBlocks

Creates an instance of LayoutNode.MeasureBlocks to pass to Layout given intrinsic measures and a measure block.

import androidx.compose.ui.Layout
import androidx.compose.ui.layout
import androidx.compose.ui.measureBlocksOf
import androidx.compose.ui.unit.Constraints

val measureBlocks = measureBlocksOf(
    minIntrinsicWidthMeasureBlock = { measurables, h ->
        // The min intrinsic width of this layout will be twice the largest min intrinsic
        // width of a child. Note that we call minIntrinsicWidth with h / 2 for children,
        // since we should be double the size of the children.
        (measurables.map { it.minIntrinsicWidth(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    minIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.minIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicWidthMeasureBlock = { measurables, h ->
        (measurables.map { it.maxIntrinsicHeight(h / 2) }.maxByOrNull { it } ?: 0) * 2
    },
    maxIntrinsicHeightMeasureBlock = { measurables, w ->
        (measurables.map { it.maxIntrinsicHeight(w / 2) }.maxByOrNull { it } ?: 0) * 2
    }
) { measurables, constraints ->
    // measurables contains one element corresponding to each of our layout children.
    // constraints are the constraints that our parent is currently measuring us with.
    val childConstraints = Constraints(
        minWidth = constraints.minWidth / 2,
        minHeight = constraints.minHeight / 2,
        maxWidth = constraints.maxWidth / 2,
        maxHeight = constraints.maxHeight / 2
    )
    // We measure the children with half our constraints, to ensure we can be double
    // the size of the children.
    val placeables = measurables.map { it.measure(childConstraints) }
    val layoutWidth = (placeables.maxByOrNull { it.width }?.width ?: 0) * 2
    val layoutHeight = (placeables.maxByOrNull { it.height }?.height ?: 0) * 2
    // We call layout to set the size of the current layout and to provide the positioning
    // of the children. The children are placed relative to the current layout place.
    layout(layoutWidth, layoutHeight) {
        placeables.forEach {
            it.placeRelative(layoutWidth - it.width, layoutHeight - it.height)
        }
    }
}
Layout(children = children, measureBlocks = measureBlocks)

Intrinsic measurement blocks define the intrinsic sizes of the current layout. These can be queried by the parent in order to understand, in specific cases, what constraints should the layout be measured with:

  • minIntrinsicWidthMeasureBlock defines the minimum width this layout can take, given a specific height, such that the content of the layout will be painted correctly
  • minIntrinsicHeightMeasureBlock defines the minimum height this layout can take, given a specific width, such that the content of the layout will be painted correctly
  • maxIntrinsicWidthMeasureBlock defines the minimum width such that increasing it further will not decrease the minimum intrinsic height
  • maxIntrinsicHeightMeasureBlock defines the minimum height such that increasing it further will not decrease the minimum intrinsic width

For a composable able to define its content according to the incoming constraints, see WithConstraints.

Parameters
minIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic width of the layout.
minIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The minimum intrinsic height of the layout.
maxIntrinsicWidthMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic width of the layout.
maxIntrinsicHeightMeasureBlock: IntrinsicMeasureBlock The maximum intrinsic height of the layout.
measureBlock: MeasureBlock The block defining the measurement and positioning of the layout.

onPositioned

fun onPositioned(onPositioned: (LayoutCoordinates) -> Unit): Modifier

Deprecated.

Returns modifier whose onPositioned is called with the final LayoutCoordinates of the Layout after measuring. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.ui.onPositioned

Column(Modifier.onPositioned { coordinates ->
    // This will be the size of the Column.
    coordinates.size
    // The position of the Column relative to the application window.
    coordinates.globalPosition
    // The position of the Column relative to the Compose root.
    coordinates.positionInRoot
    // These will be the alignment lines provided to the layout (empty here for Column).
    coordinates.providedAlignmentLines
    // This will a LayoutCoordinates instance corresponding to the parent of Column.
    coordinates.parentCoordinates
}) {
    Box(Modifier.preferredSize(20.dp), backgroundColor = Color.Green)
    Box(Modifier.preferredSize(20.dp), backgroundColor = Color.Blue)
}

Extension functions

composed

fun Modifier.composed(factory: Modifier.() -> Modifier): Modifier

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies. composed may be used to implement stateful modifiers that have instance-specific state for each modified element, allowing the same Modifier instance to be safely reused for multiple elements while maintaining element-specific state.

materialize must be called to create instance-specific modifiers if you are directly applying a Modifier to an element tree node.

drawBehind

fun Modifier.drawBehind(onDraw: DrawScope.() -> Unit): Modifier

Draw into a Canvas behind the modified content.

drawLayer

@Stable fun Modifier.drawLayer(
    scaleX: Float = 1f,
    scaleY: Float = 1f,
    alpha: Float = 1f,
    translationX: Float = 0f,
    translationY: Float = 0f,
    shadowElevation: Float = 0f,
    rotationX: Float = 0f,
    rotationY: Float = 0f,
    rotationZ: Float = 0f,
    transformOrigin: TransformOrigin = TransformOrigin.Center,
    shape: Shape = RectangleShape,
    clip: Boolean = false
): Modifier

Draw the content into a layer. This permits applying special effects and transformations:

import androidx.compose.foundation.Text
import androidx.compose.ui.drawLayer

Text("Hello World", Modifier.drawLayer(alpha = 0.5f, clip = true))
Parameters
scaleX: Float = 1f DrawLayerModifier.scaleX
scaleY: Float = 1f DrawLayerModifier.scaleY
alpha: Float = 1f DrawLayerModifier.alpha
shadowElevation: Float = 0f DrawLayerModifier.shadowElevation
rotationX: Float = 0f DrawLayerModifier.rotationX
rotationY: Float = 0f DrawLayerModifier.rotationY
rotationZ: Float = 0f DrawLayerModifier.rotationZ
shape: Shape = RectangleShape DrawLayerModifier.shape
clip: Boolean = false DrawLayerModifier.clip

drawWithContent

fun Modifier.drawWithContent(onDraw: ContentDrawScope.() -> Unit): Modifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents. It also allows the modifier to adjust the layout's canvas.

focus

@Composable fun Modifier.focus(): Modifier

Add this modifier to a component to make it focusable.

focusObserver

fun Modifier.focusObserver(onFocusChange: (FocusState) -> Unit): Modifier

Add this modifier to a component to observe focus state changes.

focusRequester

fun Modifier.focusRequester(focusRequester: FocusRequester): Modifier

Add this modifier to a component to observe changes to focus state.

layout

fun Modifier.layout(measure: MeasureScope.(Measurable, Constraints) -> MeasureScope.MeasureResult): Modifier

Creates a LayoutModifier that allows changing how the wrapped element is measured and laid out.

This is a convenience API of creating a custom LayoutModifier modifier, without having to create a class or an object that implements the LayoutModifier interface. The intrinsic measurements follow the default logic provided by the LayoutModifier.

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Stack
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.layout
import androidx.compose.ui.unit.offset

Stack(
    modifier = Modifier
        .background(Color.Gray)
        .layout { measurable, constraints ->
        // an example modifier that adds 50 pixels of vertical padding
        val padding = 50
        val placeable = measurable.measure(constraints.offset(vertical = -padding))
        this.layout(placeable.width, placeable.height + padding) {
            placeable.placeRelative(0, padding)
        }
    }
) {
    Stack(Modifier.fillMaxSize().background(Color.DarkGray)) {}
}

materialize

fun Composer<*>.materialize(modifier: Modifier): Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node. Call right before setting the returned modifier on an emitted node. You almost certainly do not need to call this function directly.

merge

fun AlignmentLine.merge(
    position1: Int,
    position2: Int
): Int

Merges two values of the current alignment line.

onPositioned

fun Modifier.onPositioned(onPositioned: (LayoutCoordinates) -> Unit): Modifier

Invoke onPositioned with the LayoutCoordinates of the element after positioning. Note that it will be called after a composition when the coordinates are finalized.

Usage example:

import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.ui.onPositioned

Column(Modifier.onPositioned { coordinates ->
    // This will be the size of the Column.
    coordinates.size
    // The position of the Column relative to the application window.
    coordinates.globalPosition
    // The position of the Column relative to the Compose root.
    coordinates.positionInRoot
    // These will be the alignment lines provided to the layout (empty here for Column).
    coordinates.providedAlignmentLines
    // This will a LayoutCoordinates instance corresponding to the parent of Column.
    coordinates.parentCoordinates
}) {
    Box(Modifier.preferredSize(20.dp), backgroundColor = Color.Green)
    Box(Modifier.preferredSize(20.dp), backgroundColor = Color.Blue)
}

zIndex

@Stable fun Modifier.zIndex(zIndex: Float): Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent. A child with larger zIndex will be drawn after all the children with smaller zIndex. When children have the same zIndex the original order in which the items were added into the parent layout is applied. Note that if there would be multiple ZIndexModifier modifiers applied for the same layout only the first one in the modifiers chain will be used. If no ZIndexModifiers applied for the layout then zIndex for this Layout is 0.

import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Stack
import androidx.compose.ui.zIndex

Stack {
    Text("Drawn second", Modifier.zIndex(1f))
    Text("Drawn first")
}