ButtonGroupScope


Button group scope used to indicate a Modifier.weight and Modifier.animateWidth of a child element. Also defines the DSL to build the content of a ButtonGroup

Summary

Public functions

Modifier

Specifies the interaction source to use with this item.

Cmn
Unit
clickableItem(
    onClick: () -> Unit,
    label: String,
    icon: (@Composable () -> Unit)?,
    weight: Float,
    enabled: Boolean
)

Adds a clickable item to the ButtonGroup.

Cmn
Unit
customItem(
    buttonGroupContent: @Composable () -> Unit,
    menuContent: @Composable (ButtonGroupMenuState) -> Unit
)

Adds a custom item to the ButtonGroup.

Cmn
Unit
toggleableItem(
    checked: Boolean,
    label: String,
    onCheckedChange: (Boolean) -> Unit,
    icon: (@Composable () -> Unit)?,
    weight: Float,
    enabled: Boolean
)

Adds a toggleable item to the ButtonGroup.

Cmn
Modifier
Modifier.weight(
    weight: @FloatRange(from = 0.0, fromInclusive = false) Float
)

Size the element's width proportional to its weight relative to other weighted sibling elements in the ButtonGroup.

Cmn

Public functions

animateWidth

fun Modifier.animateWidth(interactionSource: InteractionSource): Modifier

Specifies the interaction source to use with this item. This is used to listen to events and animate growing the pressed button and shrink the neighbor(s).

Parameters
interactionSource: InteractionSource

the InteractionSource that button group will observe.

clickableItem

fun clickableItem(
    onClick: () -> Unit,
    label: String,
    icon: (@Composable () -> Unit)? = null,
    weight: Float = Float.NaN,
    enabled: Boolean = true
): Unit

Adds a clickable item to the ButtonGroup.

Parameters
onClick: () -> Unit

The action to perform when the item is clicked.

label: String

The text label for the item.

icon: (@Composable () -> Unit)? = null

An optional composable representing the item's icon.

weight: Float = Float.NaN

the weight to be applied to this item, please see ButtonGroupScope.weight

enabled: Boolean = true

Whether the item is enabled.

customItem

fun customItem(
    buttonGroupContent: @Composable () -> Unit,
    menuContent: @Composable (ButtonGroupMenuState) -> Unit
): Unit

Adds a custom item to the ButtonGroup.

Parameters
buttonGroupContent: @Composable () -> Unit

The composable to display in the app bar.

menuContent: @Composable (ButtonGroupMenuState) -> Unit

The composable to display in the overflow menu. It receives an ButtonGroupMenuState instance.

toggleableItem

fun toggleableItem(
    checked: Boolean,
    label: String,
    onCheckedChange: (Boolean) -> Unit,
    icon: (@Composable () -> Unit)? = null,
    weight: Float = Float.NaN,
    enabled: Boolean = true
): Unit

Adds a toggleable item to the ButtonGroup.

Parameters
checked: Boolean

Whether the item is currently checked.

label: String

The text label for the item.

onCheckedChange: (Boolean) -> Unit

The action to perform when the item's checked state changes.

icon: (@Composable () -> Unit)? = null

An optional composable representing the item's icon.

weight: Float = Float.NaN

the weight to be applied to this item, please see ButtonGroupScope.weight

enabled: Boolean = true

Whether the item is enabled.

fun Modifier.weight(
    weight: @FloatRange(from = 0.0, fromInclusive = false) Float
): Modifier

Size the element's width proportional to its weight relative to other weighted sibling elements in the ButtonGroup. The parent will divide the horizontal space remaining after measuring unweighted child elements and distribute it according to this weight.

Parameters
weight: @FloatRange(from = 0.0, fromInclusive = false) Float

The proportional width to give to this element, as related to the total of all weighted siblings. Must be positive.