RectRulers

Known direct subclasses
BasicAnimatableInsetsRulers

Rulers for Window Insets that can be animated and includes the source and target values for the rulers as well as when the rulers are animating.

DisplayCutoutInsetsRulers

Rulers for the display cutout.

Known indirect subclasses
AnimatableInsetsRulers

Rulers for Window Insets that can be animated.

InnerInsetsRulers

A BasicAnimatableInsetsRulers for merging WindowInsets RectRulers.


A collection of Rulers used to define a Rectangle.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.InsetsRulers
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Constraints

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, InsetsRulers.SystemBars.top.current(0f).roundToInt())
                val topArea = measurables[0].measure(Constraints.fixed(width, top))
                topArea.place(0, 0)

                val bottom =
                    minOf(height, InsetsRulers.SystemBars.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) }
        }
    }
)

Summary

Nested types

Public properties

HorizontalRuler

The bottom position of the rectangle

Cmn
VerticalRuler

The left position of the rectangle.

Cmn
VerticalRuler

The right position of the rectangle

Cmn
HorizontalRuler

The top position of the rectangle.

Cmn

Public properties

bottom

val bottomHorizontalRuler

The bottom position of the rectangle

left

val leftVerticalRuler

The left position of the rectangle.

right

val rightVerticalRuler

The right position of the rectangle

top

val topHorizontalRuler

The top position of the rectangle.