Control Group
Compose controls with coordinated selection and focus.
Basic use
use xgpui_luma_look_radix as radix;
use gpui::{Context};
use xgpui_luma::controls::control_group::{ControlGroupItem};
struct Example {
control: xgpui_luma::controls::control_group::ControlGroup<xgpui_luma::controls::control_group::ControlGroupItem>,
selected_tools: Vec<gpui::SharedString>,
}
impl Example {
fn new(cx: &mut Context<Self>) -> Self {
let look = cx.try_global::<radix::Look>().cloned().unwrap_or_else(radix::Look::built_in);
let control = radix::control_group_builder::<ControlGroupItem>(&look, "actions", xgpui_luma::theme::ControlSize::Md)
.items([ControlGroupItem::new("open").label("Open")])
.on_value_changed(cx, |app, _, _, selected_ids, cx| {
app.selected_tools = selected_ids.clone();
cx.notify();
})
.spawn(cx);
Self { control, selected_tools: Vec::new() }
}
}Integration snippet, checked against the current SDK and Radix crates. cx is the initialized owner context. The control retains its callbacks; callback owners are held weakly. Render self.control.clone() in the owner’s view.
Radix styling
control_group_builder(&look, id, size) supplies shared base shell and toggle-item styling for derived groups. The SDK retains selection and focus behavior. Item size is chosen when creating the factory; supply custom item content through the SDK template APIs.
Pass an explicit Look, including forks. Theme adapters retain that binding; notify affected controls and their owners after palette, mode, or stylesheet edits. Resolved look values are snapshots and must be resolved again during render.
See the Radix control support table for adapter and utility status.
SDK behavior & customization
The shared group engine supports custom item and container templates.
Relevant contracts: ControlGroupItemRenderModel, ControlGroupRenderModel, ControlGroupTemplateHandlers, ControlGroupItemTemplate.
Use the module’s template contract for structural changes. Builder modifiers and item templates vary by control.
Events
Callbacks follow the existing SDK event stream. Registrations append, hold the owner weakly, and live until the control is released. cx.notify() requests an owner redraw. Compound payloads are borrowed; scalar values are passed by value.
| Event / payload | Callback |
|---|---|
Activate { activated_id: SharedString } | .on_activate(cx, |app, activated_id, cx| { … }) |
Change { changed_id: SharedString, selected: bool, selected_ids: Vec<SharedString> } | .on_value_changed(cx, |app, changed_id, selected, selected_ids, cx| { … }) |
ItemBoundsChanged { item_id: SharedString, bounds: Bounds<Pixels> } | .on_item_bounds_changed(cx, |app, item_id, bounds, cx| { … }) |
FocusChanged { focused: bool } | .on_focus_changed(cx, |app, focused, cx| { … }) |
ItemFocused { item_id: SharedString } | .on_item_focused(cx, |app, item_id, cx| { … }) |
Use .on_event(cx, |app, event, cx| { … }) for all events. Factory-created controls support the same callbacks through ControlGroupEventExt. Existing cx.subscribe observers remain supported.