Class

AlignmentLine

Defines an offset line that can be used by parent layouts to align and position their children.

AlignmentLineSample

@Composable
fun AlignmentLineSample() {
    // Create a horizontal alignment line. Note it is not common for alignment lines to be created
    // in the scope of one composable, since they are usually used across more than one function.
    // We use ::min as merging strategy, which means that the parent will have the minimum of
    // the values of the alignment line, when this is inherited from more than one child.
    val exampleLine = remember { HorizontalAlignmentLine(::min) }
    // A layout with a fixed size, and a given position for the exampleLine alignment line.
    @Composable
    fun LineProviderLayout(exampleLinePosition: Int) {
        val size: Int = 20
        Layout({}) { _, _ -> layout(size, size, mapOf(exampleLine to exampleLinePosition)) {} }
    }
    Layout({
        LineProviderLayout(exampleLinePosition = 5)
        LineProviderLayout(exampleLinePosition = 10)
    }) { measurables, constraints ->
        val placeables = measurables.map { it.measure(constraints) }
        // placeables[0][line] will be 5
        // placeables[1][line] will be 10
        layout(constraints.maxWidth, constraints.maxHeight) {
            placeables[0].place(0, 3)
            placeables[1].place(constraints.maxWidth / 2, 0)
        }
    }
    // Note that if the parent of this Layout (the parent of AlignmentLineSample) was able to
    // query its position of exampleLine (assuming this was in a shared scope), its position would
    // be 8. This is because the Layout positioned its first child at 3 from the top,
    // and because of the ::min merging strategy the position of exampleLine will be
    // min(5 + 3, 10 + 0).
}