checkbox

Function checkbox 

Source
pub fn checkbox(args: impl Into<CheckboxArgs>, state: CheckboxState)
Expand description

§checkbox

Renders an interactive checkbox with an animated checkmark.

§Usage

Use to capture a boolean (true/false) choice from the user.

§Parameters

  • args — configures the checkbox’s appearance and on_toggle callback; see CheckboxArgs.
  • state — a clonable CheckboxState that manages the checkmark and ripple animations.

§Examples

use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use tessera_ui::{tessera, Color, Dp};
use tessera_ui_basic_components::checkbox::{checkbox, CheckboxArgsBuilder, CheckboxState};

// A tiny UI demo that shows a checkbox and a text label that reflects its state.
#[derive(Clone, Default)]
struct DemoState {
    is_checked: Arc<AtomicBool>,
    checkbox_state: CheckboxState,
}

#[tessera]
fn checkbox_demo(state: DemoState) {
    // Build a simple checkbox whose on_toggle updates `is_checked`.
    let on_toggle = Arc::new({
        let is_checked = state.is_checked.clone();
        move |new_value| {
            is_checked.store(new_value, Ordering::SeqCst);
        }
    });

    // Render the checkbox; the example shows a minimal pattern for interactive demos.
    checkbox(
        CheckboxArgsBuilder::default()
            .on_toggle(on_toggle)
            .build()
            .unwrap(),
        state.checkbox_state.clone(),
    );
}