LayoutCoordinates


A holder of the measured bounds for the Layout.

Summary

Public functions

operator Int
get(alignmentLine: AlignmentLine)

Returns the position in pixels of an alignment line, or AlignmentLine.Unspecified if the line is not provided.

Cmn
Rect
localBoundingBoxOf(
    sourceCoordinates: LayoutCoordinates,
    clipBounds: Boolean
)

Returns the bounding box of sourceCoordinates in the local coordinates.

Cmn
Offset
localPositionOf(
    sourceCoordinates: LayoutCoordinates,
    relativeToSource: Offset
)

Converts an relativeToSource in sourceCoordinates space into local coordinates.

Cmn
open Offset
localPositionOf(
    sourceCoordinates: LayoutCoordinates,
    relativeToSource: Offset,
    includeMotionFrameOfReference: Boolean
)

Converts an relativeToSource in sourceCoordinates space into local coordinates.

Cmn
Offset
localToRoot(relativeToLocal: Offset)

Converts a local position within this layout into an offset from the root composable.

Cmn
open Offset
localToScreen(relativeToLocal: Offset)

Converts relativeToLocal position within this layout into an Offset relative to the device's screen.

Cmn
Offset
localToWindow(relativeToLocal: Offset)

Converts relativeToLocal position within this layout into an Offset relative to the window's origin.

Cmn
open Offset
screenToLocal(relativeToScreen: Offset)

Converts relativeToScreen relative to the device's screen's origin into an Offset relative to this layout.

Cmn
open Unit
transformFrom(sourceCoordinates: LayoutCoordinates, matrix: Matrix)

Modifies matrix to be a transform to convert a coordinate in sourceCoordinates to a coordinate in this LayoutCoordinates.

Cmn
open Unit

Takes a matrix which transforms some coordinate system C to local coordinates, and updates the matrix to transform from C to screen coordinates instead.

Cmn
Offset
windowToLocal(relativeToWindow: Offset)

Converts relativeToWindow relative to the window's origin into an Offset relative to this layout.

Cmn

Public properties

open Boolean

Indicates whether the corresponding Layout is expected to change its Offset in small increments (such as when its parent is a Scroll).

Cmn
Boolean

Returns false if the corresponding layout was detached from the hierarchy.

Cmn
LayoutCoordinates?

The coordinates of the parent layout modifier or parent layout if there is no parent layout modifier, or null if there is no parent.

Cmn
LayoutCoordinates?

The coordinates of the parent layout.

Cmn
Set<AlignmentLine>

The alignment lines provided for this layout, not including inherited lines.

Cmn
IntSize

The size of this layout in the local coordinates space.

Cmn

Extension functions

Rect

Returns the bounding box of the child in the parent's content area, including any clipping done with respect to the parent.

Cmn
Rect

The boundaries of this layout inside the root composable.

Cmn
Rect

The boundaries of this layout relative to the window's origin.

Cmn
LayoutCoordinates

Walks up the LayoutCoordinates hierarchy to find the LayoutCoordinates whose LayoutCoordinates.parentCoordinates is null and returns it.

Cmn
Offset

Returns the position of the top-left in the parent's content area or (0, 0) for the root.

Cmn
Offset

The position of this layout inside the root composable.

Cmn
Offset

The position of this layout relative to the window.

Cmn
Offset

The position of this layout on the device's screen.

Cmn

Public functions

get

operator fun get(alignmentLine: AlignmentLine): Int

Returns the position in pixels of an alignment line, or AlignmentLine.Unspecified if the line is not provided.

localBoundingBoxOf

fun localBoundingBoxOf(
    sourceCoordinates: LayoutCoordinates,
    clipBounds: Boolean = true
): Rect

Returns the bounding box of sourceCoordinates in the local coordinates. If clipBounds is true, any clipping that occurs between sourceCoordinates and this layout will affect the returned bounds, and can even result in an empty rectangle if clipped regions do not overlap. If clipBounds is false, the bounding box of sourceCoordinates will be converted to local coordinates irrespective of any clipping applied between the layouts.

When rotation or scaling is applied, the bounding box of the rotated or scaled value will be computed in the local coordinates. For example, if a 40 pixels x 20 pixel layout is rotated 90 degrees, the bounding box will be 20 pixels x 40 pixels in its parent's coordinates.

localPositionOf

fun localPositionOf(
    sourceCoordinates: LayoutCoordinates,
    relativeToSource: Offset
): Offset

Converts an relativeToSource in sourceCoordinates space into local coordinates. sourceCoordinates may be any LayoutCoordinates that belong to the same compose layout hierarchy.

By default, includes the Offset when introducesMotionFrameOfReference is true. But you may exclude it from the calculation by using the overload that takes includeMotionFrameOfReference and passing it as false.

localPositionOf

