pub struct ToggleButton<'a> { /* private fields */ }Expand description
A button widget that can be toggled on and off.
ToggleButton provides a clickable button that maintains an on/off state. When clicked, it toggles between these states and displays different visual styles accordingly. The button includes a text label and supports various interaction states like hover and click.
§Examples
let mut state = false;
loop {
// [...]
ui.add(ToggleButton::new("Toggle Me", &mut state));
}Implementations§
Source§impl<'a> ToggleButton<'a>
impl<'a> ToggleButton<'a>
Sourcepub fn new(label: &'a str, active: &'a mut bool) -> ToggleButton<'a>
pub fn new(label: &'a str, active: &'a mut bool) -> ToggleButton<'a>
Creates a new ToggleButton with the given label and active state.
The label parameter is the text to display on the button, and the active
parameter is a mutable reference to a boolean that tracks the on/off state
of the button.
§Examples
let mut state = false;
let mut smartstateProvider = SmartstateProvider::<20>::new();
loop {
// [...]
if ui.add(ToggleButton::new("Toggle Me", &mut state)).changed() {
// handle toggle
}
// or with smartstate:
if ui.add(ToggleButton::new("Toggle Me", &mut state).smartstate(smartstateProvider.nxt())).changed() {
// handle toggle
}
}Sourcepub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self
pub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self
Attaches a Smartstate to the toggle button for incremental redrawing.
Smartstates enable efficient rendering by tracking the button’s visual state and only redrawing when necessary.
Returns self for method chaining.