Incular logoIncular
API ReferenceDesign Systems

Checkbox, Radio & Switch

Selection controls with states, colors, and change callbacks.

Checkbox

PropTypeDefault
valueboolfalse
indeterminateboolfalse
enabled / read_only / requiredbooltrue / false / false
on_changedFn(bool)Tristate-aware callback
use incular::prelude::*;
use incular::controls_prelude::{Checkbox, Radio, Switch};

fn main() {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Column::builder()
                    .main_axis_size(MainAxisSize::Min)
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Checkbox::new(false)
                                .label("Accept")
                                .on_changed(|v| println!("checked: {v}")).into(),
                        Radio::new("a", Some("a")).label("Option A").into(),
                        Switch::new(true)
                                .on_changed(|v| println!("on: {v}")).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

Radio

toggleable re-fires when already selected; color setters (active_color, inactive_color, dot_color, border_color, border_width) and enabled mirror Checkbox — all exercised through the runnable program above.

Switch

enabled, read_only, child, and on_changed mirror Checkbox — exercised through the runnable program above.

CheckedState

use incular::controls_prelude::CheckedState;

fn main() {
    let unchecked = CheckedState::Unchecked;
    let checked = CheckedState::Checked;
    println!(
        "unchecked: {}, checked: {}",
        unchecked.is_checked(),
        checked.is_checked()
    );
    let from_bool: CheckedState = true.into();
    println!("from bool: {}", from_bool.is_checked());
}

Displays as "false" / "true" / "mixed". Compound roots (checkbox::Root, radio::Root<T>/Group<T>, switch::Root/Thumb) expose the same anatomy with state callbacks (on_checked_change, on_value_change). RawRadio<T> is the unstyled radio primitive (new(value, group) + on_changed).

Related: Button, Material Selection.

On this page