From f999960347aeebcacc0643adf5c794e1438bddd0 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 21:30:47 +0000 Subject: [PATCH 1/7] chore: start Burn and Dodge tooltip fix From f311f06cbdb2bb42a3c3a1aaae3e6c227fb91227 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 21:31:30 +0000 Subject: [PATCH 2/7] fix(ui): add translated Burn and Dodge control tooltips --- crates/ui-egui/src/tools/retouch_ui.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 21d589e8dd..7f343e3f7d 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -832,8 +832,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo opt(ui, tl!("Range:")); let opts = [("shadows".to_string(), tl!("Shadows")), ("midtones".to_string(), tl!("Midtones")), ("highlights".to_string(), tl!("Highlights"))]; crate::widgets::dropdown(ui, "tone-range", tl!("Range"), &mut o.tone_range, &opts, 100.0); - pct(ui, tl!("Exposure:"), &mut o.exposure); - crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")); + if let Some(range) = ui.ctx().read_response(ui.make_persistent_id(egui::IdSalt::new("tone-range"))) { + range.on_hover_text(tl!("Painting Mode")); + } + opt(ui, tl!("Exposure:")); + crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0).on_hover_text(tl!("Set exposure for stroke")); + crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")) + .on_hover_text(tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue")); } Tool::Sponge => { opt(ui, tl!("Mode:")); From 076e82956b5c4b5fa0a02528fb600373f22fd78b Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 21:51:07 +0000 Subject: [PATCH 3/7] test(ui): cover Burn and Dodge hover interactions and narrow layouts --- crates/ui-egui/src/burn_bar_tooltips_tests.rs | 208 ++++++++++++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 14 +- 2 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 crates/ui-egui/src/burn_bar_tooltips_tests.rs diff --git a/crates/ui-egui/src/burn_bar_tooltips_tests.rs b/crates/ui-egui/src/burn_bar_tooltips_tests.rs new file mode 100644 index 0000000000..c3f4ab9d14 --- /dev/null +++ b/crates/ui-egui/src/burn_bar_tooltips_tests.rs @@ -0,0 +1,208 @@ +//! #12670: hover the actual shared Burn/Dodge controls, then use them with the pointer and keys. + +use egui::accesskit::Role; +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::i18n::{Lang, tr}; +use crate::state::Tool; + +const CONTROLS: [(Role, &str, &str); 3] = [ + (Role::ComboBox, "Range:", "Painting Mode"), + (Role::SpinButton, "Exposure:", "Set exposure for stroke"), + (Role::CheckBox, "Protect Tones", "Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), +]; + +fn bar(tool: Tool, lang: Lang, width: f32, scale: f32, narrow: bool) -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 80, "height": 80})).unwrap(); + app.run("prefs.set", json!({"path": "workspace.enableNarrowOptionsBar", "value": narrow})).unwrap(); + app.ui.tool = tool; + let mut h = Harness::builder() + .with_size(vec2(width / scale, 300.0)) + .with_pixels_per_point(scale) + .with_step_dt(1.0 / 60.0) + .with_context_setup(|ctx| PhotocraftApp::setup_context(ctx, crate::theme::ThemeKind::ProMedium)) + .build_ui_state( + move |ui, app| { + let _language = crate::i18n::language_scope(lang); + crate::panels::options_bar(app, ui); + }, + app, + ); + h.run_steps(4); + h +} + +fn control<'a>(h: &'a Harness<'static, PhotocraftApp>, role: Role, label: &str) -> egui_kittest::Node<'a> { + h.query_all_by_role(role).find(|n| n.accesskit_node().label().as_deref() == Some(label)).unwrap_or_else(|| panic!("missing {role:?} {label:?}")) +} + +fn hover(h: &mut Harness<'static, PhotocraftApp>, role: Role, label: &str, tip: &str) { + control(h, role, label).scroll_to_me(); + h.run_steps(4); + let rect = control(h, role, label).rect(); + assert!(h.ctx.content_rect().contains_rect(rect), "the control is reachable: {label} {rect:?}"); + h.hover_at(rect.center()); + h.run_steps(60); + assert!(h.query_all_by_role(Role::Label).any(|n| n.accesskit_node().value().as_deref() == Some(tip)), "hovering {role:?} {label:?} must display {tip:?}"); +} + +#[test] +fn both_tools_show_exact_tooltips_on_the_controls_and_hide_them_on_leave() { + for tool in [Tool::Burn, Tool::Dodge] { + for (role, label, tip) in CONTROLS { + let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); + assert!(h.query_by_label(tip).is_none(), "no tooltip before hover"); + let before = h.state().ui.tool_options.clone(); + hover(&mut h, role, label, tip); + assert_eq!(h.state().ui.tool_options.exposure, before.exposure); + assert_eq!(h.state().ui.tool_options.tone_range, before.tone_range); + assert_eq!(h.state().ui.tool_options.protect_tones, before.protect_tones); + assert_eq!(h.ctx.memory(|m| m.focused()), None, "hover never takes keyboard focus"); + h.hover_at(egui::pos2(20.0, 200.0)); + h.run_steps(60); + assert!(h.query_by_label(tip).is_none(), "tooltip goes away after leaving {label}"); + } + } +} + +#[test] +fn hover_uses_the_active_catalog_or_english_fallback() { + for code in ["en", "de", "fr", "ja", "ar"] { + let lang = Lang::from_code(code).unwrap(); + for tool in [Tool::Burn, Tool::Dodge] { + for (role, label, tip) in CONTROLS { + let mut h = bar(tool, lang, 1600.0, 1.0, false); + // The existing scrub-caption link only names fields laid out left to right. + // In RTL, select the sole numeric control rather than assuming that link exists. + let name = if role == Role::SpinButton && lang.dir() == crate::i18n::Dir::Rtl { + h.get_by_role(role).accesskit_node().label().unwrap_or_default() + } else { + tr(lang, label).to_owned() + }; + hover(&mut h, role, &name, tr(lang, tip)); + } + } + } +} + +#[test] +fn hovering_does_not_block_exposure_editing_range_selection_or_protect_tones() { + for tool in [Tool::Burn, Tool::Dodge] { + let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); + let history = h.state().session.active().unwrap().history.past_len(); + let (role, label, tip) = CONTROLS[1]; + hover(&mut h, role, label, tip); + control(&h, role, label).click(); + h.run_steps(2); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text("37".into())); + h.run_steps(2); + let focused = h.ctx.memory(|m| m.focused()); + assert!(focused.is_some(), "Exposure receives keyboard focus"); + h.run_steps(60); + assert_eq!(h.ctx.memory(|m| m.focused()), focused, "a tooltip cannot steal focus"); + h.key_press(egui::Key::Enter); + h.run_steps(4); + assert_eq!(h.state().ui.tool_options.exposure, 37.0); + + let (role, label, tip) = CONTROLS[0]; + hover(&mut h, role, label, tip); + control(&h, role, label).click(); + h.run_steps(4); + assert!(egui::Popup::is_any_open(&h.ctx), "Range opens after hover"); + h.get_by_label("Highlights").click(); + h.run_steps(4); + assert_eq!(h.state().ui.tool_options.tone_range, "highlights"); + assert!(!egui::Popup::is_any_open(&h.ctx)); + control(&h, role, label).click(); + h.run_steps(4); + h.key_press(egui::Key::ArrowUp); + h.run_steps(2); + h.key_press(egui::Key::Escape); + h.run_steps(4); + assert_eq!(h.state().ui.tool_options.tone_range, "midtones", "Range still accepts keyboard navigation"); + + let (role, label, tip) = CONTROLS[2]; + hover(&mut h, role, label, tip); + control(&h, role, label).click(); + h.run_steps(4); + assert!(!h.state().ui.tool_options.protect_tones, "Protect Tones toggles after hover"); + control(&h, role, label).click(); + h.run_steps(4); + assert!(h.state().ui.tool_options.protect_tones); + assert_eq!(h.state().session.active().unwrap().history.past_len(), history, "option edits do not paint or add history"); + } +} + +#[test] +fn tool_switching_clears_the_old_tooltip_and_leaves_other_percentage_fields_unchanged() { + for tool in [Tool::Blur, Tool::Sharpen, Tool::Smudge] { + let mut h = bar(Tool::Burn, Lang::EN, 1600.0, 1.0, false); + hover(&mut h, CONTROLS[1].0, CONTROLS[1].1, CONTROLS[1].2); + h.state_mut().ui.tool = tool; + h.run_steps(60); + assert!(h.query_by_label(CONTROLS[1].2).is_none()); + control(&h, Role::SpinButton, "Strength:").hover(); + h.run_steps(60); + assert!(h.query_by_label(CONTROLS[1].2).is_none(), "{tool:?} must not inherit the Exposure tooltip"); + control(&h, Role::SpinButton, "Strength:").click(); + h.run_steps(2); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text("42".into())); + h.run_steps(2); + h.key_press(egui::Key::Tab); + h.run_steps(4); + assert_eq!(h.state().ui.tool_options.strength, 42.0); + h.state_mut().ui.tool = Tool::Dodge; + h.run_steps(4); + hover(&mut h, CONTROLS[1].0, CONTROLS[1].1, CONTROLS[1].2); + assert_eq!(h.state().ui.tool_options.exposure, 50.0); + } +} + +/// Run explicitly to inspect the rendered tooltips; no GPU is required by the normal regressions. +#[test] +#[ignore = "offscreen visual inspection; writes PNGs to PHOTOCRAFT_TOOLTIP_IMAGES or the temp directory"] +fn render_tooltips_for_visual_inspection() { + let out = std::env::var_os("PHOTOCRAFT_TOOLTIP_IMAGES").map(std::path::PathBuf::from).unwrap_or_else(|| std::env::temp_dir().join("photocraft-12670")); + let lang = std::env::var("PHOTOCRAFT_TOOLTIP_LANGUAGE").ok().and_then(|code| Lang::from_code(&code)).unwrap_or(Lang::EN); + std::fs::create_dir_all(&out).unwrap(); + for theme in crate::theme::ThemeKind::ALL { + for tool in [Tool::Burn, Tool::Dodge] { + for (i, (role, label, tip)) in CONTROLS.into_iter().enumerate() { + let mut h = bar(tool, lang, 1000.0, 1.0, false); + PhotocraftApp::setup_context(&h.ctx, theme); + h.run_steps(4); + h.render().unwrap().save(out.join(format!("{theme:?}-{tool:?}-{i}-before.png"))).unwrap(); + hover(&mut h, role, tr(lang, label), tr(lang, tip)); + h.render().unwrap().save(out.join(format!("{theme:?}-{tool:?}-{i}-hover.png"))).unwrap(); + } + } + } + for tool in [Tool::Burn, Tool::Dodge] { + for (i, (role, label, tip)) in CONTROLS.into_iter().enumerate() { + let mut h = bar(tool, lang, 480.0, 3.0, true); + hover(&mut h, role, tr(lang, label), tr(lang, tip)); + h.render().unwrap().save(out.join(format!("narrow-3x-{tool:?}-{i}.png"))).unwrap(); + } + } +} + +#[test] +fn tooltips_remain_reachable_in_narrow_bars_at_supported_scales() { + for scale in [0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0] { + for tool in [Tool::Burn, Tool::Dodge] { + for (role, label, tip) in CONTROLS { + let mut h = bar(tool, Lang::EN, 480.0, scale, true); + hover(&mut h, role, label, tip); + let tooltip = h.get_by_label(tip).rect(); + assert!(h.ctx.content_rect().contains_rect(tooltip), "tooltip fits at {scale}x: {tooltip:?}"); + } + } + } +} diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 7f343e3f7d..ba6fced555 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -837,8 +837,14 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo } opt(ui, tl!("Exposure:")); crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0).on_hover_text(tl!("Set exposure for stroke")); - crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")) - .on_hover_text(tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue")); + let protect_tip = tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"); + let protect = crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")).on_hover_ui(|ui| { + // Keep the long tooltip inside narrow viewports at high UI scales. + let room = (ui.ctx().content_rect().width() - egui::Frame::popup(ui.style()).total_margin().sum().x).max(1.0); + ui.set_max_width(ui.spacing().tooltip_width.min(room)); + ui.label(protect_tip); + }); + protect.ctx.accesskit_node_builder(protect.id, |node| node.set_description(protect_tip)); } Tool::Sponge => { opt(ui, tl!("Mode:")); @@ -1018,3 +1024,7 @@ mod color_replacement_tolerance_field_tests; #[cfg(test)] #[path = "../cam_options_bar_tests.rs"] mod cam_options_bar_tests; + +#[cfg(test)] +#[path = "../burn_bar_tooltips_tests.rs"] +mod burn_bar_tooltips_tests; From 9ad7b7ad87803550d856fc59efee482aa30a147f Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 22:21:44 +0000 Subject: [PATCH 4/7] fix(ui): bound all tone tooltips and avoid anonymous accessibility nodes --- crates/ui-egui/src/burn_bar_tooltips_tests.rs | 134 ++++++++++++++++-- crates/ui-egui/src/tools/retouch_ui.rs | 36 +++-- 2 files changed, 150 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/burn_bar_tooltips_tests.rs b/crates/ui-egui/src/burn_bar_tooltips_tests.rs index c3f4ab9d14..43b0fbbf51 100644 --- a/crates/ui-egui/src/burn_bar_tooltips_tests.rs +++ b/crates/ui-egui/src/burn_bar_tooltips_tests.rs @@ -3,7 +3,7 @@ use egui::accesskit::Role; use egui::vec2; use egui_kittest::Harness; -use egui_kittest::kittest::{NodeT, Queryable}; +use egui_kittest::kittest::{NodeT, Queryable, by}; use serde_json::json; use crate::PhotocraftApp; @@ -41,6 +41,15 @@ fn control<'a>(h: &'a Harness<'static, PhotocraftApp>, role: Role, label: &str) h.query_all_by_role(role).find(|n| n.accesskit_node().label().as_deref() == Some(label)).unwrap_or_else(|| panic!("missing {role:?} {label:?}")) } +fn control_name(h: &Harness<'static, PhotocraftApp>, lang: Lang, role: Role, label: &str) -> String { + // The existing scrub-caption link only names fields laid out left to right. + if role == Role::SpinButton && lang.dir() == crate::i18n::Dir::Rtl { + h.get_by_role(role).accesskit_node().label().unwrap_or_default() + } else { + tr(lang, label).to_owned() + } +} + fn hover(h: &mut Harness<'static, PhotocraftApp>, role: Role, label: &str, tip: &str) { control(h, role, label).scroll_to_me(); h.run_steps(4); @@ -77,13 +86,7 @@ fn hover_uses_the_active_catalog_or_english_fallback() { for tool in [Tool::Burn, Tool::Dodge] { for (role, label, tip) in CONTROLS { let mut h = bar(tool, lang, 1600.0, 1.0, false); - // The existing scrub-caption link only names fields laid out left to right. - // In RTL, select the sole numeric control rather than assuming that link exists. - let name = if role == Role::SpinButton && lang.dir() == crate::i18n::Dir::Rtl { - h.get_by_role(role).accesskit_node().label().unwrap_or_default() - } else { - tr(lang, label).to_owned() - }; + let name = control_name(&h, lang, role, label); hover(&mut h, role, &name, tr(lang, tip)); } } @@ -179,7 +182,8 @@ fn render_tooltips_for_visual_inspection() { PhotocraftApp::setup_context(&h.ctx, theme); h.run_steps(4); h.render().unwrap().save(out.join(format!("{theme:?}-{tool:?}-{i}-before.png"))).unwrap(); - hover(&mut h, role, tr(lang, label), tr(lang, tip)); + let name = control_name(&h, lang, role, label); + hover(&mut h, role, &name, tr(lang, tip)); h.render().unwrap().save(out.join(format!("{theme:?}-{tool:?}-{i}-hover.png"))).unwrap(); } } @@ -187,8 +191,98 @@ fn render_tooltips_for_visual_inspection() { for tool in [Tool::Burn, Tool::Dodge] { for (i, (role, label, tip)) in CONTROLS.into_iter().enumerate() { let mut h = bar(tool, lang, 480.0, 3.0, true); - hover(&mut h, role, tr(lang, label), tr(lang, tip)); + let name = control_name(&h, lang, role, label); + hover(&mut h, role, &name, tr(lang, tip)); h.render().unwrap().save(out.join(format!("narrow-3x-{tool:?}-{i}.png"))).unwrap(); + crate::theme::set_ui_font_size(&h.ctx, photocraft_engine::prefs::UiFontSize::Large); + h.run_steps(8); + let name = control_name(&h, lang, role, label); + hover(&mut h, role, &name, tr(lang, tip)); + h.render().unwrap().save(out.join(format!("narrow-3x-large-font-{tool:?}-{i}.png"))).unwrap(); + } + } +} + +#[test] +fn tooltip_descriptions_do_not_create_anonymous_accessibility_nodes() { + for tool in [Tool::Burn, Tool::Dodge] { + let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); + for (role, label, tip) in CONTROLS { + for node in h.query_all(by().predicate(|n| n.description().as_deref() == Some(tip))) { + assert_eq!(node.accesskit_node().role(), role, "{label}: tooltip metadata belongs on the named control"); + assert_eq!(node.accesskit_node().label().as_deref(), Some(label)); + } + } + assert_eq!(h.query_all_by_role(Role::CheckBox).count(), 1); + h.get_by_role_and_label(Role::CheckBox, "Protect Tones").focus(); + h.run_steps(2); + let focused = h.ctx.memory(|m| m.focused()); + hover(&mut h, CONTROLS[0].0, CONTROLS[0].1, CONTROLS[0].2); + assert_eq!(h.ctx.memory(|m| m.focused()), focused); + h.key_press(egui::Key::Space); + h.run_steps(2); + assert!(!h.state().ui.tool_options.protect_tones, "the named checkbox still responds to Space"); + } +} + +#[test] +fn tooltip_text_fits_with_every_ui_font_size_in_a_narrow_scaled_bar() { + use photocraft_engine::prefs::UiFontSize; + for size in [UiFontSize::Tiny, UiFontSize::Small, UiFontSize::Medium, UiFontSize::Large] { + for lang in [Lang::EN, Lang::from_code("de").unwrap()] { + for tool in [Tool::Burn, Tool::Dodge] { + for (role, label, tip) in CONTROLS { + let mut h = bar(tool, lang, 480.0, 3.0, true); + crate::theme::set_ui_font_size(&h.ctx, size); + h.run_steps(8); + hover(&mut h, role, tr(lang, label), tr(lang, tip)); + let text = h.get_by_role_and_label(Role::Label, tr(lang, tip)).rect(); + assert!(h.ctx.content_rect().contains_rect(text), "{lang:?} {label} at {size:?}: tooltip text must remain readable: {text:?}"); + } + } + } + } +} + +#[test] +fn both_checkbox_mouse_targets_show_the_tooltip_and_toggle() { + for tool in [Tool::Burn, Tool::Dodge] { + let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); + let label = control(&h, CONTROLS[2].0, CONTROLS[2].1).rect(); + // The shared checkbox draws a 14 pt box, then a 6 pt gap before its named label. + let box_center = egui::pos2(label.left() - 13.0, label.center().y); + for (i, at) in [box_center, label.center()].into_iter().enumerate() { + h.hover_at(at); + h.run_steps(60); + assert!(h.query_by_role_and_label(Role::Label, CONTROLS[2].2).is_some()); + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(3); + assert_eq!(h.state().ui.tool_options.protect_tones, i == 1); + } + } +} + +#[test] +fn exposure_keeps_its_bounds_and_text_entry_after_hover() { + for tool in [Tool::Burn, Tool::Dodge] { + for key in [egui::Key::Enter, egui::Key::Tab] { + for (typed, want) in [("1", 1.0), ("100", 100.0), ("0", 1.0), ("150", 100.0), ("abc", 50.0)] { + let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); + hover(&mut h, CONTROLS[1].0, CONTROLS[1].1, CONTROLS[1].2); + control(&h, CONTROLS[1].0, CONTROLS[1].1).click(); + h.run_steps(2); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(typed.into())); + h.run_steps(2); + let focused = h.ctx.memory(|m| m.focused()); + hover(&mut h, CONTROLS[0].0, CONTROLS[0].1, CONTROLS[0].2); + assert_eq!(h.ctx.memory(|m| m.focused()), focused, "hovering Range does not leave the Exposure editor"); + h.key_press(key); + h.run_steps(4); + assert_eq!(h.state().ui.tool_options.exposure, want, "{tool:?}: {typed}, {key:?}"); + } } } } @@ -202,6 +296,26 @@ fn tooltips_remain_reachable_in_narrow_bars_at_supported_scales() { hover(&mut h, role, label, tip); let tooltip = h.get_by_label(tip).rect(); assert!(h.ctx.content_rect().contains_rect(tooltip), "tooltip fits at {scale}x: {tooltip:?}"); + control(&h, role, label).click(); + h.run_steps(3); + match role { + Role::ComboBox => { + assert!(egui::Popup::is_any_open(&h.ctx), "Range still opens at {scale}x"); + h.get_by_label("Highlights").click(); + h.run_steps(3); + assert_eq!(h.state().ui.tool_options.tone_range, "highlights"); + } + Role::SpinButton => { + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text("37".into())); + h.run_steps(2); + h.key_press(egui::Key::Enter); + h.run_steps(3); + assert_eq!(h.state().ui.tool_options.exposure, 37.0, "Exposure remains editable at {scale}x"); + } + Role::CheckBox => assert!(!h.state().ui.tool_options.protect_tones, "Protect Tones still toggles at {scale}x"), + _ => unreachable!("the three shared Burn/Dodge controls"), + } } } } diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index ba6fced555..446de6015b 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -829,22 +829,38 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo } } Tool::Dodge | Tool::Burn => { + let tooltip = |response: egui::Response, text: &str| { + // The checkbox's box is a mouse target, not its named accessibility node. + // Match on_hover_text: enrich existing nodes without inventing another control. + if response.ctx.has_accesskit_node(response.id) { + response.ctx.accesskit_node_builder(response.id, |node| { + if node.description().is_none() { + node.set_description(text); + } + if node.labelled_by().is_empty() && node.label().is_none_or(str::is_empty) { + node.set_label(text); + } + }); + } + response.on_hover_ui(|ui| { + // Translations and larger UI fonts can make even the short tips overflow. + let room = (ui.ctx().content_rect().width() - egui::Frame::popup(ui.style()).total_margin().sum().x).max(1.0); + ui.set_max_width(ui.spacing().tooltip_width.min(room)); + ui.label(text); + }); + }; opt(ui, tl!("Range:")); let opts = [("shadows".to_string(), tl!("Shadows")), ("midtones".to_string(), tl!("Midtones")), ("highlights".to_string(), tl!("Highlights"))]; crate::widgets::dropdown(ui, "tone-range", tl!("Range"), &mut o.tone_range, &opts, 100.0); if let Some(range) = ui.ctx().read_response(ui.make_persistent_id(egui::IdSalt::new("tone-range"))) { - range.on_hover_text(tl!("Painting Mode")); + tooltip(range, tl!("Painting Mode")); } opt(ui, tl!("Exposure:")); - crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0).on_hover_text(tl!("Set exposure for stroke")); - let protect_tip = tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"); - let protect = crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")).on_hover_ui(|ui| { - // Keep the long tooltip inside narrow viewports at high UI scales. - let room = (ui.ctx().content_rect().width() - egui::Frame::popup(ui.style()).total_margin().sum().x).max(1.0); - ui.set_max_width(ui.spacing().tooltip_width.min(room)); - ui.label(protect_tip); - }); - protect.ctx.accesskit_node_builder(protect.id, |node| node.set_description(protect_tip)); + tooltip(crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0), tl!("Set exposure for stroke")); + tooltip( + crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")), + tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), + ); } Tool::Sponge => { opt(ui, tl!("Mode:")); From aab25d69251c05e02e10ee9e2c8ee17662a02fe6 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 22:34:59 +0000 Subject: [PATCH 5/7] test(ui): keep the unexpected-role assertion within test lint rules --- crates/ui-egui/src/burn_bar_tooltips_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/burn_bar_tooltips_tests.rs b/crates/ui-egui/src/burn_bar_tooltips_tests.rs index 43b0fbbf51..26403085ee 100644 --- a/crates/ui-egui/src/burn_bar_tooltips_tests.rs +++ b/crates/ui-egui/src/burn_bar_tooltips_tests.rs @@ -314,7 +314,7 @@ fn tooltips_remain_reachable_in_narrow_bars_at_supported_scales() { assert_eq!(h.state().ui.tool_options.exposure, 37.0, "Exposure remains editable at {scale}x"); } Role::CheckBox => assert!(!h.state().ui.tool_options.protect_tones, "Protect Tones still toggles at {scale}x"), - _ => unreachable!("the three shared Burn/Dodge controls"), + _ => panic!("unexpected Burn/Dodge control role: {role:?}"), } } } From 9957f9870a63dad67aa93380ad5f23cbd5a91544 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 23:19:38 +0000 Subject: [PATCH 6/7] fix(ui): attach tone tooltip descriptions to named controls --- crates/ui-egui/src/burn_bar_tooltips_tests.rs | 5 +++++ crates/ui-egui/src/tools/retouch_ui.rs | 19 ++++++++++--------- crates/ui-egui/src/widgets.rs | 1 + crates/ui-egui/src/widgets/buttons.rs | 8 +++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/burn_bar_tooltips_tests.rs b/crates/ui-egui/src/burn_bar_tooltips_tests.rs index 26403085ee..4360f79cb5 100644 --- a/crates/ui-egui/src/burn_bar_tooltips_tests.rs +++ b/crates/ui-egui/src/burn_bar_tooltips_tests.rs @@ -208,6 +208,11 @@ fn tooltip_descriptions_do_not_create_anonymous_accessibility_nodes() { for tool in [Tool::Burn, Tool::Dodge] { let mut h = bar(tool, Lang::EN, 1600.0, 1.0, false); for (role, label, tip) in CONTROLS { + assert_eq!( + h.get_by_role_and_label(role, label).accesskit_node().description().as_deref(), + Some(tip), + "{label}: the named control has its tooltip description" + ); for node in h.query_all(by().predicate(|n| n.description().as_deref() == Some(tip))) { assert_eq!(node.accesskit_node().role(), role, "{label}: tooltip metadata belongs on the named control"); assert_eq!(node.accesskit_node().label().as_deref(), Some(label)); diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 446de6015b..095194c6ad 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -829,11 +829,11 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo } } Tool::Dodge | Tool::Burn => { - let tooltip = |response: egui::Response, text: &str| { + let tooltip = |response: egui::Response, text: &str, accessibility_id: egui::Id| { // The checkbox's box is a mouse target, not its named accessibility node. // Match on_hover_text: enrich existing nodes without inventing another control. - if response.ctx.has_accesskit_node(response.id) { - response.ctx.accesskit_node_builder(response.id, |node| { + if response.ctx.has_accesskit_node(accessibility_id) { + response.ctx.accesskit_node_builder(accessibility_id, |node| { if node.description().is_none() { node.set_description(text); } @@ -853,14 +853,15 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo let opts = [("shadows".to_string(), tl!("Shadows")), ("midtones".to_string(), tl!("Midtones")), ("highlights".to_string(), tl!("Highlights"))]; crate::widgets::dropdown(ui, "tone-range", tl!("Range"), &mut o.tone_range, &opts, 100.0); if let Some(range) = ui.ctx().read_response(ui.make_persistent_id(egui::IdSalt::new("tone-range"))) { - tooltip(range, tl!("Painting Mode")); + let id = range.id; + tooltip(range, tl!("Painting Mode"), id); } opt(ui, tl!("Exposure:")); - tooltip(crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0), tl!("Set exposure for stroke")); - tooltip( - crate::widgets::checkbox(ui, &mut o.protect_tones, tl!("Protect Tones")), - tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), - ); + let exposure = crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0); + let exposure_id = exposure.id; + tooltip(exposure, tl!("Set exposure for stroke"), exposure_id); + let (protect, protect_id) = crate::widgets::checkbox_with_accessibility_id(ui, &mut o.protect_tones, tl!("Protect Tones")); + tooltip(protect, tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), protect_id); } Tool::Sponge => { opt(ui, tl!("Mode:")); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 40c03c1231..db37825b69 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -32,6 +32,7 @@ pub mod text_field_menu; pub mod tone; mod units; +pub(crate) use buttons::checkbox_with_accessibility_id; pub use buttons::{ ButtonRole, DialogButton, button_height, button_width, check_box, check_box_fill, checkbox, compact_button, dialog_buttons, primary_button, secondary_button, toggle, diff --git a/crates/ui-egui/src/widgets/buttons.rs b/crates/ui-egui/src/widgets/buttons.rs index 41ad5509bc..eba1bdf7d7 100644 --- a/crates/ui-egui/src/widgets/buttons.rs +++ b/crates/ui-egui/src/widgets/buttons.rs @@ -213,6 +213,12 @@ fn button_impl_h(ui: &mut Ui, label: &str, min_width: f32, height: Option, /// Spectrum-style checkbox (blue when checked). pub fn checkbox(ui: &mut Ui, on: &mut bool, label: &str) -> Response { + checkbox_with_accessibility_id(ui, on, label).0 +} + +/// Return the combined mouse response and the named checkbox's accessibility ID. +/// The response keeps the box ID; accessibility metadata belongs on the label instead. +pub(crate) fn checkbox_with_accessibility_id(ui: &mut Ui, on: &mut bool, label: &str) -> (Response, egui::Id) { let t = Tokens::get(ui.ctx()); let (mut resp, label_resp) = ui .horizontal(|ui| { @@ -235,7 +241,7 @@ pub fn checkbox(ui: &mut Ui, on: &mut bool, label: &str) -> Response { // The label is the single named, focusable checkbox; the box is a mouse target. // Override Label's metadata instead of creating a second node with the same name. label_resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, ui.is_enabled(), *on, tl!(label))); - resp + (resp, label_resp.id) } /// The fill of a check box: the accent when `on`, else the field colour. While it's pressed From f6d5b92bf2d86eecce3e72e04e5c1a642d5d36cb Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Nov 2026 23:42:47 +0000 Subject: [PATCH 7/7] fix(ui): keep tone tooltips within issue scope and document tests --- crates/ui-egui/src/burn_bar_tooltips_tests.rs | 13 ++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 31 ++++++++++++++++++- crates/ui-egui/src/widgets.rs | 1 - crates/ui-egui/src/widgets/buttons.rs | 8 +---- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/burn_bar_tooltips_tests.rs b/crates/ui-egui/src/burn_bar_tooltips_tests.rs index 4360f79cb5..b000418ab3 100644 --- a/crates/ui-egui/src/burn_bar_tooltips_tests.rs +++ b/crates/ui-egui/src/burn_bar_tooltips_tests.rs @@ -16,6 +16,7 @@ const CONTROLS: [(Role, &str, &str); 3] = [ (Role::CheckBox, "Protect Tones", "Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), ]; +/// Build a settled options-bar fixture with the requested tool, locale, viewport and scale. fn bar(tool: Tool, lang: Lang, width: f32, scale: f32, narrow: bool) -> Harness<'static, PhotocraftApp> { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); app.run("file.new", json!({"width": 80, "height": 80})).unwrap(); @@ -37,10 +38,12 @@ fn bar(tool: Tool, lang: Lang, width: f32, scale: f32, narrow: bool) -> Harness< h } +/// Find the named control by its accessibility role without matching tooltip labels. fn control<'a>(h: &'a Harness<'static, PhotocraftApp>, role: Role, label: &str) -> egui_kittest::Node<'a> { h.query_all_by_role(role).find(|n| n.accesskit_node().label().as_deref() == Some(label)).unwrap_or_else(|| panic!("missing {role:?} {label:?}")) } +/// Resolve the localized control name, using the numeric node for the existing RTL caption layout. fn control_name(h: &Harness<'static, PhotocraftApp>, lang: Lang, role: Role, label: &str) -> String { // The existing scrub-caption link only names fields laid out left to right. if role == Role::SpinButton && lang.dir() == crate::i18n::Dir::Rtl { @@ -50,6 +53,7 @@ fn control_name(h: &Harness<'static, PhotocraftApp>, lang: Lang, role: Role, lab } } +/// Scroll a control into view, wait for its hover delay and assert the visible tooltip text. fn hover(h: &mut Harness<'static, PhotocraftApp>, role: Role, label: &str, tip: &str) { control(h, role, label).scroll_to_me(); h.run_steps(4); @@ -60,6 +64,7 @@ fn hover(h: &mut Harness<'static, PhotocraftApp>, role: Role, label: &str, tip: assert!(h.query_all_by_role(Role::Label).any(|n| n.accesskit_node().value().as_deref() == Some(tip)), "hovering {role:?} {label:?} must display {tip:?}"); } +/// Check tooltip text, dismissal and unchanged option values and keyboard focus for both tools. #[test] fn both_tools_show_exact_tooltips_on_the_controls_and_hide_them_on_leave() { for tool in [Tool::Burn, Tool::Dodge] { @@ -79,6 +84,7 @@ fn both_tools_show_exact_tooltips_on_the_controls_and_hide_them_on_leave() { } } +/// Exercise translated and English-fallback tooltips in Latin, Japanese and RTL locales. #[test] fn hover_uses_the_active_catalog_or_english_fallback() { for code in ["en", "de", "fr", "ja", "ar"] { @@ -93,6 +99,7 @@ fn hover_uses_the_active_catalog_or_english_fallback() { } } +/// Verify that hovering preserves Exposure editing, Range navigation and Protect Tones toggling without history edits. #[test] fn hovering_does_not_block_exposure_editing_range_selection_or_protect_tones() { for tool in [Tool::Burn, Tool::Dodge] { @@ -142,6 +149,7 @@ fn hovering_does_not_block_exposure_editing_range_selection_or_protect_tones() { } } +/// Switch to adjacent tools and verify tooltip dismissal and independent Strength and Exposure values. #[test] fn tool_switching_clears_the_old_tooltip_and_leaves_other_percentage_fields_unchanged() { for tool in [Tool::Blur, Tool::Sharpen, Tool::Smudge] { @@ -203,6 +211,7 @@ fn render_tooltips_for_visual_inspection() { } } +/// Require descriptions on the named controls and reject anonymous duplicates while preserving checkbox keyboard focus. #[test] fn tooltip_descriptions_do_not_create_anonymous_accessibility_nodes() { for tool in [Tool::Burn, Tool::Dodge] { @@ -230,6 +239,7 @@ fn tooltip_descriptions_do_not_create_anonymous_accessibility_nodes() { } } +/// Check that English and German tooltip text fits the narrow 3x viewport at every interface font size. #[test] fn tooltip_text_fits_with_every_ui_font_size_in_a_narrow_scaled_bar() { use photocraft_engine::prefs::UiFontSize; @@ -249,6 +259,7 @@ fn tooltip_text_fits_with_every_ui_font_size_in_a_narrow_scaled_bar() { } } +/// Hover and click both the checkbox box and its label to verify their shared tooltip and toggle behavior. #[test] fn both_checkbox_mouse_targets_show_the_tooltip_and_toggle() { for tool in [Tool::Burn, Tool::Dodge] { @@ -269,6 +280,7 @@ fn both_checkbox_mouse_targets_show_the_tooltip_and_toggle() { } } +/// Cover Exposure bounds, invalid text and Enter/Tab commits while another control is hovered. #[test] fn exposure_keeps_its_bounds_and_text_entry_after_hover() { for tool in [Tool::Burn, Tool::Dodge] { @@ -292,6 +304,7 @@ fn exposure_keeps_its_bounds_and_text_entry_after_hover() { } } +/// Exercise tooltip visibility and control interaction in a narrow bar at every supported display scale. #[test] fn tooltips_remain_reachable_in_narrow_bars_at_supported_scales() { for scale in [0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0] { diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 095194c6ad..ea79767e30 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -740,6 +740,35 @@ fn content_aware_move_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } } +/// Draw Protect Tones with the shared checkbox's appearance and mouse behavior. +/// Keep the label response here so its accessibility description needs no shared-widget API change. +fn protect_tones_checkbox(ui: &mut egui::Ui, on: &mut bool) -> (egui::Response, egui::Id) { + let label = tl!("Protect Tones"); + let t = Tokens::get(ui.ctx()); + let (mut resp, label_resp) = ui + .horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 6.0; + let (rect, resp) = ui.allocate_exact_size(vec2(14.0, 14.0), egui::Sense::CLICK); + let resp = resp.on_hover_cursor(egui::CursorIcon::PointingHand); + let l = ui + .add(egui::Label::new(egui::RichText::new(label).color(t.text_dim)).selectable(false).sense(egui::Sense::click())) + .on_hover_cursor(egui::CursorIcon::PointingHand); + // Pressing the label presses the box (#4476). + let pressed = resp.is_pointer_button_down_on() || l.is_pointer_button_down_on(); + crate::widgets::check_box(ui.painter(), rect, *on, resp.hovered() || l.hovered(), pressed, &t); + (resp.union(l.clone()), l) + }) + .inner; + if resp.clicked() { + *on = !*on; + resp.mark_changed(); + } + // The label is the single named, focusable checkbox; the box is a mouse target. + // Override Label's metadata instead of creating a second node with the same name. + label_resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, ui.is_enabled(), *on, label)); + (resp, label_resp.id) +} + /// Options bar for the retouching and smart-selection tools. Returns false for other tools. pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bool { if !tool.is_brushlike() && !matches!(tool, Tool::QuickSelection | Tool::ObjectSelection | Tool::Patch | Tool::ContentAwareMove | Tool::RedEye) @@ -860,7 +889,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo let exposure = crate::widgets::value_field(ui, &mut o.exposure, 1.0..=100.0, "%", 58.0); let exposure_id = exposure.id; tooltip(exposure, tl!("Set exposure for stroke"), exposure_id); - let (protect, protect_id) = crate::widgets::checkbox_with_accessibility_id(ui, &mut o.protect_tones, tl!("Protect Tones")); + let (protect, protect_id) = protect_tones_checkbox(ui, &mut o.protect_tones); tooltip(protect, tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue"), protect_id); } Tool::Sponge => { diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index db37825b69..40c03c1231 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -32,7 +32,6 @@ pub mod text_field_menu; pub mod tone; mod units; -pub(crate) use buttons::checkbox_with_accessibility_id; pub use buttons::{ ButtonRole, DialogButton, button_height, button_width, check_box, check_box_fill, checkbox, compact_button, dialog_buttons, primary_button, secondary_button, toggle, diff --git a/crates/ui-egui/src/widgets/buttons.rs b/crates/ui-egui/src/widgets/buttons.rs index eba1bdf7d7..41ad5509bc 100644 --- a/crates/ui-egui/src/widgets/buttons.rs +++ b/crates/ui-egui/src/widgets/buttons.rs @@ -213,12 +213,6 @@ fn button_impl_h(ui: &mut Ui, label: &str, min_width: f32, height: Option, /// Spectrum-style checkbox (blue when checked). pub fn checkbox(ui: &mut Ui, on: &mut bool, label: &str) -> Response { - checkbox_with_accessibility_id(ui, on, label).0 -} - -/// Return the combined mouse response and the named checkbox's accessibility ID. -/// The response keeps the box ID; accessibility metadata belongs on the label instead. -pub(crate) fn checkbox_with_accessibility_id(ui: &mut Ui, on: &mut bool, label: &str) -> (Response, egui::Id) { let t = Tokens::get(ui.ctx()); let (mut resp, label_resp) = ui .horizontal(|ui| { @@ -241,7 +235,7 @@ pub(crate) fn checkbox_with_accessibility_id(ui: &mut Ui, on: &mut bool, label: // The label is the single named, focusable checkbox; the box is a mouse target. // Override Label's metadata instead of creating a second node with the same name. label_resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, ui.is_enabled(), *on, tl!(label))); - (resp, label_resp.id) + resp } /// The fill of a check box: the accent when `on`, else the field colour. While it's pressed