Composable Function

SubspaceLayout

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

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free

SubspaceLayoutWithContentSample

/**
 * 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.
 */
@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) }
        }
    }
}

SubspaceLayoutWithCoreEntityNameSample

/**
 * 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.
 */
@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) }
                }
            },
    )
}

SubspaceLayoutWithoutContentSample

/**
 * 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.
 */
@Composable
@SubspaceComposable
fun SubspaceLayoutWithoutContentSample(size: IntVolumeSize) {
    SubspaceLayout(
        modifier = SubspaceModifier.testTag("exactSizeSpacer"),
        measurePolicy =
            SubspaceMeasurePolicy { _, _ -> layout(size.width, size.height, size.depth) {} },
    )
}