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

docs / components / inputs / choice docs / components / inputs /

choice

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

Choose one of a few mutually exclusive options.

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 choice --to ../my-app

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

Usage

rust
use amenui::widgets::{choice, segmented};

fn view() -> El<Msg> {
    choice("c1", "大小", &["小", "中", "大"], 1, Msg::Pick)
}

Examples

Segmented

rust
fn view() -> El<Msg> {
    segmented("c2", &["日", "周", "月"], 0, 28.0, Msg::Pick)
}

API

Functionschoice, segmented
Propschoice(key, label, options, current, msg); segmented(key, options, current, height, msg).
Filessrc/widgets/choice.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

Statesthe current option is an ink plate with its label in the ground's colour; segmented is one focus stop, Left / Right move.
Keys and messagesmsg(i) with the option's index.

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).