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

docs / components / display / caption docs / components / display /

caption

04.16
On this page ▾
  1. Installation
  2. Usage
  3. API
  4. Keyboard and accessibility

A small monospaced line under a live demo that prints the parameters driving it (read from the same fields, never typed by hand), each also a number control.

El::caption_params puts it under the demo.

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

Files copied: src/widgets/caption.rs, src/widgets/mod.rs, src/widgets/number.rs

Usage

rust
use amenui::widgets::{caption};

fn view() -> El<Msg> {
    let (w, r) = (120.0_f32, 8.0_f32);
    let spec = Spec { min: 0.0, max: 400.0, step: 1.0, decimals: 0, unit: "px" };
    let params = [CaptionParam::new("width", w, spec), CaptionParam::new("radius", r, spec)];
    space(w, 40.0).radius(r).fill(Paint::ACCENT).key("cap1/demo")
        .caption_params("cap1", format!("rect(w={w:.0}, r={r:.0})"), &params, Msg::Num)
}

API

Functionscaption
Propskey, formula (the line, written from the same fields the demo reads), params (CaptionParam: name, value, spec, draft), msg.
Filessrc/widgets/caption.rs
Depends onbase, number
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

Statesrest; a number being typed (see number); a changed value recomposes its digits.
Keys and messagesmsg(i, Edit) from parameter i's control.

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