RectRulers

Interface

Common
interface RectRulers

A collection of Rulers used to define a Rectangle.

Properties

Common
val left: VerticalRuler

The left position of the rectangle.

Common
val top: HorizontalRuler

The top position of the rectangle.

Common
val right: VerticalRuler

The right position of the rectangle

Common
val bottom: HorizontalRuler

The bottom position of the rectangle

Code Examples

WindowInsetsRulersSample

@Composable
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) }
            }
        },
    )
}