本文へスキップ

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.