跳到正文

Switch

开关控件,根节点作为轨道,滑块可独立设置样式。

正在加载交互演示…

#导入

从 quickgui 导入 Switch。

use quickgui::*;

#用法

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)))

#结构

  • Switch::root
  • Switch::thumb

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

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
查看源码
is_checkedpub const fn is_checked(self) -> bool—

Configures is checked for this part.

pub const fn is_checked(self) -> bool
查看源码
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
查看源码
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>
查看源码

Switch::root_with

查看源码
pub fn root_with(self, root: Element) -> Element

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

Switch::root

查看源码
pub fn root(self) -> Element

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

Switch::thumb_with

查看源码
pub fn thumb_with(self, thumb: Element) -> Element

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

Switch::thumb

查看源码
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.