WindowInsetsRulers.Companion


Summary

Public functions

WindowInsetsRulers
innermostOf(vararg windowInsetsRulers: WindowInsetsRulers)

Merges the rulers in windowInsetsRulers, providing the innermost values from current and maximum.

Cmn

Public properties

WindowInsetsRulers

Rulers used for caption bar insets.

Cmn
WindowInsetsRulers

Rulers used for display cutout insets.

Cmn
WindowInsetsRulers

Rulers used for IME insets.

Cmn
WindowInsetsRulers

Rulers used for mandatory system gestures insets.

Cmn
WindowInsetsRulers

Rulers used for navigation bars insets.

Cmn
WindowInsetsRulers

Rulers used for insets that are safe for any content.

Cmn
WindowInsetsRulers

Rulers used for insets including system bars, IME, and the display cutout.

Cmn
WindowInsetsRulers

Rulers used for insets that include places where gestures could conflict.

Cmn
WindowInsetsRulers

Rulers used for status bars insets.

Cmn
WindowInsetsRulers

Rulers used for system bars insets, including StatusBars, NavigationBars, and CaptionBar.

Cmn
WindowInsetsRulers

Rulers used for system gestures insets.

Cmn
WindowInsetsRulers

Rulers used for tappable elements insets.

Cmn
WindowInsetsRulers

Rulers used for waterfall insets.

Cmn

Public functions

innermostOf

fun innermostOf(vararg windowInsetsRulers: WindowInsetsRulers): WindowInsetsRulers

Merges the rulers in windowInsetsRulers, providing the innermost values from current and maximum. getAnimation will return values with only WindowInsetsAnimation.isVisible and WindowInsetsAnimation.isAnimating set to meaningful values.

Public properties

CaptionBar

val CaptionBarWindowInsetsRulers

Rulers used for caption bar insets.

See WindowInsetsCompat.Type.captionBar

DisplayCutout

val DisplayCutoutWindowInsetsRulers

Rulers used for display cutout insets.

This is the safe insets that avoid all display cutouts. To get the bounds of the display cutouts themselves, use Placeable.PlacementScope.getDisplayCutoutBounds.

See WindowInsetsCompat.Type.displayCutout

Ime

val ImeWindowInsetsRulers

Rulers used for IME insets.

See WindowInsetsCompat.Type.ime

MandatorySystemGestures

val MandatorySystemGesturesWindowInsetsRulers

Rulers used for mandatory system gestures insets.

See WindowInsetsCompat.Type.mandatorySystemGestures

val NavigationBarsWindowInsetsRulers

Rulers used for navigation bars insets.

See WindowInsetsCompat.Type.navigationBars

SafeContent

val SafeContentWindowInsetsRulers

Rulers used for insets that are safe for any content. This includes SafeGestures and SafeDrawing.

SafeDrawing

val SafeDrawingWindowInsetsRulers

Rulers used for insets including system bars, IME, and the display cutout.

SafeGestures

val SafeGesturesWindowInsetsRulers

Rulers used for insets that include places where gestures could conflict. This includes MandatorySystemGestures, SystemGestures, TappableElement, and Waterfall.

StatusBars

val StatusBarsWindowInsetsRulers

Rulers used for status bars insets.

See WindowInsetsCompat.Type.statusBars

SystemBars

val SystemBarsWindowInsetsRulers

Rulers used for system bars insets, including StatusBars, NavigationBars, and CaptionBar.

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.Layout
import androidx.compose.ui.layout.WindowInsetsRulers
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, 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) }
        }
    },
)

See WindowInsetsCompat.Type.systemBars

SystemGestures

val SystemGesturesWindowInsetsRulers

Rulers used for system gestures insets.

See WindowInsetsCompat.Type.systemGestures

TappableElement

val TappableElementWindowInsetsRulers

Rulers used for tappable elements insets.

See WindowInsetsCompat.Type.tappableElement

Waterfall

val WaterfallWindowInsetsRulers

Rulers used for waterfall insets.

See DisplayCutoutCompat.getWaterfallInsets

Extension functions

WindowInsetsRulers.Companion.disable

fun WindowInsetsRulers.Companion.disable(): Unit

Used to disable androidx.compose.ui.layout.WindowInsetsRulers. This can be used when UI never reads WindowInsets across all Compose roots to reduce the overhead of requesting WindowInsets updates. Only call this when no Compose roots will ever need to handle insets over the lifetime of the application. This should be called before the first Compose root is created.