limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/Inputs

    Checkbox

    A box that is checked or not, with a label beside it: one of several options that can each be chosen, or a statement to agree to. For a setting that takes effect at once, use a Switch.

    Native componentGuide source

    Preview

    CodeSource
    fn view(state: &State, palette: ComponentPalette) -> Element {
        Checkbox::new("terms", state.terms, palette).label("I accept the terms").render()
    }
    
    fn update(state: &mut State, action: &UiAction) {
        if let UiAction::Clicked { id } = action {
            if id == "terms" {
                state.terms = !state.terms;
            }
        }
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Checkbox2 / 2
    CodeSource
    row(vec![live("check-updates", "Send me product updates").render()])
    Indeterminate
    CodeSource
    Element::column(channels).gap(8.0)
    Sizes
    CodeSource
    Element::column(vec![
        row(vec![live("check-dense", "Dense").size(ControlSize::Dense).render()]),
        row(vec![live("check-compact", "Compact").size(ControlSize::Compact).render()]),
        row(vec![live("check-regular", "Regular").size(ControlSize::Regular).render()]),
        row(vec![live("check-spacious", "Spacious").size(ControlSize::Spacious).render()]),
    ])
    .gap(8.0)
    Disabled
    CodeSource
    row(vec![
        Checkbox::new("check-off-empty", false, palette).label("Unchecked").disabled().render(),
        Checkbox::new("check-off-checked", true, palette).label("Checked").disabled().render(),
        Checkbox::new("check-off-mixed", false, palette).label("Indeterminate").indeterminate(true).disabled().render(),
    ])
    Long label
    CodeSource
    live(
        "check-long",
        "Keep a copy of every message on this device, including attachments, so that they can be read without a connection",
    )
    .render()
    .size(Some(cx.width.min(280.0)), None)
    Without a label
    CodeSource
    row(vec![
        live("check-row-1", "").accessibility_label("Select row 1").render(),
        live("check-row-2", "").accessibility_label("Select row 2").render(),
        Checkbox::new("check-row-3", true, palette).accessibility_label("Select row 3").disabled().render(),
    ])

    Checkbox

    A box that is checked or not, with a label beside it: one of several options that can each be chosen, or a statement to agree to. For a setting that takes effect at once, use a Switch.

    Import

    use limn::{Checkbox, Component};

    Usage

    A checkbox is controlled: pass whether it is checked each frame, and flip your own value when it reports a click.

    fn view(state: &State, palette: ComponentPalette) -> Element {
        Checkbox::new("terms", state.terms, palette).label("I accept the terms").render()
    }
    
    fn update(state: &mut State, action: &UiAction) {
        if let UiAction::Clicked { id } = action {
            if id == "terms" {
                state.terms = !state.terms;
            }
        }
    }

    A checked box is filled with the palette’s text color and its check is drawn in the surface color. An unchecked one is an empty box with a border.

    Label

    Checkbox::new("updates", state.updates, palette).label("Send me product updates")

    The label is part of the target: a click anywhere on it is a click on the checkbox, and the empty box lights while the pointer is over either. Without a label the checkbox is the box alone.

    A label that does not fit its width wraps; it is never cut. The box stays on the first line. In a row the checkbox takes the width of its label. In a column it takes the column’s width, and the room beside a short label is part of the target. Give it a width, or put it in a column that has one, where it should wrap:

    Checkbox::new("offline", state.offline, palette)
        .label("Keep a copy of every message on this device, including attachments")
        .render()
        .size(Some(280.0), None)

    Indeterminate

    let chosen = state.channels.iter().filter(|channel| channel.on).count();
    Checkbox::new("all-channels", chosen == state.channels.len(), palette)
        .label("All channels")
        .indeterminate(chosen > 0 && chosen < state.channels.len())

    An indeterminate box is filled and shows a dash, whatever checked is. It is for the parent of a list of which only some are chosen. It reports a click as any other; the host decides what that means, usually choosing all, or none once all are chosen.

    Sizes

    Checkbox::new("dense", on, palette).label("Dense").size(ControlSize::Dense)
    SizeBoxLabel textLine
    ControlSize::Dense141216
    ControlSize::Compact161318
    ControlSize::Regular, the default161420
    ControlSize::Spacious181624

    A checkbox is as high as its label, one line for each line of text, not as high as a button of the same size. A box alone is one line high.

    Disabled

    Checkbox::new("sync", true, palette).label("Sync").disabled().render()
    Checkbox::new("sync", state.sync, palette).label("Sync").enabled(state.signed_in).render()

    A disabled checkbox shows its value in the muted color, keeps its place and takes no pointer or focus.

    Keyboard

    KeyEffect
    TabMoves the focus to the checkbox. A disabled one is skipped.
    Enter, SpaceReports the click.

    Motion

    The fill cross-fades between empty and filled over hover_ms, as it does under the pointer, and the mark’s ink fades with it over move_ms. With reduced motion both change at once.

    Actions

    ActionWhen
    UiAction::Clicked { id }The box or its label is clicked, or Enter or Space is pressed while it has the focus.

    Accessibility

    The platform is told a check box, named by its label, whether it is on, and whether it is disabled. A box without a label has no name until the host gives one, which is also said in place of a label when both are given:

    Checkbox::new("row-3", selected, palette).accessibility_label("Select row 3")

    An indeterminate box is told as mixed: neither on nor off.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/checkbox.rs.