Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge upstream/main into feat-gap25-a11y-audit

vangel76133905ee7e2c
diff --cc crates/ui-egui/src/a11y.rs
index cca126876,000000000..43a0a3fe4
mode 100644,000000..100644
--- a/crates/ui-egui/src/a11y.rs
+++ b/crates/ui-egui/src/a11y.rs
@@@ -1,210 -1,0 +1,205 @@@
+//! Accessibility helpers (docs/gaps.md gap 25): names, roles and states for the widgets the app
+//! paints itself, and the small pieces of list keyboard handling the panels share.
+//!
+//! egui builds an AccessKit node for every widget that can take the keyboard focus, but a widget
+//! made with `ui.interact` has no name and no role until the panel says what it is. These helpers
+//! write that onto the widget's node *after* the widget is made each frame (egui rebuilds the
+//! tree every pass), and keep whatever egui already put there (its role for a `DragValue`, the
+//! numeric value of a `Slider`).
+//!
+//! Names are the same translated strings the panel draws (`i18n::tr`), never hard-coded English.
+//! `tests/ui_accessibility_audit.rs` walks the tree and fails on an unnamed control in the panels
+//! that have had their pass.
+
+use egui::accesskit::{HasPopup, Role, Toggled};
+use egui::{Context, Id, Response};
+
+/// Set `f` on `r`'s AccessKit node (nothing when AccessKit is off). egui only fills a node's
+/// bounds and actions for widgets that can take the keyboard focus; a widget that cannot (the
+/// non-current rows of a list) still needs both, or assistive technology cannot place or click it.
+fn node(r: &Response, f: impl FnOnce(&mut egui::accesskit::Node)) {
+ r.ctx.accesskit_node_builder(r.id, |n| {
+ n.set_bounds(egui::accesskit::Rect { x0: r.rect.min.x.into(), y0: r.rect.min.y.into(), x1: r.rect.max.x.into(), y1: r.rect.max.y.into() });
+ if r.sense.is_focusable() {
+ n.add_action(egui::accesskit::Action::Focus);
+ }
+ if r.sense.senses_click() {
+ n.add_action(egui::accesskit::Action::Click);
+ }
+ f(n);
+ });
+}
+
+/// Give `r`'s node a role and leave its name to the caller.
+pub(crate) fn role(r: &Response, role: Role) {
+ node(r, |n| n.set_role(role));
+}
+
+/// Give `r`'s node a role and a name.
+pub(crate) fn role_name(r: &Response, role: Role, label: &str) {
+ node(r, |n| {
+ n.set_role(role);
+ n.set_label(label);
+ });
+}
+
+/// Name `r`'s node (`label`), keeping the role egui gave it (spin button, slider, text input).
+pub(crate) fn name(r: &Response, label: &str) {
+ node(r, |n| n.set_label(label));
+}
+
++/// Give `r`'s node a current value and keep the name it already has.
++pub(crate) fn value(r: &Response, value: &str) {
++ node(r, |n| n.set_value(value));
++}
++
+/// Name `r`'s node and give it a current value (a spin button's or a text field's text).
+pub(crate) fn name_value(r: &Response, label: &str, value: &str) {
+ node(r, |n| {
+ n.set_label(label);
+ n.set_value(value);
+ });
+}
+
- /// Set `r`'s checked state (a check box, a switch, a toggle button).
- pub(crate) fn checked(r: &Response, on: bool) {
- node(r, |n| n.set_toggled(if on { Toggled::True } else { Toggled::False }));
- }
-
- /// Set `r`'s open state (a twirl, a disclosure).
- pub(crate) fn expanded(r: &Response, open: bool) {
- node(r, |n| n.set_expanded(open));
- }
-
+/// A push button; `enabled` false marks it disabled for assistive technology (it stays visible).
+pub(crate) fn button(r: &Response, label: &str, enabled: bool) {
+ node(r, |n| {
+ n.set_role(Role::Button);
+ n.set_label(label);
+ if !enabled {
+ n.set_disabled();
+ }
+ });
+}
+
+/// A button that opens a menu or popup: `open` is whether it is open now.
+pub(crate) fn menu_button(r: &Response, label: &str, open: bool) {
+ node(r, |n| {
+ n.set_role(Role::Button);
+ n.set_label(label);
+ n.set_has_popup(HasPopup::Menu);
+ n.set_expanded(open);
+ });
+}
+
+/// A button that shows or hides something (a twirl): `expanded` is the state it leads to from.
+pub(crate) fn disclosure(r: &Response, label: &str, expanded: bool) {
+ node(r, |n| {
+ n.set_role(Role::Button);
+ n.set_label(label);
+ n.set_expanded(expanded);
+ });
+}
+
+/// A check box.
+pub(crate) fn check_box(r: &Response, label: &str, checked: bool, enabled: bool) {
+ node(r, |n| {
+ n.set_role(Role::CheckBox);
+ n.set_label(label);
+ n.set_toggled(if checked { Toggled::True } else { Toggled::False });
+ if !enabled {
+ n.set_disabled();
+ }
+ });
+}
+
+/// A drop-down: `label` says what it sets and `value` is what it is set to.
+pub(crate) fn combo_box(r: &Response, label: &str, value: &str, enabled: bool) {
+ node(r, |n| {
+ n.set_role(Role::ComboBox);
+ n.set_label(label);
+ n.set_value(value);
+ n.set_has_popup(HasPopup::Menu);
+ n.set_expanded(false);
+ if !enabled {
+ n.set_disabled();
+ }
+ });
+}
+
+/// A row of a tree: selected, its depth (`level`, 1 at the top), whether it is open (`None` for a
+/// leaf) and its place among its siblings.
+pub(crate) fn tree_item(r: &Response, label: &str, selected: bool, level: usize, expanded: Option<bool>) {
+ node(r, |n| {
+ n.set_role(Role::TreeItem);
+ n.set_label(label);
+ n.set_selected(selected);
+ n.set_level(level);
+ if let Some(open) = expanded {
+ n.set_expanded(open);
+ }
+ });
+}
+
+/// An entry of a flat list: `position` is its 1-based place among `size`.
+pub(crate) fn list_item(r: &Response, label: &str, selected: bool, position: usize, size: usize) {
+ node(r, |n| {
+ n.set_role(Role::ListItem);
+ n.set_label(label);
+ n.set_selected(selected);
+ n.set_position_in_set(position);
+ n.set_size_of_set(size);
+ });
+}
+
+/// An entry of a menu or popup list; `checked` is `Some` for an entry that is on or off.
+pub(crate) fn menu_item(r: &Response, label: &str, checked: Option<bool>) {
+ node(r, |n| {
+ n.set_label(label);
+ match checked {
+ Some(on) => {
+ n.set_role(Role::MenuItemCheckBox);
+ n.set_toggled(if on { Toggled::True } else { Toggled::False });
+ }
+ None => n.set_role(Role::MenuItem),
+ }
+ });
+}
+
+/// A text field with a name (and its text as the value).
+pub(crate) fn text_input(r: &Response, label: &str, text: &str) {
+ node(r, |n| {
+ n.set_role(Role::TextInput);
+ n.set_label(label);
+ n.set_value(text);
+ });
+}
+
+/// A progress bar: `fraction` 0..=1 and the sentence it shows.
+pub(crate) fn progress(r: &Response, label: &str, fraction: f32) {
+ node(r, |n| {
+ n.set_role(Role::ProgressIndicator);
+ n.set_label(label);
+ n.set_min_numeric_value(0.0);
+ n.set_max_numeric_value(1.0);
+ n.set_numeric_value(f64::from(fraction.clamp(0.0, 1.0)));
+ });
+}
+
+// ------------------------------------------------------------------------------------------
+// List keyboard handling
+
+/// Ask for the keyboard focus on widget `id` once it is drawn (a list moves its focus to the row
+/// the arrow keys reached, which may not be focusable, or drawn, until the next pass). `key`
+/// names the list.
+pub(crate) fn focus_next_pass(ctx: &Context, key: &str, id: Id) {
+ let pass = ctx.cumulative_pass_nr();
- ctx.data_mut(|d| d.insert_temp(Id::new(("a11y-pending-focus", key)), (id, pass)));
++ ctx.data_mut(|d| d.insert_temp(Id::unique(("a11y-pending-focus", key)), (id, pass)));
+}
+
+/// True once, for the widget `focus_next_pass` named for list `key`: the caller then requests the
+/// focus. A request nobody answers within a few passes is dropped.
+pub(crate) fn take_pending_focus(ctx: &Context, key: &str, id: Id) -> bool {
- let slot = Id::new(("a11y-pending-focus", key));
++ let slot = Id::unique(("a11y-pending-focus", key));
+ let now = ctx.cumulative_pass_nr();
+ let Some((want, at)) = ctx.data(|d| d.get_temp::<(Id, u64)>(slot)) else { return false };
+ if now > at.saturating_add(4) {
+ ctx.data_mut(|d| d.remove::<(Id, u64)>(slot));
+ return false;
+ }
+ if want != id || now == at {
+ return false;
+ }
+ ctx.data_mut(|d| d.remove::<(Id, u64)>(slot));
+ true
+}
diff --cc crates/ui-egui/src/header.rs
index c1272c41d,2ad3dd20f..a8268f3f7
--- a/crates/ui-egui/src/header.rs
+++ b/crates/ui-egui/src/header.rs
@@@ -174,7 -174,7 +174,9 @@@ pub fn show(app: &mut EffectcraftApp, u
let snap = Rect::from_min_size(pos2(x, cy - 10.0), vec2(20.0, 20.0));
// The engine owns snapping (View ▸ Snapping); the checkbox mirrors it.
app.ui.snapping = app.session.state.snapping;
- if widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::new("snapping")).clicked() {
- if widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::unique("snapping")).clicked() {
++ let snap_resp = widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::unique("snapping"));
++ crate::a11y::check_box(&snap_resp, tr("Snapping"), app.ui.snapping, true);
++ if snap_resp.clicked() {
let _ = app.session.execute("view.snapping", serde_json::json!({}));
app.ui.snapping = app.session.state.snapping;
}
diff --cc crates/ui-egui/src/panels/effects_presets.rs
index 0d27b510a,3e4bd9275..36678a428
--- a/crates/ui-egui/src/panels/effects_presets.rs
+++ b/crates/ui-egui/src/panels/effects_presets.rs
@@@ -114,63 -112,6 +114,63 @@@ enum Apply
Preset(PresetRef),
}
+/// One row of the list as drawn this pass, including the rows scrolled out of view: what the
+/// arrow keys, Home / End and Enter work on (the rows are painted by hand, so this is the list).
+struct NavRow {
+ id: egui::Id,
+ /// The favourite star's widget, for an effect row.
+ star: Option<egui::Id>,
+ parent: Option<egui::Id>,
+ /// Where the row starts in the scrolled content.
+ top: f32,
+ /// A folder: (its key, open, forced open by a search).
+ folder: Option<(String, bool, bool)>,
+ /// What Enter applies, for an effect or preset row.
+ apply: Option<Apply>,
+}
+
+/// The list's keyboard state: the rows drawn, and the row the keys work from (the "cursor":
+/// selected, and the one Tab stop of the list).
+struct Nav {
+ rows: Vec<NavRow>,
+ /// The open folders on the way down to the row being drawn, by level.
+ stack: Vec<egui::Id>,
+ cursor: Option<egui::Id>,
+ /// The scroll offset and the list's top, to place rows in the content.
+ offset: f32,
+ list_top: f32,
+}
+
+impl Nav {
+ /// The row `id` is the list's Tab stop: the cursor row, or the first row while there is none.
+ fn tab_stop(&self, id: egui::Id) -> bool {
+ match self.cursor {
+ Some(c) => c == id,
+ None => self.rows.is_empty(),
+ }
+ }
+
+ /// Record the row drawn at `y`; returns whether it is the cursor row.
+ fn push(&mut self, id: egui::Id, y: f32, level: usize, folder: Option<(String, bool, bool)>, apply: Option<Apply>) -> bool {
+ let parent = level.checked_sub(2).and_then(|i| self.stack.get(i)).copied();
+ if folder.is_some() {
+ self.stack.truncate(level.saturating_sub(1));
+ self.stack.push(id);
+ }
+ self.rows.push(NavRow { id, star: None, parent, top: y - self.list_top + self.offset, folder, apply });
+ self.cursor == Some(id)
+ }
+}
+
+fn cursor_id() -> egui::Id {
- egui::Id::new("fx-cursor")
++ egui::Id::unique("fx-cursor")
+}
+
+/// The accessible name of a folder: what the row shows, in the interface language.
+fn folder_name(label: &str) -> &str {
+ tr(label)
+}
+
/// A folder row; returns whether it is open.
#[allow(clippy::too_many_arguments)]
fn folder_row(
@@@ -190,9 -129,6 +190,9 @@@
let t = app.tokens;
let open = forced_open || app.ui.effects_open.contains(key);
let r = Rect::from_min_size(pos2(list.min.x, *y), vec2(list.width(), ROW_H));
- let id = egui::Id::new(("fxcat", key));
++ let id = egui::Id::unique(("fxcat", key));
+ let tab = nav.tab_stop(id);
+ let selected = nav.push(id, *y, level, Some((key.to_string(), open, forced_open)), None);
*y += ROW_H;
if r.max.y < list.min.y || r.min.y > list.max.y {
return open;
@@@ -269,13 -174,6 +269,13 @@@ fn effect_row
let t = app.tokens;
let ctx = ui.ctx().clone();
let r = Rect::from_min_size(pos2(list.min.x, *y), vec2(list.width(), ROW_H));
- let id = egui::Id::new((auto_prefix, e.id));
- let star_id = egui::Id::new((auto_prefix, e.id, "star"));
++ let id = egui::Id::unique((auto_prefix, e.id));
++ let star_id = egui::Id::unique((auto_prefix, e.id, "star"));
+ let tab = nav.tab_stop(id);
+ let selected = nav.push(id, *y, level, None, Some(Apply::Effect(e.id.to_string())));
+ if let Some(row) = nav.rows.last_mut() {
+ row.star = Some(star_id);
+ }
*y += ROW_H;
if r.max.y < list.min.y || r.min.y > list.max.y {
return;
@@@ -347,9 -230,6 +347,9 @@@ fn preset_row
) {
let t = app.tokens;
let r = Rect::from_min_size(pos2(list.min.x, *y), vec2(list.width(), ROW_H));
- let id = egui::Id::new(("fxpreset", auto_id));
++ let id = egui::Id::unique(("fxpreset", auto_id));
+ let tab = nav.tab_stop(id);
+ let selected = nav.push(id, *y, 3, None, Some(Apply::Preset(preset.clone())));
*y += ROW_H;
if r.max.y < list.min.y || r.min.y > list.max.y {
return;
@@@ -376,123 -249,9 +376,123 @@@
}
}
+/// The list's keys. With a row focused (Tab, a screen reader): Up / Down move between rows,
+/// Home / End go to the first / last, Page Up / Page Down a page, Right opens a folder (then steps
+/// into it) and Left closes it (then steps out to it), Enter and Space apply the row or open /
+/// close the folder. With the mouse's last click in the panel and no widget focused, the arrows
+/// and Enter work the same, so the list is operable without a mouse either way. The focus follows
+/// the cursor, so a screen reader reads each row as it is reached. Returns what to apply.
+fn list_keys(app: &mut EffectcraftApp, ctx: &egui::Context, nav: &Nav, list: Rect) -> Option<Apply> {
+ use egui::Key;
+ // A cursor whose row is gone (a search hid it): the first row is the Tab stop again.
+ if let Some(c) = nav.cursor
+ && !nav.rows.iter().any(|r| r.id == c)
+ {
+ ctx.data_mut(|d| d.remove::<egui::Id>(cursor_id()));
+ ctx.request_repaint();
+ }
+ let focused = ctx.memory(|m| m.focused());
+ let on_row = focused.is_some_and(|f| nav.rows.iter().any(|r| r.id == f || r.star == Some(f)));
+ let by_mouse = focused.is_none() && app.ui.focused == crate::dock::PanelKind::EffectsPresets;
+ if (!on_row && !by_mouse) || app.dialog.is_some() || widgets::any_menu_open(ctx) {
+ return None;
+ }
+ let keys: Vec<Key> = ctx.input(|i| {
+ i.events
+ .iter()
+ .filter_map(|e| match e {
+ egui::Event::Key { key, pressed: true, modifiers, .. } if !modifiers.any() => Some(*key),
+ _ => None,
+ })
+ .collect()
+ });
+ let page = ((list.height() / ROW_H).floor() as usize).saturating_sub(1).max(1);
+ // The row with the keyboard focus is where the keys start (the first Tab lands on a row
+ // before anything is selected); otherwise the cursor.
+ let focus_row = focused.and_then(|f| nav.rows.iter().find(|r| r.id == f || r.star == Some(f))).map(|r| r.id);
+ let mut cursor = focus_row.or_else(|| nav.cursor.filter(|c| nav.rows.iter().any(|r| r.id == *c)));
+ let mut apply = None;
+ let mut moved = false;
+ for key in keys {
+ let at = cursor.and_then(|c| nav.rows.iter().position(|r| r.id == c));
+ let last = nav.rows.len().checked_sub(1)?;
+ let to = match key {
+ Key::ArrowDown => Some(at.map_or(0, |a| a.saturating_add(1).min(last))),
+ Key::ArrowUp => Some(at.map_or(last, |a| a.saturating_sub(1))),
+ Key::Home if on_row => Some(0),
+ Key::End if on_row => Some(last),
+ Key::PageDown if on_row => Some(at.map_or(0, |a| a.saturating_add(page).min(last))),
+ Key::PageUp if on_row => Some(at.map_or(last, |a| a.saturating_sub(page))),
+ Key::ArrowRight | Key::ArrowLeft | Key::Enter | Key::Space if at.is_some() => {
+ let row = at.and_then(|a| nav.rows.get(a))?;
+ let toggle = |app: &mut EffectcraftApp, open: bool| {
+ if let Some((k, _, forced)) = &row.folder
+ && !forced
+ {
+ if open {
+ app.ui.effects_open.insert(k.clone());
+ } else {
+ app.ui.effects_open.remove(k);
+ }
+ }
+ };
+ match (key, &row.folder) {
+ (Key::ArrowRight, Some((_, false, _))) => {
+ toggle(app, true);
+ None
+ }
+ (Key::ArrowRight, Some((_, true, _))) => at.map(|a| a.saturating_add(1).min(last)),
+ (Key::ArrowLeft, Some((_, true, false))) => {
+ toggle(app, false);
+ None
+ }
+ (Key::ArrowLeft, _) => row.parent.and_then(|p| nav.rows.iter().position(|r| r.id == p)),
+ (Key::Enter, Some((_, open, _))) | (Key::Space, Some((_, open, _))) if on_row || key == Key::Enter => {
+ toggle(app, !*open);
+ None
+ }
+ (Key::Enter, None) => {
+ apply = row.apply.clone();
+ None
+ }
+ (Key::Space, None) if on_row => {
+ apply = row.apply.clone();
+ None
+ }
+ _ => None,
+ }
+ }
+ _ => None,
+ };
+ if let Some(to) = to
+ && let Some(row) = nav.rows.get(to)
+ {
+ cursor = Some(row.id);
+ moved = true;
+ }
+ }
+ if moved && let Some(c) = cursor {
+ ctx.data_mut(|d| d.insert_temp(cursor_id(), c));
+ // Scroll the row into view.
+ if let Some(row) = nav.rows.iter().find(|r| r.id == c) {
- widgets::PanelScroll::reveal(ctx, egui::Id::new("fx-scroll"), row.top, row.top + ROW_H, list.height());
++ widgets::PanelScroll::reveal(ctx, egui::Id::unique("fx-scroll"), row.top, row.top + ROW_H, list.height());
+ }
+ app.ui.focused = crate::dock::PanelKind::EffectsPresets;
+ if on_row {
+ a11y::focus_next_pass(ctx, "fx", c);
+ }
+ ctx.request_repaint();
+ }
+ // The arrows are the list's, not egui's spatial focus moves.
+ if on_row {
+ ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
+ }
+ apply
+}
+
/// User preset files, rescanned every few seconds (and on Refresh List).
fn user_presets(ctx: &egui::Context, force: bool, scan: impl FnOnce() -> Vec<PresetFile>) -> Arc<Vec<PresetFile>> {
- let id = egui::Id::new("fx-user-presets");
+ let id = egui::Id::unique("fx-user-presets");
let now = ctx.input(|i| i.time);
if !force
&& let Some((at, v)) = ctx.data(|d| d.get_temp::<(f64, Arc<Vec<PresetFile>>)>(id))
@@@ -524,10 -281,8 +524,10 @@@ pub fn show(app: &mut EffectcraftApp, u
app.auto.add("effects.search", sr, "Search");
// Contents menu.
let mr = Rect::from_center_size(pos2(rect.max.x - 18.0, sr.center().y), vec2(22.0, 22.0));
- let mpop = egui::Id::new("fx-contents-menu");
- let menu_resp = widgets::icon_button(ui, mr, Icon::Hamburger, false, &t, egui::Id::new("fx-menu")).on_hover_text(tr("Effects & Presets options"));
+ let mpop = egui::Id::unique("fx-contents-menu");
- if widgets::icon_button(ui, mr, Icon::Hamburger, false, &t, egui::Id::unique("fx-menu")).on_hover_text(tr("Effects & Presets options")).clicked() {
++ let menu_resp = widgets::icon_button(ui, mr, Icon::Hamburger, false, &t, egui::Id::unique("fx-menu")).on_hover_text(tr("Effects & Presets options"));
+ a11y::menu_button(&menu_resp, tr("Effects & Presets options"), widgets::popup_is_open(ui, mpop));
+ if menu_resp.clicked() {
widgets::open_popup(ui, mpop);
}
app.auto.add("effects.menu", mr, "Effects & Presets options");
diff --cc crates/ui-egui/src/panels/properties.rs
index bd8756e1a,c9d759c16..4fcc53843
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@@ -247,8 -247,7 +247,8 @@@ fn transform_row(app: &mut EffectcraftA
p.text(pos2(r.min.x + 42.0, cy), Align2::LEFT_CENTER, &pr.name, Tokens::ui(12.0), t.text);
let vx = r.min.x + (r.width() * 0.5).max(130.0);
let label = Rect::from_min_max(pos2(r.min.x + 42.0, r.min.y), pos2(vx - 20.0, r.max.y));
- let resp = ui.interact(label, egui::Id::new(("props-label", uid)), Sense::click());
+ let resp = ui.interact(label, egui::Id::unique(("props-label", uid)), Sense::click());
+ crate::a11y::role_name(&resp, egui::accesskit::Role::Button, &pr.name);
app.auto.add(&format!("{base}.label"), label, &pr.name);
if resp.double_clicked() {
app.ui.timeline.search.clear();
diff --cc crates/ui-egui/src/panels/render_queue.rs
index 8423666db,ae5436296..1704dd92d
--- a/crates/ui-egui/src/panels/render_queue.rs
+++ b/crates/ui-egui/src/panels/render_queue.rs
@@@ -65,11 -64,6 +65,11 @@@ pub fn utc_stamp(unix: u64) -> String
format!("{y:04}-{}", t.format("%m-%d %H:%M:%S"))
}
+/// A queue item's row: its click area, keyboard focus and accessibility node.
+fn row_id(item: u64) -> egui::Id {
- egui::Id::new(("rq-row", item))
++ egui::Id::unique(("rq-row", item))
+}
+
fn status_color(t: &Tokens, s: &RenderStatus) -> Color32 {
match s {
RenderStatus::Done => Color32::from_rgb(0x6c, 0xc0, 0x6c),
@@@ -474,18 -468,14 +474,18 @@@ pub fn show(app: &mut EffectcraftApp, u
let render_b = Rect::from_min_size(pos2(top.max.x - 12.0 - bw, top.min.y + 34.0), vec2(bw, 26.0));
let stop_b = Rect::from_min_size(pos2(render_b.min.x - 8.0 - bw, render_b.min.y), vec2(bw, 26.0));
let can_render = !rendering && queue.iter().any(RenderQueueItem::is_queued) && !available.is_empty();
- let render_resp = widgets::text_button(ui, render_b, "Render", can_render, &t, egui::Id::new("rq-render"));
- if widgets::text_button(ui, render_b, "Render", can_render, &t, egui::Id::unique("rq-render")).clicked() && can_render {
++ let render_resp = widgets::text_button(ui, render_b, "Render", can_render, &t, egui::Id::unique("rq-render"));
+ a11y::button(&render_resp, "Render", can_render);
+ if render_resp.clicked() && can_render {
actions.push(("renderQueue.render", json!({"wait": false})));
}
app.auto.add("renderQueue.render", render_b, "Render");
// Notify (sound + notification when the queue finishes).
let notify = app.session.project.render_prefs.notify;
let nb = Rect::from_min_size(pos2(render_b.min.x - 8.0 - 2.0 * bw - 8.0, render_b.min.y + 4.0), vec2(18.0, 18.0));
- let notify_resp = widgets::checkbox(ui, nb, notify, &t, egui::Id::new("rq-notify"));
- if widgets::checkbox(ui, nb, notify, &t, egui::Id::unique("rq-notify")).clicked() {
++ let notify_resp = widgets::checkbox(ui, nb, notify, &t, egui::Id::unique("rq-notify"));
+ a11y::check_box(&notify_resp, tr("Notify"), notify, true);
+ if notify_resp.clicked() {
actions.push(("renderQueue.setNotify", json!({"notify": !notify})));
}
p.text(pos2(nb.max.x + 5.0, nb.center().y), Align2::LEFT_CENTER, tr("Notify"), Tokens::ui(11.5), t.text_dim);
@@@ -518,9 -508,8 +518,9 @@@
}
}
};
- p.text(pos2(bar.min.x + 8.0, bar.center().y), Align2::LEFT_CENTER, bar_text, Tokens::ui(11.5), t.text);
+ p.text(pos2(bar.min.x + 8.0, bar.center().y), Align2::LEFT_CENTER, &bar_text, Tokens::ui(11.5), t.text);
app.auto.add("renderQueue.progress", bar, &format!("{:.0}%", frac * 100.0));
- a11y::progress(&ui.interact(bar, egui::Id::new("rq-progress"), Sense::hover()), &bar_text, frac);
++ a11y::progress(&ui.interact(bar, egui::Id::unique("rq-progress"), Sense::hover()), &bar_text, frac);
// ---------------------------------------------------------- column header
let head = Rect::from_min_size(pos2(rect.min.x, top.max.y), vec2(rect.width(), HEAD_H));
@@@ -557,10 -546,7 +557,10 @@@
if queue.is_empty() {
lp.text(pos2(list.center().x, list.min.y + 30.0), Align2::CENTER_CENTER, tr("The render queue is empty."), Tokens::ui(12.0), t.text_faint);
}
+ let ctx = ui.ctx().clone();
+ // Where each item's row starts in the scrolled content, for the keys.
+ let mut tops: Vec<(u64, f32)> = Vec::new();
- let editing_id = egui::Id::new("rq-edit-output");
+ let editing_id = egui::Id::unique("rq-edit-output");
let mut editing: Option<(u64, String)> = ui.data(|d| d.get_temp(editing_id));
for (k, it) in queue.iter().enumerate() {
let n = k + 1;
@@@ -615,9 -592,7 +615,9 @@@
app.auto.add(&aid("row"), row, &format!("#{n}"));
let is_open = open.contains(&it.id);
let tw = Rect::from_center_size(pos2(cx_twirl + 8.0, row.center().y), vec2(14.0, 14.0));
- let tw_resp = widgets::twirl(ui, tw, is_open, egui::Id::new(("rq-twirl", it.id)), &t);
- if widgets::twirl(ui, tw, is_open, egui::Id::unique(("rq-twirl", it.id)), &t).clicked() {
++ let tw_resp = widgets::twirl(ui, tw, is_open, egui::Id::unique(("rq-twirl", it.id)), &t);
+ a11y::disclosure(&tw_resp, &tr_args(if is_open { "Hide details of {}" } else { "Show details of {}" }, &[&name]), is_open);
+ if tw_resp.clicked() {
if is_open {
open.retain(|i| *i != it.id);
} else {
@@@ -626,9 -601,7 +626,9 @@@
}
app.auto.add(&aid("twirl"), tw, "Twirl");
let cb = Rect::from_center_size(pos2(cx_render + 20.0, row.center().y), vec2(18.0, 18.0));
- let cb_resp = widgets::checkbox(ui, cb, it.render, &t, egui::Id::new(("rq-cb", it.id)));
- if widgets::checkbox(ui, cb, it.render, &t, egui::Id::unique(("rq-cb", it.id))).clicked() && !rendering {
++ let cb_resp = widgets::checkbox(ui, cb, it.render, &t, egui::Id::unique(("rq-cb", it.id)));
+ a11y::check_box(&cb_resp, &format!("{}: {name}", tr("Render")), it.render, !rendering);
+ if cb_resp.clicked() && !rendering {
actions.push(("renderQueue.setRender", json!({"item": it.id, "render": !it.render})));
}
app.auto.add(&aid("render"), cb, if it.render { "Render: on" } else { "Render: off" });
@@@ -644,10 -619,9 +644,10 @@@
let st_rect = Rect::from_min_size(pos2(cx_status, row.min.y), vec2(w_status, ROW_H));
lp.text(pos2(cx_status + 2.0, row.center().y), Align2::LEFT_CENTER, &status, Tokens::ui(12.0), status_color(&t, &it.status));
if let RenderStatus::Failed(e) = &it.status {
- ui.interact(st_rect, egui::Id::new(("rq-st", it.id)), Sense::hover()).on_hover_text(e);
+ ui.interact(st_rect, egui::Id::unique(("rq-st", it.id)), Sense::hover()).on_hover_text(e);
}
app.auto.add(&aid("status"), st_rect, &status);
+ a11y::tree_item(&row_resp, &format!("{n}. {name}, {status}"), is_sel, 1, Some(is_open));
if let Some(s) = it.started {
lp.text(pos2(cx_started + 2.0, row.center().y), Align2::LEFT_CENTER, utc_stamp(s), Tokens::ui(11.5), t.text_dim);
} else {
@@@ -677,11 -651,9 +677,11 @@@
};
lp.text(pos2(cx_num - 6.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::ui(11.5), t.text_dim);
let dd = Rect::from_min_size(pos2(ix + 70.0, r.min.y + 3.0), vec2(220.0, ROW_H - 6.0));
- let did = egui::Id::new(("rq-dd", it.id, sub));
+ let did = egui::Id::unique(("rq-dd", it.id, sub));
let shown: String = if summary.chars().count() > 31 { summary.chars().take(30).chain(std::iter::once('…')).collect() } else { summary.clone() };
- if widgets::dropdown(ui, dd, &shown, &t, did).clicked() && !rendering {
+ let dd_resp = widgets::dropdown(ui, dd, &shown, &t, did);
+ a11y::combo_box(&dd_resp, label.trim_end_matches(':'), &summary, !rendering);
+ if dd_resp.clicked() && !rendering {
widgets::open_popup(ui, did);
}
let labels: Vec<String> = menu.iter().map(|(l, _)| l.clone()).collect();
@@@ -715,10 -684,8 +715,10 @@@
// Log: Errors Only / Plus Settings / Plus Per Frame Info.
let ld = Rect::from_min_size(pos2(r.max.x - 190.0, r.min.y + 3.0), vec2(150.0, ROW_H - 6.0));
lp.text(pos2(ld.min.x - 6.0, r.center().y), Align2::RIGHT_CENTER, tr("Log:"), Tokens::ui(11.5), t.text_dim);
- let lid = egui::Id::new(("rq-log", it.id));
+ let lid = egui::Id::unique(("rq-log", it.id));
- if widgets::dropdown(ui, ld, it.log.label(), &t, lid).clicked() && !rendering {
+ let log_resp = widgets::dropdown(ui, ld, it.log.label(), &t, lid);
+ a11y::combo_box(&log_resp, tr("Log:").trim_end_matches(':'), it.log.label(), !rendering);
+ if log_resp.clicked() && !rendering {
widgets::open_popup(ui, lid);
}
let llabels: Vec<String> = RenderLog::ALL.iter().map(|l| mark(it.log == *l, l.label())).collect();
@@@ -735,15 -699,8 +735,15 @@@
let ox = dd.max.x + 14.0;
lp.text(pos2(ox, r.center().y), Align2::LEFT_CENTER, tr("Output To:"), Tokens::ui(11.5), t.text_dim);
let odd = Rect::from_min_size(pos2(ox + 62.0, r.min.y + 3.0), vec2(22.0, ROW_H - 6.0));
- let oid = egui::Id::new(("rq-out", it.id));
+ let oid = egui::Id::unique(("rq-out", it.id));
- if widgets::dropdown(ui, odd, "", &t, oid).clicked() && !rendering {
+ let out_resp = widgets::dropdown(ui, odd, "", &t, oid);
+ a11y::combo_box(
+ &out_resp,
+ tr("Output To:").trim_end_matches(':'),
+ &app.session.resolve_output(it).unwrap_or_else(|| "Not yet specified".into()),
+ !rendering,
+ );
+ if out_resp.clicked() && !rendering {
widgets::open_popup(ui, oid);
}
app.auto.add(&aid("outputTo"), odd, "Output To");
@@@ -782,8 -735,7 +782,8 @@@
}
} else {
let shown = app.session.resolve_output(it).unwrap_or_else(|| "Not yet specified".into());
- let resp = ui.interact(path_rect, egui::Id::new(("rq-path", it.id)), Sense::click());
+ let resp = ui.interact(path_rect, egui::Id::unique(("rq-path", it.id)), Sense::click());
+ a11y::button(&resp, &tr_args("Output file: {}", &[&shown]), !rendering);
let col = if resp.hovered() { t.accent_hover } else { t.hot_text };
lp.with_clip_rect(path_rect.intersect(list)).text(pos2(path_rect.min.x, r.center().y), Align2::LEFT_CENTER, &shown, Tokens::ui(11.5), col);
// Clicking the file name opens the save dialog (Output Movie To); Alt-click, or a
@@@ -813,69 -765,6 +813,69 @@@
None => d.remove::<(u64, String)>(editing_id),
});
+ // Keyboard: Up / Down move between the queued items, Home / End go to the first / last, Right
+ // and Left open and close the item's settings, Enter and Space do the same (Space only with a
+ // row focused: otherwise it plays the preview). The focus follows the selection.
+ let focused = ctx.memory(|m| m.focused());
+ let on_row = focused.is_some_and(|f| queue.iter().any(|i| row_id(i.id) == f));
+ let by_mouse = focused.is_none() && app.ui.focused == crate::dock::PanelKind::RenderQueue;
+ if (on_row || by_mouse) && editing.is_none() && app.dialog.is_none() && !widgets::any_menu_open(&ctx) {
+ let keys: Vec<egui::Key> = ctx.input(|i| {
+ i.events
+ .iter()
+ .filter_map(|e| match e {
+ egui::Event::Key { key, pressed: true, modifiers, .. } if !modifiers.any() => Some(*key),
+ _ => None,
+ })
+ .collect()
+ });
+ let mut moved = None;
+ for key in keys {
+ use egui::Key;
+ let at = selected.and_then(|s| queue.iter().position(|i| i.id == s));
+ let Some(last) = queue.len().checked_sub(1) else { break };
+ let to = match key {
+ Key::ArrowDown => Some(at.map_or(0, |a| a.saturating_add(1).min(last))),
+ Key::ArrowUp => Some(at.map_or(last, |a| a.saturating_sub(1))),
+ Key::Home if on_row => Some(0),
+ Key::End if on_row => Some(last),
+ _ => None,
+ };
+ if let Some(item) = to.and_then(|to| queue.get(to)) {
+ selected = Some(item.id);
+ moved = Some(item.id);
+ continue;
+ }
+ let Some(item) = selected.filter(|s| queue.iter().any(|i| i.id == *s)) else { continue };
+ match key {
+ Key::ArrowRight if !open.contains(&item) => open.push(item),
+ Key::ArrowLeft => open.retain(|i| *i != item),
+ Key::Enter | Key::Space if on_row || key == Key::Enter => {
+ if open.contains(&item) {
+ open.retain(|i| *i != item);
+ } else {
+ open.push(item);
+ }
+ }
+ _ => {}
+ }
+ }
+ if let Some(item) = moved {
+ if let Some((_, top)) = tops.iter().find(|(id, _)| *id == item) {
- widgets::PanelScroll::reveal(&ctx, egui::Id::new("rq-scroll"), *top, *top + ROW_H, list.height());
++ widgets::PanelScroll::reveal(&ctx, egui::Id::unique("rq-scroll"), *top, *top + ROW_H, list.height());
+ }
+ app.ui.focused = crate::dock::PanelKind::RenderQueue;
+ if on_row {
+ a11y::focus_next_pass(&ctx, "rq", row_id(item));
+ }
+ ctx.request_repaint();
+ }
+ // The arrows are the queue's, not egui's spatial focus moves.
+ if on_row {
+ ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
+ }
+ }
+
// Delete removes the selected item when the panel has focus.
if app.ui.focused == crate::dock::PanelKind::RenderQueue
&& editing.is_none()
diff --cc crates/ui-egui/src/panels/settings.rs
index 6ce282c91,a60272b4b..4c7340a30
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@@ -693,21 -671,11 +693,21 @@@ pub fn show(app: &mut EffectcraftApp, c
ui.vertical(|ui| {
ui.set_width(page_width + 4.0);
egui::ScrollArea::vertical().id_salt("settings-pages").max_height(body_h).auto_shrink([false, false]).show(ui, |ui| {
+ // One Tab stop for the list (the open page); Up / Down / Home / End move
+ // between the pages and the focus goes with them.
// The rows touch, so the pointer never falls between two of them.
ui.spacing_mut().item_spacing.y = 0.0;
- for p in &all {
- let (r, resp) = ui.allocate_exact_size(vec2(page_width, 24.0), egui::Sense::click());
+ let ctx = ui.ctx().clone();
- let page_item = |id: &str| egui::Id::new(("settings-page", id.to_string()));
++ let page_item = |id: &str| egui::Id::unique(("settings-page", id.to_string()));
+ let on_list = all.iter().any(|q| ctx.memory(|m| m.has_focus(page_item(q.id))));
+ for (n, p) in all.iter().enumerate() {
let sel = page == p.id;
+ let r = ui.allocate_space(vec2(page_width, 24.0)).1;
+ let resp = ui.interact(r, page_item(p.id), if sel { egui::Sense::click() } else { egui::Sense::CLICK });
+ a11y::list_item(&resp, crate::i18n::settings_page_title(p.title), sel, n + 1, all.len());
+ if a11y::take_pending_focus(&ctx, "settings", resp.id) {
+ resp.request_focus();
+ }
if sel {
ui.painter().rect_filled(r, 3.0, t.accent);
} else if resp.hovered() {
diff --cc crates/ui-egui/src/widgets.rs
index 9408bcb30,e54fe87c1..92311c68b
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@@ -257,10 -257,6 +257,7 @@@ pub fn twirl(ui: &mut Ui, rect: Rect, o
vec![c + vec2(-0.8 * k, -1.6 * k), c + vec2(0.8 * k, 0.0), c + vec2(-0.8 * k, 1.6 * k)]
};
ui.painter().add(egui::Shape::line(pts, Stroke::new(1.4, col)));
- // A button that opens and closes something; the caller names it.
- crate::a11y::role(&resp, egui::accesskit::Role::Button);
- crate::a11y::expanded(&resp, open);
+ focus_outline(ui, &resp, t);
resp
}
@@@ -274,10 -270,6 +271,7 @@@ pub fn icon_toggle(ui: &mut Ui, rect: R
if on || resp.hovered() {
icons::paint(ui.painter(), rect.shrink(rect.width() * 0.18), icon, if on { t.icon } else { t.text_faint });
}
- // A switch; the caller names it.
- crate::a11y::role(&resp, egui::accesskit::Role::Button);
- crate::a11y::checked(&resp, on);
+ focus_outline(ui, &resp, t);
resp
}
@@@ -348,11 -343,8 +347,11 @@@ fn field(ui: &mut Ui, rect: Rect, text
// As tall as the field, so the text and the hint sit on its middle (they sat high, #581).
.min_size(inner.size())
.font(Tokens::ui(12.0))
- .vertical_align(egui::Align::Center),
+ .align(egui::Align2::LEFT_CENTER),
- )
+ );
+ // The hint is the field's visible name (the caller can give it a better one).
+ crate::a11y::name(&resp, hint);
+ resp
}
/// Dropdown-looking control ("Full ▾").
@@@ -383,10 -384,6 +391,10 @@@ pub fn dropdown_tip(ui: &mut Ui, rect:
};
ui.painter().text(pos2(rect.min.x + 7.0, rect.center().y), Align2::LEFT_CENTER, shown, Tokens::ui(11.5), t.text);
icons::paint(ui.painter(), Rect::from_center_size(pos2(rect.max.x - 9.0, rect.center().y), vec2(8.0, 8.0)), Icon::ChevronDown, t.text_dim);
+ // A drop-down showing `text`; the caller names what it sets.
+ crate::a11y::role(&resp, egui::accesskit::Role::ComboBox);
- crate::a11y::name_value(&resp, "", text);
++ crate::a11y::value(&resp, text);
+ focus_outline(ui, &resp, t);
if let Some(tip) = tip {
return resp.on_hover_text(tip.to_string());
}
@@@ -423,10 -419,6 +432,7 @@@ pub fn checkbox(ui: &mut Ui, rect: Rect
let p = |x: f32, y: f32| pos2(b.min.x + x * b.width(), b.min.y + y * b.height());
ui.painter().line(vec![p(0.2, 0.52), p(0.42, 0.74), p(0.8, 0.28)], Stroke::new(1.6, Color32::WHITE));
}
- // A check box; the caller names it.
- crate::a11y::role(&resp, egui::accesskit::Role::CheckBox);
- crate::a11y::checked(&resp, on);
+ focus_outline(ui, &resp, t);
resp
}
@@@ -446,9 -438,7 +452,9 @@@ pub fn scroll_bar(ui: &mut Ui, auto: &m
let thumb_len = (len * len / (len + max.max(0.0)).max(1.0)).max(16.0).min(len).max(0.0);
let travel = (len - thumb_len).max(1.0);
let thumb_at = |s: f32| track.min[a] + (len - thumb_len) * if max > 0.0 { (s / max).clamp(0.0, 1.0) } else { 0.0 };
- let resp = ui.interact(track.expand2(if vertical { vec2(3.0, 0.0) } else { vec2(0.0, 3.0) }), egui::Id::unique(key), Sense::drag());
+ // Dragged with the mouse only: a Tab stop that no key could move would be a trap. The panels
+ // scroll with their own keys (the arrows, Page Up / Page Down) and the wheel.
- let resp = ui.interact(track.expand2(if vertical { vec2(3.0, 0.0) } else { vec2(0.0, 3.0) }), egui::Id::new(key), Sense::DRAG);
++ let resp = ui.interact(track.expand2(if vertical { vec2(3.0, 0.0) } else { vec2(0.0, 3.0) }), egui::Id::unique(key), Sense::DRAG);
let pressed = resp.is_pointer_button_down_on() && ui.input(|i| i.pointer.any_pressed());
let mut s = scroll;
if let Some(p) = resp.interact_pointer_pos().filter(|p| pressed && !(thumb_at(scroll)..=thumb_at(scroll) + thumb_len).contains(&p[a])) {
diff --cc crates/ui-egui/tests/ui_accessibility_audit.rs
index f55722d1e,000000000..acbbabf41
mode 100644,000000..100644
--- a/crates/ui-egui/tests/ui_accessibility_audit.rs
+++ b/crates/ui-egui/tests/ui_accessibility_audit.rs
@@@ -1,377 -1,0 +1,373 @@@
+//! Accessibility audit (docs/gaps.md gap 25): renders panels headless and walks the AccessKit
+//! tree of the frame. Every interactive node (button, check box, text input, combo box, slider,
+//! spin button, tree or list item, tab, link, ...) must have a non-empty name, a role that says
+//! what it is, and the state that role needs (checked, selected, a value).
+//!
+//! * The panels that had their pass (`FIXED`: Effects & Presets, Settings, Render Queue with its
+//! Templates dialog) must have **zero** findings.
+//! * Every other panel is counted and printed (run with `--nocapture`), and checked against
+//! [`BASELINE`], a ratchet that can only shrink: fixing a panel lowers its number, and a number
+//! must never go up. When a panel's count falls, lower its entry (the test says so).
+//!
+//! What this does not measure: how a real screen reader speaks the tree (none was run), colour
+//! contrast, focus order or keyboard operation (the `ui_*_keyboard.rs` tests cover those), or
+//! widgets that are scrolled out of view and not drawn.
+
+use std::collections::HashSet;
+
+use effectcraft_engine::Session;
+use effectcraft_ui_egui::EffectcraftApp;
+use effectcraft_ui_egui::dock::PanelKind;
+use egui::accesskit::{Action, Role, Toggled};
+use egui::{Rect, pos2};
+use egui_kittest::Harness;
+use egui_kittest::kittest::NodeT;
+use serde_json::json;
+
+/// Groups that must be clean. A group is the first part of a scenario name (before the `:`).
+const FIXED: &[&str] = &["EffectsPresets", "Settings", "RenderQueue", "Project"];
+
+/// (scenario, findings, of them unnamed controls) per not-yet-fixed scenario, as measured when
+/// this test was written (Effect Controls with one Gaussian Blur on the layer, every other panel
+/// as it opens). A ratchet: a number may only go down, never up; when a pass over a panel lowers
+/// it, lower its entry in the same change, and remove the entry (and add the panel to `FIXED`)
+/// when it reaches zero. A scenario that is not listed is held to zero.
+const BASELINE: &[(&str, usize, usize)] = &[
- ("EffectControls:default", 25, 15),
- ("Composition:default", 16, 14),
- ("Layer:default", 4, 3),
- ("Timeline:default", 83, 55),
++ ("EffectControls:default", 28, 14),
++ ("Composition:default", 4, 2),
++ ("Layer:default", 2, 1),
++ ("Timeline:default", 89, 42),
+ ("Audio:default", 4, 2),
- ("Preview:default", 5, 5),
- ("Properties:default", 45, 28),
- ("Character:default", 13, 9),
++ ("Properties:default", 47, 23),
++ ("Character:default", 8, 4),
+ ("Paragraph:default", 24, 12),
- ("Align:default", 18, 11),
- ("Tracker:default", 1, 1),
- ("Wiggler:default", 2, 2),
++ ("Align:default", 10, 2),
+ ("Smoother:default", 2, 1),
+ ("MotionSketch:default", 4, 2),
- ("Paint:default", 5, 3),
- ("Brushes:default", 16, 9),
- ("Flowchart:default", 8, 4),
++ ("Paint:default", 6, 3),
++ ("Brushes:default", 11, 2),
++ ("Flowchart:default", 5, 1),
+ ("History:default", 10, 5),
- ("Markers:default", 1, 1),
- ("MaskInterpolation:default", 2, 2),
- ("ScriptConsole:default", 5, 3),
- ("EssentialGraphics:default", 2, 2),
- ("Footage:default", 3, 2),
- ("Progress:default", 1, 1),
- ("VrCompEditor:default", 13, 7),
++ ("Markers:default", 2, 1),
++ ("MaskInterpolation:default", 2, 1),
++ ("ScriptConsole:default", 6, 3),
++ ("EssentialGraphics:default", 1, 1),
++ ("Footage:default", 2, 1),
++ ("VrCompEditor:default", 6, 0),
+];
+
+/// How many controls the fixed scenarios must at least show, so that "zero findings" is never
+/// the result of looking at nothing. Any scenario not listed needs 2.
+const MIN_CONTROLS: &[(&str, usize)] = &[
+ ("EffectsPresets:default", 10),
+ ("EffectsPresets:open", 10),
+ ("EffectsPresets:search", 5),
+ ("EffectsPresets:menu", 8),
+ ("Settings:general", 12),
+ ("Settings:appearance", 15),
+ ("Settings:labels", 30),
+ ("RenderQueue:queued", 8),
+ ("RenderQueue:expanded", 12),
+ ("RenderQueue:menu", 20),
+ ("RenderQueue:templates:renderSettings", 8),
+ ("RenderQueue:templates:outputModule", 8),
+];
+
+/// The roles that are controls: anything with one of these (or with a click or focus action) is
+/// held to the rules below.
+const CONTROL_ROLES: &[Role] = &[
+ Role::Button,
+ Role::CheckBox,
+ Role::ColorWell,
+ Role::ComboBox,
+ Role::Link,
+ Role::ListBoxOption,
+ Role::ListItem,
+ Role::MenuItem,
+ Role::MenuItemCheckBox,
+ Role::MenuItemRadio,
+ Role::MultilineTextInput,
+ Role::RadioButton,
+ Role::SearchInput,
+ Role::Slider,
+ Role::SpinButton,
+ Role::Switch,
+ Role::Tab,
+ Role::TextInput,
+ Role::TreeItem,
+];
+
+#[derive(Debug, Clone)]
+struct Finding {
+ scenario: String,
+ problem: &'static str,
+ role: Role,
+ name: String,
+ rect: [i32; 4],
+}
+
+impl std::fmt::Display for Finding {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "[{}] {}: {:?} {:?} at {:?}", self.scenario, self.problem, self.role, self.name, self.rect)
+ }
+}
+
+fn app_session() -> Session {
+ let mut s = Session::default();
+ s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 4})).unwrap();
+ s.execute("layer.newSolid", json!({"name": "Red", "color": "#c04040"})).unwrap();
+ s.execute("layer.newSolid", json!({"name": "Blue", "color": "#4040c0"})).unwrap();
+ s.execute("effect.apply", json!({"effect": "Gaussian Blur"})).ok();
+ s
+}
+
+fn harness() -> Harness<'static, EffectcraftApp> {
+ let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(app_session()));
+ h.run_steps(4);
+ h
+}
+
+fn invoke(h: &mut Harness<'_, EffectcraftApp>, id: &str, params: serde_json::Value) {
+ let ctx = h.ctx.clone();
+ effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, id, params).unwrap();
+ h.run_steps(4);
+}
+
+fn panel_rect(h: &Harness<'_, EffectcraftApp>, p: PanelKind) -> Option<Rect> {
+ let e = h.state().auto.find(&format!("panel.{}", p.id()))?;
+ Some(Rect::from_min_size(pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
+}
+
+fn dialog_rect(h: &Harness<'_, EffectcraftApp>, title: &str) -> Option<Rect> {
- h.ctx.memory(|m| m.area_rect(egui::Id::new(("modal", title))))
++ h.ctx.memory(|m| m.area_rect(egui::Id::unique(("modal", title))))
+}
+
+/// The ids of every node now, so a later audit can look at what appeared since (a popup).
+fn node_ids(h: &Harness<'_, EffectcraftApp>) -> HashSet<String> {
+ h.root().children_recursive().map(|n| format!("{:?}", n.accesskit_node().id())).collect()
+}
+
+/// Walk the tree and check every control whose centre is inside `scope` (and, when `since` is
+/// given, that was not in the tree before).
+fn audit(h: &Harness<'_, EffectcraftApp>, scenario: &str, scope: Rect, since: Option<&HashSet<String>>) -> (Vec<Finding>, usize) {
+ let mut out = Vec::new();
+ let mut controls = 0;
+ for n in h.root().children_recursive() {
+ let a = n.accesskit_node();
+ if a.is_hidden() {
+ continue;
+ }
+ let Some(b) = a.bounding_box() else {
+ // No bounds: assistive technology cannot place it. Only a control is a finding (and
+ // it is one wherever it is: there is no position to scope it by).
+ if CONTROL_ROLES.contains(&a.role()) {
+ out.push(Finding { scenario: scenario.to_string(), problem: "no bounds", role: a.role(), name: a.label().unwrap_or_default(), rect: [0; 4] });
+ }
+ continue;
+ };
+ if !scope.contains(pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)) {
+ continue;
+ }
+ if since.is_some_and(|s| s.contains(&format!("{:?}", a.id()))) {
+ continue;
+ }
+ let role = a.role();
+ let actionable = a.data().supports_action(Action::Click) || a.data().supports_action(Action::Focus);
+ let control = CONTROL_ROLES.contains(&role);
+ if !control && !(actionable && matches!(role, Role::Unknown | Role::GenericContainer)) {
+ continue;
+ }
+ let name = a.label().unwrap_or_default();
+ controls += 1;
+ let finding = |problem: &'static str| Finding {
+ scenario: scenario.to_string(),
+ problem,
+ role,
+ name: name.clone(),
+ rect: [b.x0 as i32, b.y0 as i32, b.x1 as i32, b.y1 as i32],
+ };
+ if !control && matches!(role, Role::Unknown | Role::GenericContainer) {
+ // Something you can click or focus, that no role describes.
+ out.push(finding("clickable or focusable without a control role"));
+ }
+ if name.trim().is_empty() {
+ out.push(finding("no name"));
+ }
+ let state_missing = match role {
+ Role::CheckBox | Role::RadioButton | Role::Switch | Role::MenuItemCheckBox | Role::MenuItemRadio => {
+ a.toggled().is_none() || a.toggled() == Some(Toggled::Mixed)
+ }
+ Role::Slider | Role::SpinButton => a.numeric_value().is_none(),
+ Role::ComboBox => a.value().is_none_or(|v| v.trim().is_empty()),
+ Role::TreeItem | Role::ListItem | Role::ListBoxOption | Role::Tab => a.is_selected().is_none(),
+ _ => false,
+ };
+ if state_missing {
+ out.push(finding("no state or value"));
+ }
+ }
+ (out, controls)
+}
+
+fn count_unnamed(f: &[Finding]) -> usize {
+ f.iter().filter(|f| f.problem == "no name").count()
+}
+
+struct Report {
+ findings: Vec<Finding>,
+ /// (scenario, findings, of them unnamed, controls looked at)
+ rows: Vec<(String, usize, usize, usize)>,
+}
+
+impl Report {
+ fn add(&mut self, scenario: &str, (f, controls): (Vec<Finding>, usize)) {
+ self.rows.push((scenario.to_string(), f.len(), count_unnamed(&f), controls));
+ self.findings.extend(f);
+ }
+}
+
+fn group(scenario: &str) -> &str {
+ scenario.split(':').next().unwrap_or(scenario)
+}
+
+fn collect() -> Report {
+ let mut r = Report { findings: vec![], rows: vec![] };
+
+ // ---- Effects & Presets: closed, everything open, searching, the contents menu.
+ let mut h = harness();
+ h.state_mut().show_panel(PanelKind::EffectsPresets);
+ h.run_steps(4);
+ let rect = panel_rect(&h, PanelKind::EffectsPresets).expect("Effects & Presets is drawn");
+ r.add("EffectsPresets:default", audit(&h, "EffectsPresets:default", rect, None));
+ {
+ let s = h.state_mut();
+ s.session.prefs.toggle_effect_favorite("ec.blur.gaussian");
+ s.ui.effects_open.insert("favorites".into());
+ s.ui.effects_open.insert("presets".into());
+ s.ui.effects_open.insert("presets/Text".into());
+ s.ui.effects_open.insert("Blur & Sharpen".into());
+ }
+ h.run_steps(4);
+ r.add("EffectsPresets:open", audit(&h, "EffectsPresets:open", rect, None));
+ h.state_mut().ui.effects_search = "blur".into();
+ h.run_steps(4);
+ r.add("EffectsPresets:search", audit(&h, "EffectsPresets:search", rect, None));
+ let before = node_ids(&h);
- h.ctx.data_mut(|d| d.insert_temp(egui::Id::new("fx-contents-menu").with("open"), true));
++ h.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("fx-contents-menu").with("open"), true));
+ h.run_steps(4);
+ let screen = Rect::from_min_size(pos2(0.0, 0.0), egui::vec2(1600.0, 1000.0));
+ r.add("EffectsPresets:menu", audit(&h, "EffectsPresets:menu", screen, Some(&before)));
+
+ // ---- Settings: every page.
+ let mut h = harness();
+ let before = node_ids(&h);
+ for page in effectcraft_engine::prefs::pages() {
+ invoke(&mut h, "app.settings", json!({"page": page.id}));
+ let name = format!("Settings:{}", page.id);
+ let rect = dialog_rect(&h, "Settings").expect("the Settings dialog is open");
+ r.add(&name, audit(&h, &name, rect, Some(&before)));
+ }
+
+ // ---- Render Queue: empty, queued and expanded, a menu open, the Templates dialogs.
+ let mut h = harness();
+ h.state_mut().show_panel(PanelKind::RenderQueue);
+ h.run_steps(4);
+ let rect = panel_rect(&h, PanelKind::RenderQueue).expect("the Render Queue is drawn");
+ r.add("RenderQueue:empty", audit(&h, "RenderQueue:empty", rect, None));
+ let comp = h.state().session.active_comp_id().expect("a comp").0;
+ let mut items = vec![];
+ for _ in 0..2 {
+ let out = h.state_mut().session.execute("renderQueue.add", json!({"comp": comp})).unwrap();
+ items.push(out["item"].as_u64().or_else(|| out["items"][0].as_u64()).unwrap_or(0));
+ }
+ h.run_steps(4);
+ r.add("RenderQueue:queued", audit(&h, "RenderQueue:queued", rect, None));
+ let first = h.state().session.project.render_queue.first().map(|i| i.id).expect("a queue item");
- h.ctx.data_mut(|d| d.insert_temp(egui::Id::new("rq-ui"), (vec![first], Some(first))));
++ h.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("rq-ui"), (vec![first], Some(first))));
+ h.run_steps(4);
+ r.add("RenderQueue:expanded", audit(&h, "RenderQueue:expanded", rect, None));
+ let before = node_ids(&h);
- h.ctx.data_mut(|d| d.insert_temp(egui::Id::new(("rq-dd", first, 0)).with("open"), true));
++ h.ctx.data_mut(|d| d.insert_temp(egui::Id::unique(("rq-dd", first, 0)).with("open"), true));
+ h.run_steps(4);
+ r.add("RenderQueue:menu", audit(&h, "RenderQueue:menu", screen, Some(&before)));
- h.ctx.data_mut(|d| d.insert_temp(egui::Id::new(("rq-dd", first, 0)).with("open"), false));
++ h.ctx.data_mut(|d| d.insert_temp(egui::Id::unique(("rq-dd", first, 0)).with("open"), false));
+ let before = node_ids(&h);
+ for (kind, title) in [("renderSettings", "Render Settings Templates"), ("outputModule", "Output Module Templates")] {
+ invoke(&mut h, "app.templates", json!({"kind": kind}));
+ let name = format!("RenderQueue:templates:{kind}");
+ let rect = dialog_rect(&h, title).expect("the Templates dialog is open");
+ r.add(&name, audit(&h, &name, rect, Some(&before)));
+ }
+ let _ = items;
+
+ // ---- Everything else, informational: each panel on its own.
+ let mut h = harness();
+ for p in PanelKind::ALL {
+ if matches!(p, PanelKind::EffectsPresets | PanelKind::RenderQueue) {
+ continue;
+ }
+ h.state_mut().show_panel(p);
+ h.run_steps(3);
+ let name = format!("{}:default", p.id());
+ let Some(rect) = panel_rect(&h, p) else {
+ r.rows.push((format!("{name} (not drawn)"), 0, 0, 0));
+ continue;
+ };
+ r.add(&name, audit(&h, &name, rect, None));
+ }
+ r
+}
+
+#[test]
+fn fixed_panels_have_no_unnamed_or_roleless_controls_and_the_others_do_not_get_worse() {
+ let report = collect();
+ println!("\nAccessibility audit: findings per scenario (unnamed in brackets)");
+ let mut by_group: Vec<(String, usize, usize, usize)> = vec![];
+ for (name, n, unnamed, controls) in &report.rows {
+ println!(" {name:<44} {n:>4} findings ({unnamed} unnamed) of {controls} controls");
+ let g = group(name).to_string();
+ match by_group.iter_mut().find(|(k, ..)| *k == g) {
+ Some(e) => {
+ e.1 += n;
+ e.2 += unnamed;
+ e.3 += controls;
+ }
+ None => by_group.push((g, *n, *unnamed, *controls)),
+ }
+ }
+ println!("\nBy panel (findings, unnamed controls, controls looked at):");
+ for (g, n, unnamed, controls) in &by_group {
+ let state = if FIXED.contains(&g.as_str()) { "fixed: must be 0" } else { "not yet audited" };
+ println!(" {g:<28} {n:>4} findings, {unnamed:>3} unnamed, {controls:>4} controls {state}");
+ }
+ let total_unnamed: usize = by_group.iter().map(|(_, _, u, _)| u).sum();
+ println!(" all panels: {total_unnamed} unnamed controls\n");
+
+ let mut failures = vec![];
+ for f in &report.findings {
+ if FIXED.contains(&group(&f.scenario)) {
+ failures.push(f.to_string());
+ }
+ }
+ assert!(failures.is_empty(), "{} accessibility findings in the fixed panels:\n{}", failures.len(), failures.join("\n"));
+
+ // A clean panel must not be clean because nothing was looked at.
+ for (name, _, _, controls) in &report.rows {
+ if FIXED.contains(&group(name)) {
+ let min = MIN_CONTROLS.iter().find(|(k, _)| k == name).map_or(2, |(_, v)| *v);
+ assert!(*controls >= min, "{name}: only {controls} controls found in the tree (expected {min}); the scenario is not showing the panel");
+ }
+ }
+
+ for (name, n, unnamed, _) in &report.rows {
+ if FIXED.contains(&group(name)) {
+ continue;
+ }
+ let (allowed, allowed_unnamed) = BASELINE.iter().find(|(k, ..)| k == name).map_or((0, 0), |(_, v, u)| (*v, *u));
+ assert!(*n <= allowed, "{name}: {n} findings, the baseline allows {allowed}; a panel must not get worse");
+ assert!(*unnamed <= allowed_unnamed, "{name}: {unnamed} unnamed controls, the baseline allows {allowed_unnamed}; a panel must not get worse");
+ if *n < allowed || *unnamed < allowed_unnamed {
+ println!("note: {name} improved to {n} findings ({unnamed} unnamed); lower its BASELINE entry from {allowed} ({allowed_unnamed})");
+ }
+ }
+}