New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Ui

layout

Common

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].

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.7.0-beta04")
}

Overloads


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

Code Example

ConvenienceLayoutModifierSample

@Composable
@Sampled
fun ConvenienceLayoutModifierSample() {
    Box(
        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))
                layout(placeable.width, placeable.height + padding) {
                    placeable.placeRelative(0, padding)
                }
            }
    ) {
        Box(Modifier.fillMaxSize().background(Color.DarkGray))
    }
}