Skip to content

Switch

An on/off control with a root track and independently styled thumb.

Loading interactive demo…

#Import

Import Switch from quickgui.

use quickgui::*;

#Usage

let control = Switch::new(enabled);
control
    .root().w(40.0).h(24.0).rounded(12.0).on_click(toggle)
    .child(control.thumb_with(div().size(18.0, 18.0).rounded(9.0)))

#Anatomy

  • Switch::root
  • Switch::thumb

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

pub const fn new(checked: bool) -> Self
read_onlypub const fn read_only(mut self, read_only: bool) -> Self—

Show a value the user may read but not change, Base UI's `readOnly`. A read-only switch stays focusable and stays in the Tab sequence; only the toggle it would perform is refused, through [`Self::next_checked`].

pub const fn read_only(mut self, read_only: bool) -> Self
View source
is_checkedpub const fn is_checked(self) -> bool—

Configures is checked for this part.

pub const fn is_checked(self) -> bool
View source
is_read_onlypub const fn is_read_only(self) -> bool—

Configures is read only for this part.

pub const fn is_read_only(self) -> bool
View source
next_checkedpub const fn next_checked(self) -> Option<bool>—

The value an activation moves this switch to, or `None` when it refuses.

pub const fn next_checked(self) -> Option<bool>
View source

Switch::root_with

View source
pub fn root_with(self, root: Element) -> Element

Decorate an application-owned root/track without adding layout or appearance.

Switch::root

View source
pub fn root(self) -> Element

Create the unstyled root part. Use [`Self::root_with`] to supply an existing element.

Switch::thumb_with

View source
pub fn thumb_with(self, thumb: Element) -> Element

Hide an application-owned visual thumb from the accessible name.

Switch::thumb

View source
pub fn thumb(self) -> Element

Create the unstyled thumb part. Use [`Self::thumb_with`] to supply an existing element.

pub fn switch(checked: bool) -> Element

Create an unstyled controlled switch root. This shorthand is equivalent to `Switch::new(checked).root_with(div())`. Use [`Switch`] directly when composing a separate thumb part.