// Define reusable building blocks as extension functions on FlexBoxScope.
fun FlexBoxScope.header(title: String) {
text(title, style = TextStyle.HEADING)
}
fun FlexBoxScope.mediaRow(iconName: String, label: String) {
flexBox(direction = Direction.ROW, gap = 8, crossAlignment = Alignment.CENTER) {
icon(name = iconName, style = IconStyle.FILLED)
text(label, style = TextStyle.BODY)
}
}
// Compose them inside any flexBox { } block.
display.sendContent {
flexBox(direction = Direction.COLUMN, gap = 8) {
header("Now Playing")
mediaRow("headphones", "My Song")
button(label = "Stop", style = ButtonStyle.SECONDARY)
}
}
class FlexBoxScope
button
(
label
, style
, iconName
, onClick
, flexGrow
, flexShrink
, alignSelf
)
|
Adds a button component as a child.
Displays a tappable button on the wearable display. Buttons can optionally include an icon alongside the label and respond to tap events via onClick.
Signature
fun button(label: String, style: ButtonStyle = ButtonStyle.PRIMARY, iconName: IconName? = null, onClick: () -> Unit? = null, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null) Parameters label: String
The button text.
onClick: Function0?
Optional callback invoked when the button is tapped on the wearable.
flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0.
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
|
buttonGroup
(
alignment
, flexGrow
, flexShrink
, alignSelf
, block
)
|
Adds a button group as a child.
A button group arranges its ButtonGroupScope.buttons horizontally and, on smartglass, keeps each unfocused icon button collapsed to its icon while widening the focused one to reveal its label. Prefer this over a FlexBoxScope.flexBox row of buttons when you want that focus-driven reveal.
Signature
fun buttonGroup(alignment: ButtonGroupAlignment = ButtonGroupAlignment.CENTER, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null, block: ButtonGroupScope.() -> Unit) Parameters alignment: ButtonGroupAlignment
How the buttons are positioned within the group. Defaults to ButtonGroupAlignment.CENTER.
flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0.
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
block: Function1
Builder block for adding buttons to the group.
|
flexBox
(
direction
, gap
, alignment
, crossAlignment
, wrap
, padding
, paddingTop
, paddingBottom
, paddingStart
, paddingEnd
, background
, onClick
, flexGrow
, flexShrink
, alignSelf
, block
)
|
Adds a nested FlexBox layout as a child.
Creates a flexible layout within the current FlexBox. Individual padding params override the uniform padding value when set.
Signature
fun flexBox(direction: Direction = Direction.COLUMN, gap: Int = 0, alignment: Alignment = Alignment.START, crossAlignment: Alignment = Alignment.START, wrap: Boolean = false, padding: Int = 0, paddingTop: Int? = null, paddingBottom: Int? = null, paddingStart: Int? = null, paddingEnd: Int? = null, background: FlexBoxBackground = FlexBoxBackground.NONE, onClick: () -> Unit? = null, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null, block: FlexBoxScope.() -> Unit) Parameters gap: Int
Spacing in pixels between children. Defaults to 0.
wrap: Boolean
Whether children should wrap to the next line when they exceed the available space.
padding: Int
Uniform padding in pixels applied to all sides. Defaults to 0.
paddingTop: Int?
Padding for the top edge. Overrides padding when set.
paddingBottom: Int?
Padding for the bottom edge. Overrides padding when set.
paddingStart: Int?
Padding for the start edge. Overrides padding when set.
paddingEnd: Int?
Padding for the end edge. Overrides padding when set.
onClick: Function0?
Optional callback invoked when this FlexBox is tapped on the wearable.
flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0 (no growth).
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
block: Function1
Builder block for adding child components.
|
icon
(
name
, style
, flexGrow
, flexShrink
, alignSelf
)
|
Adds an icon component as a child.
Displays an icon on the wearable display.
Signature
fun icon(name: IconName, style: IconStyle = IconStyle.FILLED, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null) Parameters flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0.
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
|
image
(
uri
, bitmap
, sizePreset
, cornerRadius
, flexGrow
, flexShrink
, alignSelf
)
|
Adds an image component as a child.
Displays an image on the wearable display, sourced from either a remote uri or a local bitmap. Provide exactly one of uri or bitmap.
A bitmap is sent inline so it renders without network access on the wearable: the SDK downscales it to the display bounds (preserving aspect ratio) and encodes it into the payload. Prefer a remote uri for large or photographic images so the bytes are streamed by the wearable instead of inlined.
Signature
fun image(uri: String? = null, bitmap: Bitmap?, sizePreset: ImageSize = ImageSize.FILL, cornerRadius: CornerRadius = CornerRadius.NONE, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null) Parameters uri: String?
The URI of the image to display (e.g. an https URL, a data: URI, or a drawable:// reference).
bitmap: Bitmap?
A local bitmap to send inline, downscaled to the display and encoded by the SDK.
flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0.
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
|
text
(
content
, style
, color
, flexGrow
, flexShrink
, alignSelf
)
|
Adds a text component as a child.
Displays styled text content on the wearable display.
Signature
fun text(content: String, style: TextStyle = TextStyle.BODY, color: TextColor = TextColor.PRIMARY, flexGrow: Float = 0.0f, flexShrink: Float = 0.0f, alignSelf: Alignment? = null) Parameters content: String
The text string to display.
flexGrow: Float
How much this child should grow relative to siblings. Defaults to 0.
flexShrink: Float
How much this child should shrink relative to siblings. Defaults to 0.
|