Checkbox
二态或不确定状态的选择控件,指示器可独立设置样式。
正在加载交互演示…
let checkbox = Checkbox::new(checked);
checkbox
.root().flex_row().items_center().gap(8.0).on_click(toggle)
.child(checkbox.indicator_with(div().size(16.0, 16.0).rounded(4.0)))
.child(text("Remember me"))#导入
从 quickgui 导入 Checkbox。
use quickgui::*;#用法
let checkbox = Checkbox::new(checked);
checkbox
.root().flex_row().items_center().gap(8.0).on_click(toggle)
.child(checkbox.indicator_with(div().size(16.0, 16.0).rounded(4.0)))
.child(text("Remember me"))#结构
Checkbox::rootCheckbox::indicator
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
Checkbox
查看源码pub fn new(state: impl Into<ToggleState>) -> Selfparentpub fn parent(children: impl IntoIterator<Item = bool>) -> Self—
Derive a parent checkbox from the checked values of the boxes it governs. This is Base UI's `parent` checkbox: every child checked reports on, none reports off, and a mix reports mixed. QuickGUI keeps no child registry — the application passes the values it is already rendering — so the derivation stays a pure function of the caller's own data. ``` use quickgui::{Checkbox, ToggleState}; assert_eq!(Checkbox::parent([true, true]).state(), ToggleState::On); assert_eq!(Checkbox::parent([false, false]).state(), ToggleState::Off); assert_eq!(Checkbox::parent([true, false]).state(), ToggleState::Mixed); // An empty group is unchecked rather than mixed. assert_eq!(Checkbox::parent([]).state(), ToggleState::Off); ```
pub fn parent(children: impl IntoIterator<Item = 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`. Unlike a disabled checkbox, a read-only one stays focusable and stays in the Tab sequence. QuickGUI projects the state and refuses the transition through [`Self::next_state`]; the application's own listener asks for that transition rather than toggling blindly.
pub const fn read_only(mut self, read_only: bool) -> Self查看源码statepub const fn state(self) -> ToggleState—
is_read_onlypub const fn is_read_only(self) -> bool—
next_statepub const fn next_state(self) -> Option<ToggleState>—
The state an activation moves this checkbox to, or `None` when it refuses. Mixed and off both move to on, and on moves to off, which is the web's tri-state contract. A read-only checkbox returns `None`, so a click listener that asks before writing cannot change a value the control is refusing.
pub const fn next_state(self) -> Option<ToggleState>查看源码parent_next_checkedpub const fn parent_next_checked(self) -> Option<bool>—
The checked value activating a parent checkbox moves its whole group to. A partially or fully unchecked parent checks everything; a fully checked one clears it. Returns `None` when the parent is read-only.
pub const fn parent_next_checked(self) -> Option<bool>查看源码Checkbox::root_with
查看源码pub fn root_with(self, root: Element) -> ElementDecorate an application-owned root without adding layout or appearance.
Checkbox::root
查看源码pub fn root(self) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
Checkbox::indicator_with
查看源码pub fn indicator_with(self, indicator: Element) -> ElementHide an application-owned visual indicator from the accessible name.
Checkbox::indicator
查看源码pub fn indicator(self) -> ElementCreate the unstyled indicator part. Use [`Self::indicator_with`] to supply an existing element.
checkbox
查看源码pub fn checkbox(state: impl Into<ToggleState>) -> ElementCreate an unstyled controlled checkbox root. This shorthand is equivalent to `Checkbox::new(state).root_with(div())`. Use [`Checkbox`] directly when composing a separate indicator part.
