pub struct ToggleSwitch<'a> { /* private fields */ }Expand description
A toggle switch widget that provides an animated on/off control with a sliding knob.
The ToggleSwitch widget creates a visual control that allows users to toggle between two states (on/off). It features a sliding knob that moves horizontally across a track to indicate the current state.
The widget supports:
- Customizable width and height
- Theme-based colors for active/inactive states
- Interactive hover and click effects
- Integration with Kolibri’s smartstate system for efficient rendering
§Examples
let mut state = false;
// Create a basic toggle switch
ui.add(ToggleSwitch::new(&mut state));
// Create a custom-sized toggle switch
ui.add(ToggleSwitch::new(&mut state)
.width(60)
.height(30));Implementations§
Source§impl<'a> ToggleSwitch<'a>
impl<'a> ToggleSwitch<'a>
Sourcepub fn new(active: &'a mut bool) -> ToggleSwitch<'a>
pub fn new(active: &'a mut bool) -> ToggleSwitch<'a>
Creates a new ToggleSwitch instance with the provided mutable reference to the active state.
The new ToggleSwitch will have a default width of 50 pixels and a height of 25 pixels.
Sourcepub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self
pub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self
Adds a Smartstate to the toggle switch for incremental redrawing.
The smartstate is used to efficiently manage the rendering of the toggle switch. Through this Smartstate, the toggle switch can leverage the smartstate system to avoid unnecessary redraws and improve performance.
Sourcepub fn width(self, width: u32) -> Self
pub fn width(self, width: u32) -> Self
Sets the width of the toggle switch.
The width determines the horizontal size of the switch’s track. A minimum width of 30 pixels is enforced to ensure proper rendering and usability.
§Examples
let mut state = false;
ui.add(ToggleSwitch::new(&mut state).width(60));Sourcepub fn height(self, height: u32) -> Self
pub fn height(self, height: u32) -> Self
Sets the height of the toggle switch.
The height determines the vertical size of the switch’s track and knob. A minimum height of 15 pixels is enforced to ensure proper rendering and usability.
§Examples
let mut state = false;
loop {
// [...]
ui.add(ToggleSwitch::new(&mut state).height(30).width(60));
}