精确设置一个数值:获得焦点后直接键入,或用方向键和两侧的按钮按步长改;在数值上横向拖动可以连续调。
安装
组件以源码分发。把它和它依赖的文件拷进你的项目,再按需要改:
cargo run --release --bin amenui -- add number --to ../my-app拷贝的文件: src/widgets/number.rs, src/widgets/mod.rs
用法
use amenui::widgets::{number};
fn view() -> El<Msg> {
number("n1", "份数", 3.0, Spec { min: 0.0, max: 9.0, step: 1.0, decimals: 0, unit: "" }, None, Msg::Num).width(320.0)
}示例
带单位
fn view() -> El<Msg> {
number("n2", "宽度", 12.5, Spec { min: 0.0, max: 64.0, step: 0.5, decimals: 1, unit: "px" }, None, Msg::Num).width(320.0)
}接口
| 函数 | number |
|---|---|
| 参数 | key, label, value, spec: Spec (min, max, step, decimals, unit), draft (what is being typed), msg. |
| 文件 | src/widgets/number.rs |
| 依赖 | base |
| 对波前的响应 | nudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap) |
| 重组 | its value text ({key}/shown) recomposes when the value changes |
键盘与无障碍
| 状态 | rest, focused, typing (ink border, accent caret), disabled; a new value recomposes its digits ({key}/shown). |
|---|---|
| 键盘与消息 | msg(Edit::Draft(s)) while typing, Edit::Set(v) on Enter / steps / arrows / scrub, Edit::Cancel on Esc or blur. |
在网页上,每个控件都在页面里有一个带角色和名字的镜像元素,读屏软件和浏览器自己的焦点都看得到它(DESIGN.md §1.14)。
配方: 表单