When the resizable modifier is present and enabled, draggable UI controls will be shown that allow the user to resize the element in 3D space.
ResizableWithStateSample
/**
* A sample demonstrating a resizable component where the developer manages the state and applies
* the resulting size.
*/
@SubspaceComposable
@Composable
public fun ResizableWithStateSample() {
val density = LocalDensity.current
var panelWidth by remember { mutableStateOf(400.dp) }
var panelHeight by remember { mutableStateOf(300.dp) }
SpatialPanel(
modifier =
SubspaceModifier.width(panelWidth)
.height(panelHeight)
.resizable(
onResize = { event ->
// The developer decides when and how to apply the new size.
// In this example, we update our state when the resize interaction ends.
if (event.type == SpatialResizeEventType.End) {
with(density) {
panelWidth = event.size.width.toDp()
panelHeight = event.size.height.toDp()
}
}
}
)
) {
Text("Resizable with size state.")
}
}