GPUI Box GitHub

Components / controls

ButtonGroup builder

Adjacent related actions sharing one frame.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::controls::button::ButtonGroup;

Reviewed in actions.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

child(button: impl Into<EffectScoped<Button>>) -> Self
children<B: Into<EffectScoped<Button>>>(buttons: impl IntoIterator<Item = B>) -> Self
Example · actions
fn actions(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_actions(window, cx);
    let split = cx.global::<SceneActions>().split.clone();
    let theme = cx.theme().clone();

    stack(&theme)
        .w(px(560.0))
        .h(px(360.0))
        .child(
            row(&theme)
                .child(
                    // One row, one weight: a chipless button beside four
                    // chipped ones reads as the one that is unavailable.
                    IconButton::new("scene.actions.copy", Icon::Copy, "Copy run id")
                        .secondary()
                        .on_click(|_, _| {}),
                )
                .child(
                    IconButton::new("scene.actions.rename", Icon::Pen, "Rename run")
                        .secondary()
                        .on_click(|_, _| {}),
                )
                .child(
                    IconButton::new("scene.actions.refresh", Icon::Refresh, "Refresh")
                        .secondary()
                        .loading(true)
                        .on_click(|_, _| {}),
                )
                .child(
                    IconButton::new("scene.actions.delete", Icon::Trash, "Delete run")
                        .danger()
                        .on_click(|_, _| {}),
                )
                .child(
                    IconButton::new("scene.actions.archive", Icon::Archive, "Archive run")
                        .secondary()
                        .disabled(true)
                        .on_click(|_, _| {}),
                ),
        )
        .child(
            row(&theme).child(
                // A range picker built the way a host would build one: the
                // track is the group's, the answers that are not current stay
                // bare on it, and the one that is holds a chip in the colour
                // the library reserves for the current answer.
                ButtonGroup::new("scene.actions.range")
                    .children([
                        Button::new("scene.actions.range.day")
                            .label("Day")
                            .ghost()
                            .on_click(|_, _| {}),
                        Button::new("scene.actions.range.week")
                            .label("Week")
                            .variant(gpui_kit_theme::Variant::Light)
                            .selected(true)
                            .on_click(|_, _| {}),
                        Button::new("scene.actions.range.month")
                            .label("Month")
                            .ghost()
                            .on_click(|_, _| {}),
                    ])
                    .small(),
            ),
        )
        .child(row(&theme).child(split))
        .into_any_element()
}

Source: crates/gpui-kit/src/controls/button.rs