Composable Function

SubspaceLayout

SubspaceLayout is the main component for laying out leaf nodes with zero children.

SubspaceLayoutWithoutContentSample

/** A data class representing a 3D size with integer dimensions. */
data class IntVolumeSize(val width: Int, val height: Int, val depth: Int)

/**
 * This sample demonstrates a [SubspaceLayout] with no content, which can be used as a spacer or a
 * placeholder in a 3D layout. It is the equivalent of a `Box` in traditional Compose.
 *
 * @param size The size of the spacer.
 */
@Sampled
@Composable
@SubspaceComposable
fun SubspaceLayoutWithoutContentSample(size: IntVolumeSize) {
    SubspaceLayout(
        modifier = SubspaceModifier.testTag("exactSizeSpacer"),
        measurePolicy =
            SubspaceMeasurePolicy { _, _ -> layout(size.width, size.height, size.depth) {} },
    )
}

/**
 * This sample demonstrates a [SubspaceLayout] with content. The content is measured and placed
 * according to the provided measure policy. In this case, it places all children at the origin.
 *
 * @param modifier The modifier to be applied to the layout.
 * @param content The composable content to be laid out.
 */

SubspaceLayoutWithContentSample

@Sampled
@Composable
@SubspaceComposable
fun SubspaceLayoutWithContentSample(
    modifier: SubspaceModifier = SubspaceModifier,
    content: @SubspaceComposable @Composable () -> Unit,
) {
    SubspaceLayout(content = content, modifier = modifier) { measurables, constraints ->
        val placeables = measurables.map { it.measure(constraints) }
        layout(constraints.maxWidth, constraints.maxHeight, constraints.maxDepth) {
            placeables.forEach { it.place(Pose.Identity) }
        }
    }
}

/**
 * This sample demonstrates how to provide a `coreEntityName` to a [SubspaceLayout]. This name is
 * used for debugging and identification purposes in the 3D scene graph.
 *
 * @param modifier The modifier to be applied to the layout.
 * @param content The composable content to be laid out.
 */

SubspaceLayoutWithCoreEntityNameSample

@Sampled
@Composable
@SubspaceComposable
fun SubspaceLayoutWithCoreEntityNameSample(
    modifier: SubspaceModifier = SubspaceModifier,
    content: @SubspaceComposable @Composable () -> Unit,
) {
    SubspaceLayout(
        content = content,
        modifier = modifier,
        coreEntityName = "MyCustomLayoutEntity",
        measurePolicy =
            SubspaceMeasurePolicy { measurables, constraints ->
                val placeables = measurables.map { it.measure(constraints) }
                layout(constraints.maxWidth, constraints.maxHeight, constraints.maxDepth) {
                    placeables.forEach { it.place(Pose.Identity) }
                }
            },
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: