limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/Actions

    ButtonGroup

    A set of actions that sits in a row when there is room and in a column when there is not, such as the foot of a dialog. The group owns the order, spacing and alignment of the buttons it is given.

    Native componentGuide source

    Preview

    CodeSource
    fn view(palette: ComponentPalette) -> Element {
        ButtonGroup::new(vec![
            Button::new("cancel", "Cancel", palette)
                .variant(ButtonVariant::Outline)
                .render(),
            Button::new("save", "Save", palette).render(),
        ])
        .render()
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Button group2 / 5
    CodeSource
    ButtonGroup::new(group("button-group-end", palette))
        .align_end()
        .leading(
            Button::new("button-group-help", "Help", palette)
                .variant(ButtonVariant::Ghost)
                .render(),
        )
        .render()
    Button group3 / 5
    CodeSource
    ButtonGroup::new(group("button-group-stacked", palette))
        .stacked(true)
        .reverse_when_stacked(true)
        .leading(
            Button::new("button-group-stacked-help", "Help", palette)
                .variant(ButtonVariant::Ghost)
                .render(),
        )
        .render()
        .size(Some(220.0), None)
    Button group4 / 5
    CodeSource
    ButtonGroup::new(group("button-group-wide", palette)).sizing(WIDE_GROUP).render()
    Button group5 / 5
    CodeSource
    ButtonGroup::new(group("button-group-wide-stacked", palette))
        .sizing(WIDE_GROUP)
        .stacked(true)
        .render()
        .size(Some(220.0), None)

    ButtonGroup

    A set of actions that sits in a row when there is room and in a column when there is not, such as the foot of a dialog. The group owns the order, spacing and alignment of the buttons it is given.

    Import

    use limn::{Button, ButtonGroup, ButtonVariant, Component};

    Usage

    Pass rendered buttons in reading order, the primary action last. They sit in a row, 6 px apart. Each button still reports its own UiAction::Clicked.

    fn view(palette: ComponentPalette) -> Element {
        ButtonGroup::new(vec![
            Button::new("cancel", "Cancel", palette)
                .variant(ButtonVariant::Outline)
                .render(),
            Button::new("save", "Save", palette).render(),
        ])
        .render()
    }

    Stacked

    ButtonGroup::new(buttons)
        .stacked(narrow)
        .reverse_when_stacked(true)
        .render()

    stacked(true) lays the actions in a column, each as wide as the group. The host decides when: the group does not measure itself. reverse_when_stacked reverses the actions in the column so the primary one comes first; in a row it does nothing.

    Aligned to the end

    ButtonGroup::new(buttons).align_end().render()

    align_end pushes the actions to the far edge of the row.

    A leading element

    ButtonGroup::new(buttons)
        .align_end()
        .leading(
            Button::new("help", "Help", palette)
                .variant(ButtonVariant::Ghost)
                .render(),
        )
        .render()

    leading keeps one element at the near edge, before the actions: at the start of the row, and first in the column whatever the actions’ order.

    Sizing

    const WIDE: ButtonGroupSizing = ButtonGroupSizing { gap: 12.0, stacked_gap: 10.0 };
    
    ButtonGroup::new(buttons).sizing(WIDE).render()

    A ButtonGroupSizing has one gap for the row and one for the column. ButtonGroupSizing::DEFAULT is 6 and 6.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/buttons.rs.