HorizontalRuler


A horizontal Ruler. Defines a line that can be used by parent layouts to align or position their children vertically. The position of the ruler can be retrieved with Placeable.PlacementScope.current and can be set with MeasureScope.layout using RulerScope.provides.

Summary

Public companion functions

HorizontalRuler
derived(calculation: Placeable.PlacementScope.(defaultValue: Float) -> Float)

Creates a HorizontalRuler whose values are derived from values available in the PlacementScope, such as other HorizontalRulers.

Cmn
HorizontalRuler
maxOf(vararg rulers: HorizontalRuler)

Creates a HorizontalRuler derived from the greater value of all HorizontalRulers in rulers that supply a value.

Cmn
HorizontalRuler
minOf(vararg rulers: HorizontalRuler)

Creates a HorizontalRuler derived from the least value of all HorizontalRulers in rulers that supply a value.

Cmn

Public constructors

Creates a HorizontalRuler whose values are directly provided.

Cmn

Public companion functions

derived

fun derived(calculation: Placeable.PlacementScope.(defaultValue: Float) -> Float): HorizontalRuler

Creates a HorizontalRuler whose values are derived from values available in the PlacementScope, such as other HorizontalRulers.

import androidx.compose.ui.layout.HorizontalRuler
import androidx.compose.ui.unit.Dp

class PaddedRulers(val ruler: HorizontalRuler, val padding: Dp) {
    val top =
        HorizontalRuler.derived { defaultValue ->
            val rulerValue = ruler.current(Float.NaN)
            if (rulerValue.isNaN()) {
                defaultValue
            } else {
                rulerValue + padding.toPx()
            }
        }
    val bottom =
        HorizontalRuler.derived { defaultValue ->
            val rulerValue = ruler.current(Float.NaN)
            if (rulerValue.isNaN()) {
                defaultValue
            } else {
                rulerValue - padding.toPx()
            }
        }
}
Parameters
calculation: Placeable.PlacementScope.(defaultValue: Float) -> Float

A function that calculates the value of the ruler

See also
minOf
maxOf

maxOf

fun maxOf(vararg rulers: HorizontalRuler): HorizontalRuler

Creates a HorizontalRuler derived from the greater value of all HorizontalRulers in rulers that supply a value. This is the right-most of all provided ruler values.

minOf

fun minOf(vararg rulers: HorizontalRuler): HorizontalRuler

Creates a HorizontalRuler derived from the least value of all HorizontalRulers in rulers that supply a value. This is the left-most of all provided ruler values.

Public constructors

HorizontalRuler

HorizontalRuler()

Creates a HorizontalRuler whose values are directly provided. The developer can set the ruler value in MeasureScope.layout using RulerScope.provides or RulerScope.providesRelative.