Turn a setting on or off.
Installation
Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:
cargo run --release --bin amenui -- add switch --to ../my-appFiles copied: src/widgets/switch.rs, src/widgets/mod.rs
Usage
use amenui::widgets::{switch, switch_sized};
fn view() -> El<Msg> {
switch("s1", "通知", false, None, Msg::Nothing).width(220.0)
}Examples
On
fn view() -> El<Msg> {
switch("s2", "通知", true, None, Msg::Nothing).width(220.0)
}API
| Functions | switch, switch_sized |
|---|---|
| Props | key, label, on, states (names of off / on), msg; switch_sized adds the track height. |
| Files | src/widgets/switch.rs |
| Depends on | base |
| Response to fronts | nudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap) |
| Recomposition | keyed labels recompose when their text changes |
Keyboard and accessibility
| States | off, on, focused, disabled. |
|---|---|
| Keys and messages | msg 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