toggle_button

Function toggle_button 

Source
pub fn toggle_button(state: impl Fn() -> bool + 'static) -> ToggleButton
Expand description

A reactive toggle button.

When the button is toggled by clicking or dragging the widget, an update will be sent to the ToggleButton::on_toggle handler.

By default this toggle button has a style class of ToggleButtonClass applied with a default style provided.

§Examples

// An example using read-write signal
let state = RwSignal::new(true);
let toggle = toggle_button(move || state.get())
    // Set action when button is toggled according to the toggle state provided.
    .on_toggle(move |new_state| state.set(new_state));

// Use toggle button specific styles to control its look and behavior
let customized_toggle = toggle_button(move || state.get())
    .on_toggle(move |new_state| state.set(new_state))
    .toggle_style(|s| s
        // Set toggle button accent color
        .accent_color(css::REBECCA_PURPLE)
        // Set toggle button circle radius
        .circle_rad(5.)
        // Set toggle button handle color
        .handle_color(css::PURPLE)
        // Set toggle button handle inset
        .handle_inset(1.)
        // Set toggle button behavior:
        // - `Follow` - to follow the pointer movement
        // - `Snap` - to snap once pointer passed 50% treshold
        .behavior(ToggleHandleBehavior::Snap)
    );

§Reactivity

This function is reactive and will reactively respond to changes.