pub fn switch(args: impl Into<SwitchArgs>, state: Arc<RwLock<SwitchState>>)
Expand description
A UI component that displays a toggle switch for boolean state.
The switch
component provides a customizable on/off control, commonly used for toggling settings.
It can be controlled via external state (SwitchState
) or by using the checked
and on_toggle
parameters.
§Arguments
args
- Parameters for configuring the switch, seeSwitchArgs
.
§Example
use tessera_ui::Dp;
use tessera_ui_basic_components::switch::{SwitchArgs, switch, SwitchState};
use std::sync::Arc;
use parking_lot::RwLock;
let state = Arc::new(RwLock::new(SwitchState::new(false)));
switch(SwitchArgs {
on_toggle: Some(Arc::new(|checked| {
println!("Switch toggled: {}", checked);
})),
width: Dp(60.0),
height: Dp(36.0),
..Default::default()
}, state.clone());