Components / controls
SegmentedControl builder
A strip where exactly one segment holds.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::controls::segmented::SegmentedControl;
Reviewed in form.
Also drawn by motion-state, which arranges components rather than reviewing them.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
label(label: impl Into<SharedString>) -> Self
segments(segments: impl IntoIterator<Item = Segment>) -> Self
selected(id: impl Into<SharedString>) -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
bind(binding: &Binding<SharedString>, cx: &App) -> Self
Example · form
fn form(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_form(window, cx);
let form = cx.global::<SceneForm>();
let (name, retention, region, labels) = (
form.name.clone(),
form.retention.clone(),
form.region.clone(),
form.labels.clone(),
);
let theme = cx.theme().clone();
// No fixed height and nothing pushed to the bottom: a form is a stack of
// fields one gap apart, and the 250px of nothing that a pinned last field
// opened up is not a rhythm anything else in the library keeps.
stack(&theme)
.w(px(420.0))
.child(
FormField::new("scene.form.name.form-field", "Workspace name")
.control("scene.form.name")
.required(true)
// The description says what the field is for and the error
// says what went wrong; neither answers for the other.
.description("Shown wherever this workspace appears.")
.error("A workspace with this name already exists.")
.child(name),
)
.child(
FormField::new("scene.form.retention.form-field", "Retention")
.control("scene.form.retention")
.required(true)
.description("How long a finished run is kept.")
.error("This workspace allows at most 60 days.")
.child(retention),
)
.child(
FormField::new("scene.form.visibility.form-field", "Visibility")
.control("scene.form.visibility")
.description("Who can open the runs in this workspace.")
.validation(ValidationState::Validating)
.child(
SegmentedControl::new("scene.form.visibility")
.label("Visibility")
.segments([
Segment::new("private", "Only me"),
Segment::new("team", "Workspace team"),
Segment::new("public", "Public").disabled(true),
])
.selected("team")
.on_select(|_, _, _| {}),
),
)
.child(
// The neutral strip above uses a raised knob alone. This large
// capsule opts into identity tint; selection does not invent it.
FormField::new("scene.form.lane.form-field", "Lane")
.control("scene.form.lane")
.description("Each lane keeps the colour it is known by.")
.child(
SegmentedControl::new("scene.form.lane")
.label("Lane")
.control_size(ControlSize::Lg)
.segments([
Segment::new("read", "Read")
.tint(super::display::identity_tint(&theme, "agent.read")),
Segment::new("shell", "Shell")
.tint(super::display::identity_tint(&theme, "agent.shell")),
Segment::new("network", "Network")
.tint(super::display::identity_tint(&theme, "agent.network")),
])
.selected("shell")
.on_select(|_, _, _| {}),
),
)
.child(
FormField::new("scene.form.labels.form-field", "Labels")
.control("scene.form.labels")
// The keystroke lives in the hint, so the description does not
// spend a second line repeating it.
.description("At most five, and each one only once.")
.hint("enter")
.child(labels),
)
.child(
FormField::new("scene.form.region.form-field", "All Agent models")
.control("scene.form.region")
.description("Choose a chat-capable model for direct runs.")
.child(region),
)
.into_any_element()
}