From 523e240ca30b599552cbc7e0f42d78bc51344da8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 15:26:32 -0800 Subject: [PATCH] Tools: the one-column drawing-mode button reads as a plain button In one column the Tools rail shows a single drawing-mode button, named for the current mode, that cycles the modes. It took the selected look whenever the mode was not Draw Normal, so a screen reader read "Draw Normal (Shift+D), toggle button, not pressed" while Draw Normal was the current mode. The button now has no pressed state: it reads as a button named for the current mode, and it no longer takes the selected look in Draw Behind or Draw Inside. In two columns each of the three buttons still reads pressed when it is the current mode. --- crates/ui-egui/src/toolbar.rs | 18 +++++++++----- crates/ui-egui/src/toolbar/tests.rs | 37 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index b9f54527f7..dfbcb4c703 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -740,9 +740,14 @@ fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) { (vectorcraft_engine::DrawMode::Behind, "dc-draw-behind", "Draw Behind", "behind"), (vectorcraft_engine::DrawMode::Inside, "dc-draw-inside", "Draw Inside", "inside"), ]; - let mode_button = |ui: &mut Ui, icon: &'static str, name: &str, on: bool| { + // `on` is the pressed state of one of the three side-by-side buttons; the single one-column button has none. + let mode_button = |ui: &mut Ui, icon: &'static str, name: &str, on: Option| { let tip = format!("{} (Shift+D)", tl!(name)); - let button = IconButton::new(IconId::new(icon)).label(tip.clone()).tooltip(tip).selected(on); + let button = IconButton::new(IconId::new(icon)).label(tip.clone()).tooltip(tip); + let button = match on { + Some(on) => button.selected(on), + None => button, + }; // Small in two columns, where the three sit side by side in the rail's width. let button = if two { button.size(ControlSize::Sm) } else { button }; button.show(ui).clicked() @@ -754,15 +759,16 @@ fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) { // Side by side, each one a click away, a tight gap apart to fit the rail's width. Row::new().gap(Gap::Tight).show(ui, |ui, _| { for (mode, icon, name, id) in modes { - if mode_button(ui, icon, name, app.session.draw_mode == mode) { + if mode_button(ui, icon, name, Some(app.session.draw_mode == mode)) { run = Some(("view.drawMode", json!({ "mode": id }))); } } }); - } else if let Some((mode, icon, name, _)) = modes.into_iter().find(|m| m.0 == app.session.draw_mode) - && mode_button(ui, icon, name, mode != vectorcraft_engine::DrawMode::Normal) + } else if let Some((_, icon, name, _)) = modes.into_iter().find(|m| m.0 == app.session.draw_mode) + && mode_button(ui, icon, name, None) { - // One column: the current mode's button, which cycles them. + // One column: the current mode's button, named for it, which cycles them; it is always the + // current mode, so it has no pressed state. run = Some(("view.drawMode", json!({}))); } } diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index ee4b832ed2..e99a4dfa36 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -1,4 +1,4 @@ -use egui::accesskit::{Node, Role}; +use egui::accesskit::{Node, Role, Toggled}; use egui::{Event, PointerButton, Pos2}; use serde_json::json; use vectorcraft_engine::Session; @@ -306,6 +306,41 @@ fn the_paint_and_drawing_mode_buttons_fit_the_toolbar_width() { assert_eq!(app.session.draw_mode, vectorcraft_engine::DrawMode::Behind); } +/// A screen reader reads the drawing-mode buttons' state as the rail shows it, in every mode: in two columns the +/// current mode's button reads pressed and the other two not pressed; in one column the single button is named for the +/// current mode and cycles the modes, so it reads as a plain button with no pressed state. +#[test] +fn the_drawing_mode_buttons_report_the_current_mode() { + let mut app = app_with(200, 200); + let ctx = reader(); + // Draw Inside draws into one selected path. + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let modes = [("normal", "Draw Normal (Shift+D)"), ("behind", "Draw Behind (Shift+D)"), ("inside", "Draw Inside (Shift+D)")]; + let mut t0 = 0.0; + for double in [false, true] { + app.run("window.toolbarColumns", json!({ "double": double })).unwrap(); + for (current, _) in modes { + app.run("view.drawMode", json!({ "mode": current })).unwrap(); + let nodes = settled(&mut app, &ctx, t0, 900.0); + t0 += 10.0; + for (mode, label) in modes { + let node = nodes.iter().find(|n| n.label() == Some(label)); + if double { + let node = node.unwrap_or_else(|| panic!("two columns, {current:?}: {label} is drawn")); + let pressed = if mode == current { Toggled::True } else { Toggled::False }; + assert_eq!(node.toggled(), Some(pressed), "two columns, {current:?}: {label}"); + } else if mode == current { + let node = node.unwrap_or_else(|| panic!("one column, {current:?}: {label} is drawn")); + assert_eq!(node.role(), Role::Button, "one column, {current:?}: {label}"); + assert_eq!(node.toggled(), None, "one column, {current:?}: {label} has no pressed state"); + } else { + assert!(node.is_none(), "one column, {current:?}: {label} is not shown"); + } + } + } + } +} + /// A Learn link's tool in a collapsed group of the Tools panel opens that group's flyout with the tool in it, and /// chooses nothing: the rail reveals the located tool. #[test]