open fun localPositionOf(
    sourceCoordinates: LayoutCoordinates,
    relativeToSource: Offset = Offset.Zero,
    includeMotionFrameOfReference: Boolean = true
): Offset

Converts an relativeToSource in sourceCoordinates space into local coordinates. sourceCoordinates may be any LayoutCoordinates that belong to the same compose layout hierarchy.

Use includeMotionFrameOfReference to decide whether to include the Offset of any LayoutCoordinate that returns true in the includeMotionFrameOfReference flag.

In other words, passing includeMotionFrameOfReference as false, returns a calculation that excludes the Offset set from Layouts that place their children using Placeable.PlacementScope.withMotionFrameOfReferencePlacement.

localToRoot

fun localToRoot(relativeToLocal: Offset): Offset

Converts a local position within this layout into an offset from the root composable.

localToScreen

open fun localToScreen(relativeToLocal: Offset): Offset

Converts relativeToLocal position within this layout into an Offset relative to the device's screen. Returns Offset.Unspecified if the conversion cannot be performed.

localToWindow

fun localToWindow(relativeToLocal: Offset): Offset

Converts relativeToLocal position within this layout into an Offset relative to the window's origin.

screenToLocal

open fun screenToLocal(relativeToScreen: Offset): Offset

Converts relativeToScreen relative to the device's screen's origin into an Offset relative to this layout. Returns Offset.Unspecified if the conversion cannot be performed.

transformFrom

open fun transformFrom(sourceCoordinates: LayoutCoordinates, matrix: Matrix): Unit

Modifies matrix to be a transform to convert a coordinate in sourceCoordinates to a coordinate in this LayoutCoordinates.

transformToScreen

open fun transformToScreen(matrix: Matrix): Unit

Takes a matrix which transforms some coordinate system C to local coordinates, and updates the matrix to transform from C to screen coordinates instead.

windowToLocal

fun windowToLocal(relativeToWindow: Offset): Offset

Converts relativeToWindow relative to the window's origin into an Offset relative to this layout.

Public properties

introducesMotionFrameOfReference

open val introducesMotionFrameOfReferenceBoolean

Indicates whether the corresponding Layout is expected to change its Offset in small increments (such as when its parent is a Scroll).

In those situations, the corresponding placed LayoutCoordinates will have their introducesMotionFrameOfReference return true.

Custom Layouts that are expected to have similar behaviors should place their children using Placeable.PlacementScope.withMotionFrameOfReferencePlacement.

You may then use localPositionOf with includeMotionFrameOfReference = false to query a Layout's position such that it excludes all Offset introduced by those Layouts.

This is typically helpful when deciding when to animate an approachLayout using LookaheadScope coordinates. As you probably don't want to trigger animations on small positional increments.

isAttached

val isAttachedBoolean

Returns false if the corresponding layout was detached from the hierarchy.

parentCoordinates

val parentCoordinatesLayoutCoordinates?

The coordinates of the parent layout modifier or parent layout if there is no parent layout modifier, or null if there is no parent.

parentLayoutCoordinates

val parentLayoutCoordinatesLayoutCoordinates?

The coordinates of the parent layout. Null if there is no parent.

providedAlignmentLines

val providedAlignmentLinesSet<AlignmentLine>

The alignment lines provided for this layout, not including inherited lines.

size

val sizeIntSize

The size of this layout in the local coordinates space.

Extension functions

boundsInParent

fun LayoutCoordinates.boundsInParent(): Rect

Returns the bounding box of the child in the parent's content area, including any clipping done with respect to the parent. For the root, the bounds is positioned at (0, 0) and sized to the size of the root.

boundsInRoot

fun LayoutCoordinates.boundsInRoot(): Rect

The boundaries of this layout inside the root composable.

boundsInWindow

fun LayoutCoordinates.boundsInWindow(): Rect

The boundaries of this layout relative to the window's origin.

findRootCoordinates

fun LayoutCoordinates.findRootCoordinates(): LayoutCoordinates

Walks up the LayoutCoordinates hierarchy to find the LayoutCoordinates whose LayoutCoordinates.parentCoordinates is null and returns it. If LayoutCoordinates.isAttached, this will have the size of the androidx.compose.ui.platform.ComposeView.

positionInParent

fun LayoutCoordinates.positionInParent(): Offset

Returns the position of the top-left in the parent's content area or (0, 0) for the root.

positionInRoot

fun LayoutCoordinates.positionInRoot(): Offset

The position of this layout inside the root composable.

positionInWindow

fun LayoutCoordinates.positionInWindow(): Offset

The position of this layout relative to the window.

positionOnScreen

fun LayoutCoordinates.positionOnScreen(): Offset

The position of this layout on the device's screen. Returns Offset.Unspecified if the conversion cannot be performed.