DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Number fields are labelled by the icon that names them (accessibility)
paaspaas008ec58cc1cc8b
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rsindex 749115b31..690d8fc32 100644--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@ -579,8 +579,9 @@ fn icon_field(ui: &mut egui::Ui, icon: &str, tip: &str, field: NumField) -> Optilet (r, resp) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::hover());icons::paint(ui.painter(), r, icon, t.icon);resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, tip));+ let label = resp.id;resp.on_hover_text(tip);- field.spinner().show(ui)+ field.spinner().labelled_by(label).show(ui)}/// A column of two rows (the Control panel's two-row groups).@@ -1367,6 +1368,28 @@ fn community_card(app: &mut DesignApp, ui: &mut egui::Ui) {#[cfg(test)]mod tests {++ /// A Control panel field is labelled by its icon, so assistive technology reads "Tracking"+ /// (or "Font Size", …) with the value.+ #[test]+ fn icon_fields_are_labelled_by_their_icon() {+ use egui::accesskit::Role;+ let ctx = egui::Context::default();+ crate::theme::install_fonts(&ctx, "en");+ ctx.enable_accesskit();+ let mut update = None;+ for _ in 0..2 {+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {+ icon_field(ui, "tracking", "Tracking", NumField::number("tracking_test", Some(0.0), "", 0));+ });+ out.textures_delta.clear();+ update = out.platform_output.accesskit_update;+ }+ let update = update.expect("an AccessKit tree");+ let named = |n: &egui::accesskit::Node| n.label() == Some("Tracking") || n.value() == Some("Tracking");+ let icon = update.nodes.iter().find(|(_, n)| named(n)).map(|(id, _)| *id).expect("the icon's node");+ assert!(update.nodes.iter().any(|(_, n)| n.role() == Role::TextInput && n.labelled_by().contains(&icon)), "the editor names its icon");+ }use egui::{pos2, vec2};use egui_kittest::kittest::{NodeT, Queryable};diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex ff8447aba..8a2d03f65 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -1329,8 +1329,11 @@ fn half_field(ui: &mut Ui, b: Rect, right: bool, y: f32, half: f32, icon: &str,let x = if right { half + 10.0 } else { 0.0 };let ir = sub(b, x, y + 1.0, 19.0, 19.0);icons::paint(ui.painter(), ir, icon, t.icon);- ui.interact(ir, ui.id().with(("half_icon", icon)), Sense::hover()).on_hover_text(tip);- place(ui, sub(b, x + 24.0, y, half - 24.0, FIELD_H), |ui| field.width(half - 24.0).show(ui))+ let resp = ui.interact(ir, ui.id().with(("half_icon", icon)), Sense::hover());+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, tip));+ let label = resp.id;+ resp.on_hover_text(tip);+ place(ui, sub(b, x + 24.0, y, half - 24.0, FIELD_H), |ui| field.width(half - 24.0).labelled_by(label).show(ui))}/// Properties › Character after •••: vertical and horizontal scale, baseline shift and skew,diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 31fe194c2..d8eb6c51e 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -80,6 +80,8 @@ pub struct NumField<'a> {range: (f64, f64),enabled: bool,parens: bool,+ /// The widget naming the field (an icon or caption beside it), for accessibility.+ label: Option<egui::Id>,}impl<'a> NumField<'a> {@@ -90,7 +92,19 @@ impl<'a> NumField<'a> {Self::new(id, value, NumKind::Number { suffix, decimals })}fn new(id: &'a str, value: Option<f64>, kind: NumKind<'a>) -> Self {- NumField { id, value, kind, width: 72.0, spinner: false, presets: &[], step: None, range: (f64::MIN, f64::MAX), enabled: true, parens: false }+ NumField {+ id,+ value,+ kind,+ width: 72.0,+ spinner: false,+ presets: &[],+ step: None,+ range: (f64::MIN, f64::MAX),+ enabled: true,+ parens: false,+ label: None,+ }}/// Total width (spinner and preset segments included).pub fn width(mut self, w: f32) -> Self {@@ -130,6 +144,12 @@ impl<'a> NumField<'a> {self.enabled = on;self}+ /// The editor is labelled by widget `id` (an icon or caption that names the field), so+ /// assistive technology reads the field's name with its value.+ pub fn labelled_by(mut self, id: egui::Id) -> Self {+ self.label = Some(id);+ self+ }/// Draw the field; returns the new value when the user commits an edit (Enter, focus loss,/// a spinner click, ↑/↓ while focused (Shift = ×10) or a preset).@@ -210,6 +230,10 @@ impl<'a> NumField<'a> {editor_ui.disable();}let r = editor_ui.put(value_rect, te);+ let r = match self.label {+ Some(id) => r.labelled_by(id),+ None => r,+ };if r.has_focus() {// ↑/↓ step the value while typing.let (up, down, shift) = ui.input_mut(|i| {