A button that stays pressed, or a group of them.
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 toggle --to ../my-appFiles copied: src/widgets/toggle.rs, src/widgets/mod.rs
Usage
use amenui::widgets::{toggle, toggle_group};
fn view() -> El<Msg> {
toggle("tg1", "B", true, Msg::Nothing)
}Examples
A group
fn view() -> El<Msg> {
toggle_group("tg2", &["左", "中", "右"], &[true, false, false], Msg::Pick)
}API
| Functions | toggle, toggle_group |
|---|---|
| Props | toggle: key, label, on, msg; toggle_group: key, labels, on (one per label), msg(i). |
| Files | src/widgets/toggle.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 (aria-pressed), focused; in a group one focus stop, Left / Right move focus by choosing, Space toggles. |
|---|---|
| Keys and messages | msg / msg(i) 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).