offset

Compose Modifier

Common
fun Modifier.offset(x: Dp = 0.dp, y: Dp = 0.dp) =
    this then
        OffsetElement(
            x = x,
            y = y,
            rtlAware = true,
            inspectorInfo = {
                name = "offset"
                properties["x"] = x
                properties["y"] = y
            },
        )

Offset the content by (x dp, y dp). The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.

This modifier will automatically adjust the horizontal offset according to the layout direction: when the layout direction is LTR, positive x offsets will move the content to the right and when the layout direction is RTL, positive x offsets will move the content to the left. For a modifier that offsets without considering layout direction, see absoluteOffset.

Common
fun Modifier.offset(offset: Density.() -> IntOffset) =
    this then
        OffsetPxElement(
            offset = offset,
            rtlAware = true,
            inspectorInfo = {
                name = "offset"
                properties["offset"] = offset
            },
        )

Offset the content by offset px. The offsets can be positive as well as non-positive. Applying an offset only changes the position of the content, without interfering with its size measurement.

This modifier is designed to be used for offsets that change, possibly due to user interactions. It avoids recomposition when the offset is changing, and also adds a graphics layer that prevents unnecessary redrawing of the context when the offset is changing.

This modifier will automatically adjust the horizontal offset according to the layout direction: when the LD is LTR, positive horizontal offsets will move the content to the right and when the LD is RTL, positive horizontal offsets will move the content to the left. For a modifier that offsets without considering layout direction, see absoluteOffset.