PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Give numeric type controls translated accessible names (#4310)
Lessa315c9cc0bcbd
diff --git a/crates/ui-egui/src/props_layout_tests.rs b/crates/ui-egui/src/props_layout_tests.rsindex 0b99569fe..8f7fbc15f 100644--- a/crates/ui-egui/src/props_layout_tests.rs+++ b/crates/ui-egui/src/props_layout_tests.rs@@ -175,8 +175,12 @@ fn type_controls_fill_the_panel_at_every_width_and_scale() {.map(|r| r.right()).fold(f32::MIN, f32::max);// (Both rows have a unit suffix: compare with the size/leading row.)- let top = fields.iter().map(|r| r.top()).fold(f32::MAX, f32::min);- let lead = fields.iter().filter(|r| (r.top() - top).abs() < 0.5).map(|r| r.right()).fold(f32::MIN, f32::max);+ // Variable-font axes can precede the size/leading row and have no unit suffix.+ // Compare the intended point-valued controls, retaining the same edge tolerance.+ let lead = ["Font size", "Leading (set to the font size × auto-leading when Auto)"]+ .into_iter()+ .map(|label| h.get_by_role_and_label(egui::accesskit::Role::SpinButton, label).rect().right())+ .fold(f32::MIN, f32::max);assert!((t_right - lead).abs() < 0.5, "{what}: Transform fields end at {t_right}, Character at {lead}");// Quick Actions buttons span the panel too.let qa = h.get_by_label("Rasterize Type").rect();diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rsindex 28d4d7c56..4bfa31227 100644--- a/crates/ui-egui/src/type_tool.rs+++ b/crates/ui-egui/src/type_tool.rs@@ -1733,8 +1733,14 @@ fn num_field(ui: &mut egui::Ui, label: &str, tip: &str, v: f32, range: std::ops:ui.spacing_mut().item_spacing.x = 4.0;let (r, resp) = ui.allocate_exact_size(egui::vec2(22.0, 22.0), egui::Sense::hover());ui.painter().text(r.center(), egui::Align2::CENTER_CENTER, label, crate::theme::semibold(10.0), t.text_dim);- crate::widgets::scrub_label(ui, &resp.on_hover_text(tip));- if crate::widgets::value_field(ui, &mut v, range, unit, width).changed() {+ crate::widgets::scrub_label(ui, &resp.on_hover_text(tl!(tip)));+ let response = crate::widgets::value_field(ui, &mut v, range, unit, width);+ response.widget_info(|| {+ let mut info = egui::WidgetInfo::drag_value(ui.is_enabled(), f64::from(v));+ info.label = Some(tl!(tip).to_owned());+ info+ });+ if response.changed() {out = Some(v);}});diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rsindex a6b045bc1..25011745e 100644--- a/crates/ui-egui/src/type_tool_tests.rs+++ b/crates/ui-egui/src/type_tool_tests.rs@@ -14,6 +14,33 @@ use super::{layout, text_layer};use crate::PhotocraftApp;use crate::canvas::ViewXform;+#[test]+fn numeric_type_fields_have_localized_accessible_names() {+ let pt = crate::i18n::Lang::from_code("pt-br").unwrap();+ let mut h = Harness::builder().build_ui_state(+ move |ui, value: &mut f32| {+ if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {+ return;+ }+ crate::i18n::with_language(pt, || {+ if let Some(next) = super::num_field(ui, "tT", "Font size", *value, 1.0..=999.0, "pt", 80.0) {+ *value = next;+ }+ });+ },+ 24.0,+ );+ PhotocraftApp::setup_context(&h.ctx, Default::default());+ h.run_steps(4);+ h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Tamanho da fonte").click();+ h.run();+ h.key_press_modifiers(Modifiers::COMMAND, egui::Key::A);+ h.event(egui::Event::Text("36".into()));+ h.key_press(egui::Key::Enter);+ h.run();+ assert_eq!(*h.state(), 36.0);+}+fn harness(ppp: f32, app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {make_harness(ppp, app, false)}@@ -1333,8 +1360,10 @@ mod multi_layer_formatting {h}- fn number(h: &mut Harness<'static, PhotocraftApp>, index: usize, value: &str) {- h.get_all_by_role(Role::SpinButton).nth(index).expect("numeric field").click();+ fn number(h: &mut Harness<'static, PhotocraftApp>, label: &str, value: &str) {+ // Variable-font axes add numeric fields before size/leading. Select the setting by+ // its accessible name, so a font scan cannot shift this action onto another control.+ h.get_by_role_and_label(Role::SpinButton, label).click();h.run();h.key_press_modifiers(Modifiers::COMMAND, egui::Key::A);h.event(egui::Event::Text(value.into()));@@ -1409,16 +1438,16 @@ mod multi_layer_formatting {let raster = LayerId(app.run("layer.new.layer", json!({"name": "Selected raster"})).unwrap()["layer"].as_u64().unwrap());selected(&mut app, &[ids[0], ids[1], raster]);let mut h = controls(app, true);- number(&mut h, 0, "60");+ number(&mut h, "Font size", "60");// Differ from the automatic 72 pt leading so this is an actual property change.- number(&mut h, 1, "84");+ number(&mut h, "Leading (set to the font size × auto-leading when Auto)", "84");h.get_by_label("Faux Bold").click();h.run();h.get_by_label("Center text").click();h.run();h.get_by_label("Hyphenate").click();h.run();- number(&mut h, 6, "9");+ number(&mut h, "Indent left margin", "9");for (id, scale) in [(ids[0], 2.0), (ids[1], 4.0)] {let c = style(h.state(), id, 0);assert_eq!(c.size_pt * scale, 60.0);@@ -1435,7 +1464,7 @@ mod multi_layer_formatting {let peer = text(h.state(), ids[1]).char_runs();editing(h.state_mut(), ids[0]);h.run();- number(&mut h, 0, "40");+ number(&mut h, "Font size", "40");assert_eq!((size_at(h.state(), ids[0], 0), size_at(h.state(), ids[0], 1), size_at(h.state(), ids[0], 3)), (30.0, 20.0, 30.0));assert_eq!(text(h.state(), ids[1]).char_runs(), peer);}