DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Label the object Control panel's captions and chips for screen readers
moppeeerb57d96a58304
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rsindex c5f519bf1..8f9fcb454 100644--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@ -598,7 +598,7 @@ mod tests {use crate::test_window::{self, wheel};/// The Control panel's last control with nothing selected.- const LAST_CONTROL: &str = "Jump to Next Column";+ const LAST_CONTROL: &str = "Align bottom edges";const FIRST_CONTROL: &str = "Rotate 90° Counterclockwise";fn app() -> crate::DesignApp {@@ -647,7 +647,7 @@ mod tests {assert_eq!(test_window::panel_rect(&h, "control_bar").height(), bar.height(), "the bar keeps its height");// A popup opened from a scrolled control opens at that control.let fill = h.get_by_label("Fill").rect();- let chip = pos2(fill.max.x + 15.0, fill.center().y);+ let chip = fill.center();h.hover_at(chip);h.drag_at(chip);h.drop_at(chip);diff --git a/crates/ui-egui/src/object_control.rs b/crates/ui-egui/src/object_control.rsindex 0000caf8f..7c2634e23 100644--- a/crates/ui-egui/src/object_control.rs+++ b/crates/ui-egui/src/object_control.rs@@ -1,7 +1,7 @@//! The object Control panel: fixed, compact two-row groups, independent of widget layout growth.use designcraft_geom::{Unit, corners::CornerShape};-use egui::{Rect, Sense, Ui, vec2};+use egui::{Color32, Rect, Sense, Ui, vec2};use serde_json::{Value, json};use crate::panels::{self, properties};@@ -32,7 +32,9 @@ fn cell<R>(ui: &mut Ui, group: Rect, x: f32, row: usize, width: f32, enabled: bofn icon(ui: &mut Ui, group: Rect, x: f32, row: usize, name: &str, tip: &str) {let rect = Rect::from_min_size(group.min + vec2(x, row as f32 * ROW_PITCH + 2.5), vec2(16.0, 16.0));icons::paint(ui.painter(), rect, name, Tokens::get(ui.ctx()).icon);- ui.interact(rect, ui.id().with(("caption", name, row)), Sense::hover()).on_hover_ui(|ui| {+ let resp = ui.interact(rect, ui.id().with(("caption", name, row)), Sense::hover());+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, tip));+ resp.on_hover_ui(|ui| {crate::rtl::label(ui, tip);});}@@ -149,8 +151,9 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {separator(ui);group(ui, "appearance", 224.0, |ui, rect| {for (row, stroke) in [(0, false), (1, true)] {- cell(ui, rect, 0.0, row, 30.0, selected, |ui| {- panels::swatch_picker(+ // The chips open with nothing selected too, as they always have.+ cell(ui, rect, 0.0, row, 30.0, true, |ui| {+ let chip_resp = panels::swatch_picker(app,ui,if stroke { "ctlstroke" } else { "ctlfill" },@@ -161,7 +164,7 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {);let chip = Rect::from_min_size(rect.min + vec2(0.0, row as f32 * ROW_PITCH + 1.5), vec2(18.0, 18.0));if stroke && let Some(doc) = app.session.active().map(|st| &st.doc) {- let (color, gradient) = info.as_ref().map_or((Some(egui::Color32::GRAY), None), |i| widgets::swatch_colors(doc, &i.stroke, 1.0));+ let (color, gradient) = info.as_ref().map_or((Some(Color32::GRAY), None), |i| widgets::swatch_colors(doc, &i.stroke, 1.0));let inner = Tokens::get(ui.ctx()).panel;if gradient.is_some() {widgets::paint_chip(ui.painter(), chip, color, gradient);@@ -170,7 +173,11 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {widgets::paint_stroke_chip(ui.painter(), chip, color, inner);}}- ui.interact(chip, ui.id().with("swatch_tip"), Sense::hover()).on_hover_text(tr(if stroke { "Stroke" } else { "Fill" }));+ if let Some(resp) = chip_resp {+ let label = tr(if stroke { "Stroke" } else { "Fill" });+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, &label));+ resp.on_hover_text(label);+ }});}icon(ui, rect, 36.0, 0, "panel-stroke", &tr("Stroke Weight"));@@ -282,8 +289,10 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {});if let Some(columns) = info.as_ref().and_then(|i| i.columns) {separator(ui);- group(ui, "columns", 48.0, |ui, rect| {- icon(ui, rect, 0.0, 0, "text-columns", &tr("Columns"));+ let caption = tr("Columns");+ let caption_w = ui.painter().layout_no_wrap(caption.clone(), egui::FontId::proportional(widgets::LABEL_SIZE), Color32::PLACEHOLDER).size().x;+ group(ui, "columns", (caption_w + 2.0).ceil().max(48.0), |ui, rect| {+ cell(ui, rect, 0.0, 0, rect.width(), true, |ui| widgets::caption(ui, &caption));if let Some(v) = cell(ui, rect, 0.0, 1, 48.0, true, |ui| {NumField::number("ccols", Some(columns as f64), "", 0).width(48.0).spinner().range(1.0, 100.0).show(ui)}) {diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rsindex 581f6747e..2a07f34ed 100644--- a/crates/ui-egui/src/panels/mod.rs+++ b/crates/ui-egui/src/panels/mod.rs@@ -181,42 +181,53 @@ pub fn swatch_menu_row(ui: &mut egui::Ui, doc: &designcraft_doc::Document, name:resp.clicked()}-/// A swatch dropdown showing a chip and name; `on_pick` gets the chosen swatch name.-pub fn swatch_picker(app: &mut DesignApp, ui: &mut egui::Ui, id: &str, current: Option<String>, on_pick: impl FnOnce(&mut DesignApp, String)) {- let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return };+/// A swatch dropdown showing a chip and name; `on_pick` gets the chosen swatch name. Returns the+/// chip's response (`None` without a document), for a caller to label or annotate.+pub fn swatch_picker(+ app: &mut DesignApp,+ ui: &mut egui::Ui,+ id: &str,+ current: Option<String>,+ on_pick: impl FnOnce(&mut DesignApp, String),+) -> Option<egui::Response> {+ let doc = app.session.active().map(|d| d.doc.clone())?;let cur = current.unwrap_or_default();let (c, g) = crate::widgets::swatch_colors(&doc, &cur, 1.0);let mut picked = None;- ui.push_id(id, |ui| {- let (r, resp) = ui.allocate_exact_size(vec2(30.0, 18.0), egui::Sense::click());- crate::widgets::paint_chip(- ui.painter(),- egui::Rect::from_min_size(r.min, vec2(18.0, 18.0)),- if cur.is_empty() { Some(egui::Color32::GRAY) } else { c },- g,- );- crate::icons::paint(- ui.painter(),- egui::Rect::from_min_size(r.min + vec2(18.0, 3.0), vec2(12.0, 12.0)),- "chevron-down",- Tokens::get(ui.ctx()).icon,- );- egui::Popup::menu(&resp).show(|ui| {- ui.set_min_width(200.0);- ui.set_max_width(280.0);- egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {- for sw in &doc.swatches {- if swatch_menu_row(ui, &doc, &sw.name, &cur) {- picked = Some(sw.name.clone());- ui.close();+ let resp = ui+ .push_id(id, |ui| {+ let (r, resp) = ui.allocate_exact_size(vec2(30.0, 18.0), egui::Sense::click());+ crate::widgets::paint_chip(+ ui.painter(),+ egui::Rect::from_min_size(r.min, vec2(18.0, 18.0)),+ if cur.is_empty() { Some(egui::Color32::GRAY) } else { c },+ g,+ );+ crate::icons::paint(+ ui.painter(),+ egui::Rect::from_min_size(r.min + vec2(18.0, 3.0), vec2(12.0, 12.0)),+ "chevron-down",+ Tokens::get(ui.ctx()).icon,+ );+ egui::Popup::menu(&resp).show(|ui| {+ ui.set_min_width(200.0);+ ui.set_max_width(280.0);+ egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {+ for sw in &doc.swatches {+ if swatch_menu_row(ui, &doc, &sw.name, &cur) {+ picked = Some(sw.name.clone());+ ui.close();+ }}- }+ });});- });- });+ resp+ })+ .inner;if let Some(p) = picked {on_pick(app, p);}+ Some(resp)}/// A five-pointed star (filled, or outlined).diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 47cb31711..dcb010b31 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -396,7 +396,9 @@ pub fn caption(ui: &mut Ui, s: &str) {/// A right-aligned caption of a fixed width (`W:` before a spinner).pub fn caption_w(ui: &mut Ui, s: &str, w: f32) {let t = Tokens::get(ui.ctx());- let (r, _) = ui.allocate_exact_size(vec2(w, FIELD_H), Sense::hover());+ let (r, resp) = ui.allocate_exact_size(vec2(w, FIELD_H), Sense::hover());+ // Painted, so tell screen readers (and UI tests) what it says.+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, s));crate::rtl::paint(ui.painter(), pos2(r.max.x - 2.0, r.center().y), egui::Align2::RIGHT_CENTER, s, egui::FontId::proportional(11.5), t.text);}