Components / controls
SplitButton view
One action, plus the ones it stands in for.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::controls::split_button::SplitButton;
Reviewed in actions.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
label(label: impl Into<SharedString>) -> Self
icon(glyph: Icon) -> Self
variant(variant: ButtonVariant) -> Self
primary() -> Self
secondary() -> Self
items(items: impl IntoIterator<Item = MenuItem>, cx: &mut Context<Self>) -> Self
menu_name(name: impl Into<SharedString>, cx: &mut Context<Self>) -> Self
default_disabled(disabled: bool) -> Self
on_click(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
Commands
Need a Context, so they need a view.
set_label(label: impl Into<SharedString>, cx: &mut Context<Self>)
set_icon(icon: Option<Icon>, cx: &mut Context<Self>)
set_variant(variant: ButtonVariant, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_default_disabled(disabled: bool, cx: &mut Context<Self>)
set_items(items: Vec<MenuItem>, cx: &mut Context<Self>)
set_menu_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_on_click(handler: impl Fn(&mut Window, &mut App) + 'static, cx: &mut Context<Self>)
clear_on_click(cx: &mut Context<Self>)
set_disabled(disabled: bool, window: &mut Window, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
is_disabled() -> bool
menu() -> &Entity<Menu>
is_open(cx: &App) -> bool
open_menu(window: &mut Window, cx: &mut Context<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()
}