pub fn glass_switch(args: impl Into<GlassSwitchArgs>)
Expand description
A glass-like switch component for toggling a boolean state.
The glass_switch
provides a visually appealing switch with a frosted glass effect.
It animates smoothly between its “on” and “off” states and is fully customizable
in terms of size, color, and border.
§Example
use std::sync::Arc;
use tessera_ui_basic_components::glass_switch::{glass_switch, GlassSwitchArgs, GlassSwitchArgsBuilder};
// In a real app, you would manage the state.
// This example shows how to create a switch that is initially off.
glass_switch(
GlassSwitchArgsBuilder::default()
.checked(false)
.on_toggle(Arc::new(|new_state| {
// Update your application state here
println!("Switch toggled to: {}", new_state);
}))
.build()
.unwrap(),
);
// An initially checked switch
glass_switch(
GlassSwitchArgsBuilder::default()
.checked(true)
.build()
.unwrap(),
);
§Arguments
args
- An instance ofGlassSwitchArgs
which can be built usingGlassSwitchArgsBuilder
.checked
: Abool
indicating the current state of the switch (true
for on,false
for off).on_toggle
: A callbackArc<dyn Fn(bool) + Send + Sync>
that is called when the switch is clicked. It receives the new boolean state.- Other arguments for customization like
width
,height
,track_on_color
,track_off_color
, etc. are also available.