Interface

RectRulers

A collection of Rulers used to define a Rectangle.

WindowInsetsRulersSample

@Composable
@Sampled
fun WindowInsetsRulersSample() {
    Layout(
        modifier = Modifier.fillMaxSize(),
        content = {
            Box(Modifier.background(Color.Blue)) // top area (e.g. status bar)
            Box(Modifier.background(Color.Yellow)) // bottom area (e.g. navigation bar)
            Box(Modifier.background(Color.White)) // content between top and bottom
        },
        measurePolicy = { measurables, constraints ->
            if (constraints.hasBoundedWidth && constraints.hasBoundedHeight) {
                val width = constraints.maxWidth
                val height = constraints.maxHeight
                layout(width, height) {
                    val top =
                        maxOf(0, WindowInsetsRulers.SystemBars.current.top.current(0f).roundToInt())
                    val topArea = measurables[0].measure(Constraints.fixed(width, top))
                    topArea.place(0, 0)

                    val bottom =
                        minOf(
                            height,
                            WindowInsetsRulers.SystemBars.current.bottom.current(0f).roundToInt(),
                        )
                    val bottomArea =
                        measurables[1].measure(Constraints.fixed(width, height - bottom))
                    bottomArea.place(0, bottom)

                    val contentArea = measurables[2].measure(Constraints.fixed(width, bottom - top))
                    contentArea.place(0, top)
                }
            } else {
                // It should only get here if inside scrollable content or trying to align
                // to an alignment line. Only place the content.
                val placeable = measurables[2].measure(constraints) // content
                layout(placeable.width, placeable.height) { placeable.place(0, 0) }
            }
        },
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: