Switch
开关控件,根节点作为轨道,滑块可独立设置样式。
正在加载交互演示…
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)))#导入
从 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::rootSwitch::thumb
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
Switch
查看源码pub const fn new(checked: bool) -> Selfread_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—
is_read_onlypub 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) -> ElementDecorate an application-owned root/track without adding layout or appearance.
Switch::root
查看源码pub fn root(self) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
Switch::thumb_with
查看源码pub fn thumb_with(self, thumb: Element) -> ElementHide an application-owned visual thumb from the accessible name.
Switch::thumb
查看源码pub fn thumb(self) -> ElementCreate the unstyled thumb part. Use [`Self::thumb_with`] to supply an existing element.
switch
查看源码pub fn switch(checked: bool) -> ElementCreate 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.
