Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CheckboxCard

Layer: molecule · Path: src/molecules/checkbox_card.rs · Exports: checkbox_card::CheckboxCard

A selectable card bound to a &mut bool: an interactive Surface wrapping a display-only Checkbox plus a label and optional description. The whole card is the click target — clicking anywhere toggles the bound bool (the inner checkbox is non-interactive, so there is no double-toggle).

Design

  • Purpose / when to use — A larger, more legible alternative to a bare checkbox for opt-in settings, where a description helps.
  • AnatomySurface::new().interactive().selected(checked) padded SPACE_3 → horizontal row of a display Checkbox (.interactive(false)) + a vertical stack of a body_strong Text label and an optional muted caption description.
  • States — selected visual driven by Surface::selected(*checked); hover/press handled by Surface::interactive().
  • Tokens / layout consumedcore::SPACE_3 (pad + checkbox→text gap). See tokens.

API

MethodEffect
CheckboxCard::new(checked: &'a mut bool, label: impl Into<String>) -> SelfBind state + set label.
.description(description: impl Into<String>) -> SelfOptional muted caption under the label.
.id_source(id: impl std::hash::Hash) -> SelfStable surface id (use when several share a frame).
.show(self, ui: &mut Ui) -> ResponseRender; toggles *checked on click. Returns the surface Response.

Usage

#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::CheckboxCard;

// minimal
let mut on = true;
CheckboxCard::new(&mut on, "Enable notifications").show(ui);
}
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::CheckboxCard;

// realistic — with description + stable id
CheckboxCard::new(&mut on, "Enable notifications")
    .description("Email + in-app alerts")
    .id_source("cc")
    .show(ui);
}

Composition

Composes Surface + Checkbox + Text. It never paints — see the guards.

Notes

  • Two-way binding: show writes *self.checked = !*self.checked when the surface is clicked.
  • The inner checkbox is mirrored display state (.interactive(false)), so it doesn’t compete for the click.
  • Set id_source to avoid surface-id collisions when stacking multiple cards.