WindowInsetsRulers


Contains rulers used for window insets. The current values are available as well as values when the insets are fully visible.

Other animation properties can be retrieved with getAnimation.

Summary

Public companion functions

WindowInsetsRulers
innermostOf(vararg windowInsetsRulers: WindowInsetsRulers)

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

Cmn

Public companion 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

WindowInsetsAnimation

Additional properties related to animating this WindowInsetsRulers.

Cmn

Public properties

RectRulers

The current values for the window insets RectRulers.

Cmn
RectRulers

The values for the insets when the insets are fully visible.

Cmn

Public companion 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 companion 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

Public functions

getAnimation

fun getAnimation(scope: Placeable.PlacementScope): WindowInsetsAnimation

Additional properties related to animating this WindowInsetsRulers.

Public properties

current

val currentRectRulers

The current values for the window insets RectRulers. Values for some insets may not be provided on platforms that don't support specific Window Insets types.

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

maximum

val maximumRectRulers

The values for the insets when the insets are fully visible. The value does not change when the insets are hidden. Values for some insets may not be provided on some platforms. For example, values are never provided for Ime on Android.

When no animations are active, maximum and current will have the same value if WindowInsetsAnimation.isVisible is true. If false, then maximum will not be changed, while current will have values the same as the Window borders. For example, when a status bar is visible, its height may be intrude 100 pixels into the Window and maximum's top will be at 100 pixels for StatusBars. When the status bar is invisible, maximum will have the same top value at 100 pixels, while current's top will be at 0 pixels.

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

// When the status bar is visible, don't show the content that would be in the status area.
// When the status bar is hidden, show content that would be in the status area.
Layout(
    modifier = Modifier.fillMaxSize(),
    content = {
        Box(Modifier.background(Color.Blue)) // status bar area content
        Box(Modifier.background(Color.Yellow)) // normal content
    },
    measurePolicy = { measurables, constraints ->
        val width = constraints.maxWidth
        val height = constraints.maxHeight
        layout(width, height) {
            val top = WindowInsetsRulers.StatusBars.maximum.top.current(0f).roundToInt()
            val statusBarAnimationProperties = WindowInsetsRulers.StatusBars.getAnimation(this)
            if (!statusBarAnimationProperties.isVisible) {
                // Only place the status bar content when the status bar isn't visible. We don't
                // want it cluttering the status bar area when the status bar is shown.
                measurables[0].measure(Constraints.fixed(width, top)).place(0, 0)
            }
            // Place the normal content below where the status bar would be.
            measurables[1].measure(Constraints.fixed(width, height - top)).place(0, top)
        }
    },
)