Buttons initiate actions based on user interaction. The Meta Horizon OS UI Set provides several button variants and types to cover common use cases in spatial interfaces. All buttons support standard interaction states (default, hover, pressed, disabled) and utilize the SpatialTheme for styling.
Common features
Interaction feedback: Provide visual feedback on hover and press (slight background change, scaling).
Theming: Colors, shapes, and typography are derived from SpatialTheme.
Accessibility: Designed with minimum target sizes in mind (though exact hit target implementation depends on Compose behavior).
isEnabled parameter: Controls interactability and visual state.
Button variants
These define the primary visual style and semantic meaning.
These components use the underlying button variants but arrange content differently.
Text tile button
Composable: TextTileButton
Usage: Often used in grids or lists for selectable items, representing entities like files, apps, or options. Has a distinct selected state.
Layout: Stacked layout, can contain an icon, primary label, and optional secondary label.
State: Uses selected: Boolean and onSelectionChange: (Boolean) -> Unit props. Background and foreground colors change based on selection state (using TextTileButtonDefaults).
import com.meta.spatial.uiset.button.TextTileButton
// ... other imports
var isSelected by remember { mutableStateOf(false) }
TextTileButton(
label = "Document Title",
secondaryLabel = "Edited 2 hours ago",
icon = { Icon(SpatialIcons.Regular.Document, null) },
selected = isSelected,
onSelectionChange = { isSelected = it } // Often !isSelected
)
Button shelf
Composable: ButtonShelf
Usage: Typically used in horizontal rows (like a “shelf”) for quick actions or toggles, often in system UIs or toolbars.
Layout: Stacked icon-over-label layout within a fixed size.
State: Uses selected: Boolean and onSelectionChange: (Boolean) -> Unit props. Background and foreground colors change based on selection state (using ButtonShelfDefaults).
import com.meta.spatial.uiset.button.ButtonShelf
// ... other imports
var isMicOn by remember { mutableStateOf(false) }
ButtonShelf(
label = "Microphone",
icon = { Icon(SpatialIcons.Regular.MicrophoneOn, null) }, // Icon might change based on state too
selected = isMicOn,
onSelectionChange = { isMicOn = it }
)
Common parameters
onClick: () -> Unit: Lambda executed when the button is clicked (for non-selectable buttons).
onSelectionChange: (Boolean) -> Unit: Lambda executed when a selectable button’s state changes.
label: String: The primary text displayed.
leading: @Composable (() -> Unit)?: Composable for an icon placed before the label (for standard button variants).
icon: @Composable (() -> Unit): Composable for the icon (required for icon buttons, ButtonShelf, optional for TextTileButton).
secondaryLabel: String?: Optional secondary text (for TextTileButton).