Merge pull request #9344 from dotCooCoo/fix/transform-each-field-names

Transform Each: screen readers tell the Scale and Move fields apart
This commit is contained in:
BFlat
2026-11-26 08:41:17 +07:00
committed by GitHub
2 changed files with 63 additions and 12 deletions
+47
View File
@@ -429,6 +429,53 @@ fn the_transform_effect_dialog_has_its_controls_previews_them_and_shows_them_aga
assert_eq!((flag(&app, "objects"), flag(&app, "strokes")), (true, true));
}
/// The names of the sliders and number fields in the window's access tree.
fn slider_and_field_names(app: &mut VectorcraftApp) -> Vec<String> {
let out = frame(app, vec![]);
let update = out.platform_output.accesskit_update.expect("an accessibility tree");
update
.nodes
.iter()
.filter(|(_, node)| matches!(node.role(), Role::TextInput | Role::SpinButton | Role::Slider))
.filter_map(|(_, node)| node.label())
.map(str::to_owned)
.collect()
}
/// Each Scale and Move slider and number field carries its row in its name, so the two Horizontal and two Vertical
/// labels are told apart; the visible labels only describe them.
fn assert_scale_and_move_names(names: &[String]) {
for name in ["Scale Horizontal:", "Scale Vertical:", "Move Horizontal:", "Move Vertical:"] {
let count = names.iter().filter(|n| n.as_str() == name).count();
assert_eq!(count, 2, "a slider and a number field named {name}: {names:?}");
}
for bare in ["Horizontal:", "Vertical:"] {
assert!(!names.iter().any(|n| n == bare), "no control named only {bare}: {names:?}");
}
}
/// Effect > Distort & Transform > Transform names its Scale and Move controls by their row.
#[test]
fn the_transform_effect_names_scale_and_move_controls_by_their_row() {
let mut app = app();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
app.run("select.all", json!({})).unwrap();
app.run("effect.dialog", json!({"effect": "distort.transform"})).unwrap();
settle(&mut app);
assert_scale_and_move_names(&slider_and_field_names(&mut app));
}
/// Object > Transform > Transform Each shares the rows, and so the names.
#[test]
fn transform_each_names_scale_and_move_controls_by_their_row() {
let mut app = app();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 60, "height": 20})).unwrap();
app.run("select.all", json!({})).unwrap();
open_each(&mut app, false);
settle(&mut app);
assert_scale_and_move_names(&slider_and_field_names(&mut app));
}
/// Transform Each opened by its menu item, on Absolute when `absolute` (as it was last confirmed).
fn open_each(app: &mut VectorcraftApp, absolute: bool) {
if absolute {
+16 -12
View File
@@ -17,7 +17,7 @@
use craft::behavior::Mixed;
use craft::ui::choice::{Checkbox, Radio, RadioGroup};
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use craft::ui::contract::{Bind, FieldLabelRole, Props as _, Show as _, ShowContainer as _, SideLabel};
use craft::ui::dialog::{DialogHost, DialogId, FieldRefusal};
use craft::ui::display::Text;
use craft::ui::form::Field;
@@ -290,30 +290,32 @@ enum Measure {
}
/// One captioned side: a slider over `rail` and a number field in ±`limit`, `value` being none
/// while the objects differ (the field reads Mixed). Returns the value the user set this pass.
/// while the objects differ (the field reads Mixed). `caption` is the row (Scale or Move) and the
/// visible label; the label repeats in each row, so it only describes the controls, and their
/// names start with the row. Returns the value the user set this pass.
fn side(
ui: &mut Ui,
key: &'static str,
label: impl Into<Label>,
(row, label): (&'static str, &'static str),
value: Option<f64>,
measure: Measure,
rail: &RangeInclusive<f64>,
limit: f64,
) -> Option<f64> {
let label: Label = label.into();
let name: Label = format!("{row} {label}").into();
let mut edit = None;
Field::new(label.clone()).id_salt(key).show(ui, |ui, _| {
Field::new(label).side(SideLabel::new().role(FieldLabelRole::Describes)).id_salt(key).show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
let shown = value.map_or(Mixed::Mixed, |v| Mixed::Same(Some(v)));
let dragged = Slider::new(Bind::given(value.map_or(Mixed::Mixed, |v| Mixed::Same(v.clamp(*rail.start(), *rail.end())))), rail.clone())
.label(label.clone())
.label(name.clone())
.id_salt("slider")
.show(ui)
.value()
.copied();
let field = match measure {
Measure::Percent => NumberField::new(label.clone(), Bind::given(shown)).unit_kind(UnitKind::Percent),
Measure::Length(lengths) => NumberField::length(label.clone(), Bind::given(shown), lengths),
Measure::Percent => NumberField::new(name.clone(), Bind::given(shown)).unit_kind(UnitKind::Percent),
Measure::Length(lengths) => NumberField::length(name.clone(), Bind::given(shown), lengths),
};
let typed = field.range(-limit..=limit).id_salt("field").show(ui).edit.value().cloned().flatten();
edit = typed.or(dragged);
@@ -361,11 +363,12 @@ pub(crate) fn rows(ui: &mut Ui, fields: &mut DialogFields, lengths: LengthUnits,
let (mut angle, mut toggled, mut mode) = (None, None, None);
let read: &DialogFields = fields;
let shown = Stack::new().show(ui, |ui, _| {
Text::new(tl!("Scale")).show(ui);
let scale = tl!("Scale");
Text::new(scale).show(ui);
Row::new().show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
for (at, (key, label)) in [(hk, tl!("Horizontal:")), (vk, tl!("Vertical:"))].into_iter().enumerate() {
scales[at] = side(ui, key, label, field_number(read, key), measure, &rail, limit);
scales[at] = side(ui, key, (scale, label), field_number(read, key), measure, &rail, limit);
}
});
if link == ScaleLink::Toggle {
@@ -375,9 +378,10 @@ pub(crate) fn rows(ui: &mut Ui, fields: &mut DialogFields, lengths: LengthUnits,
if link == ScaleLink::Toggle {
mode = mode_radios(ui, !absolute);
}
Text::new(tl!("Move")).show(ui);
let shift = tl!("Move");
Text::new(shift).show(ui);
for (at, (key, label)) in [("moveH", tl!("Horizontal:")), ("moveV", tl!("Vertical:"))].into_iter().enumerate() {
moves[at] = side(ui, key, label, Some(num(read, key, 0.0)), Measure::Length(lengths), &MOVE_RAIL, MAX_ABSOLUTE);
moves[at] = side(ui, key, (shift, label), Some(num(read, key, 0.0)), Measure::Length(lengths), &MOVE_RAIL, MAX_ABSOLUTE);
}
Text::new(tl!("Rotate")).show(ui);
angle = rotate_row(ui, num(read, "rotate", 0.0));