pub fn switch_with_child(
args: impl Into<SwitchArgs>,
state: SwitchState,
child: impl FnOnce() + Send + Sync + 'static,
)Expand description
§switch_with_child
Animated Material 3 switch with required custom thumb content; ideal for boolean toggles that show an icon or label.
§Usage
Use for settings or binary preferences; provide a child to draw custom content (e.g., an icon) inside the thumb.
§Parameters
args— configures sizing, colors, and callbacks; seeSwitchArgs.state— a clonableSwitchStatethat owns the checked state and animation.child— closure rendered at the thumb center.
§Examples
use std::sync::Arc;
use tessera_ui_basic_components::switch::{switch_with_child, SwitchArgsBuilder, SwitchState};
use tessera_ui_basic_components::text::{text, TextArgsBuilder};
let switch_state = SwitchState::new(false);
switch_with_child(
SwitchArgsBuilder::default()
.on_toggle(Arc::new(|checked| {
assert!(checked || !checked);
}))
.build()
.unwrap(),
switch_state,
|| {
text(
TextArgsBuilder::default()
.text("✓".to_string())
.build()
.unwrap(),
);
},
);