Checkbox

A boolean choice backed by an SDK control.

This page describes the SDK control. Code uses the Radix Look; builders use the ambient Look or built-in fallback.

Try it

Toggle Notifications to update the checked value. This preview runs the exact code sample below.

Open example separately ↗

Create it

Radix · integration snippet
use gpui::Context;
use xgpui_luma_look_radix as radix;
use xgpui_luma::infra::presenter::HasPresenter;

struct Example {
    control: xgpui_luma::controls::checkbox::Checkbox,
    notifications_enabled: bool,
}

impl Example {
    fn new(cx: &mut Context<Self>) -> Self {
        let control = radix::Checkbox::new("checkbox")
            .with_data(true)
            .label("Notifications")
            .on_value_changed(cx, |app: &mut Self, checked, cx| {
                app.notifications_enabled = checked;
                cx.notify();
            })
            .spawn(cx);

        Self { control, notifications_enabled: true }
    }
}

Checked against the current SDK and Radix crates. The owner retains the control; callback owners are held weakly. Render self.control.clone() in its view.

Events

Callbacks update application state. Repeated registrations append; the control retains them and holds the owner weakly. cx.notify() requests an owner redraw. set_data synchronizes state silently; on_value_changed follows the existing user-change event.

Event / payloadCallbackApplication use
Change { checked: bool }.on_value_changed(cx, |app, checked, cx| { … })Update the application’s checked value.
FocusChanged { focused: bool }.on_focus_changed(cx, |app, focused, cx| { … })Focus state changed.
EnabledChanged { enabled: bool }.on_enabled_changed(cx, |app, enabled, cx| { … })Enabled state changed.
HoverChanged { hovered: bool }.on_hover_changed(cx, |app, hovered, cx| { … })Pointer hover state changed.

CheckboxEvent · Event definitions. Use .on_event(cx, |app, event, cx| { … }) for all events. Factory-created controls support the same callbacks through CheckboxEventExt. Existing cx.subscribe observers remain supported.