Skip to main content

glass_switch

Function glass_switch 

Source
pub fn glass_switch() -> GlassSwitchBuilder
Expand description

§glass_switch

An interactive switch with glass effect.

§Usage

Use when you need a toggle switch with a glassmorphic style.

§Parameters

  • modifier — optional modifier chain applied to the switch subtree.
  • on_toggle — optional callback invoked when the switch toggles.
  • checked — initial checked state.
  • width — optional track width override.
  • height — optional track height override.
  • track_on_color — optional track tint when checked.
  • track_off_color — optional track tint when unchecked.
  • thumb_on_alpha — optional thumb alpha when checked.
  • thumb_off_alpha — optional thumb alpha when unchecked.
  • thumb_border — optional thumb border override.
  • track_border — optional track border override.
  • thumb_padding — optional thumb padding.
  • accessibility_label — optional accessibility label.
  • accessibility_description — optional accessibility description.
  • controller — optional external controller.

§Examples

use tessera_components::glass_switch::{GlassSwitchController, glass_switch};
use tessera_components::theme::{MaterialTheme, material_theme};
use tessera_ui::{LayoutResult, remember, tessera};

#[tessera]
fn demo() {
    let controller = remember(|| GlassSwitchController::new(false));
    assert!(!controller.with(|c| c.is_checked()));

    material_theme()
        .theme(|| MaterialTheme::default())
        .child(move || {
            glass_switch().checked(controller.with(|c| c.is_checked()));
        });

    controller.with_mut(|c| c.toggle());
    assert!(controller.with(|c| c.is_checked()));
}