amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / inputs / switch docs / components / inputs /

switch

04.4
On this page ▾
  1. Installation
  2. Usage
  3. Examples
  4. API
  5. Keyboard and accessibility

Turn a setting on or off.

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add switch --to ../my-app

Files copied: src/widgets/switch.rs, src/widgets/mod.rs

Usage

rust
use amenui::widgets::{switch, switch_sized};

fn view() -> El<Msg> {
    switch("s1", "通知", false, None, Msg::Nothing).width(220.0)
}

Examples

On

rust
fn view() -> El<Msg> {
    switch("s2", "通知", true, None, Msg::Nothing).width(220.0)
}

API

Functionsswitch, switch_sized
Propskey, label, on, states (names of off / on), msg; switch_sized adds the track height.
Filessrc/widgets/switch.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesoff, on, focused, disabled.
Keys and messagesmsg on press, Enter or Space.

On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).

Recipes: A form