From aedac66d9514b38681cfa71b676d0d830b20866e Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 14 Nov 2026 01:35:26 +0100 Subject: [PATCH 1/3] WIP: Art History Brush: Area 0-500 px, field alerts and tooltips (#12630) From 4eb0b6ea23f4ae8934f3632691e466a15f0028a9 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 14 Nov 2026 01:59:26 +0100 Subject: [PATCH 2/3] Art History Brush: Area 0-500 px, field alerts and tooltips (#12630) Area takes whole pixels 0-500 in the options bar and in paint.artHistoryBrush; Area and Tolerance alert on a typed value past their range; Tolerance gets a slider arrow; Opacity, Area and Tolerance get the reference tooltips; the hint text is gone. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/retouch_cmds.rs | 2 +- .../src/cmd/retouch_cmds/art_history.rs | 3 +- crates/ui-egui/src/panels/options_bar.rs | 2 +- crates/ui-egui/src/tools.rs | 3 + .../src/tools/art_history_fields_tests.rs | 122 ++++++++++++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 21 ++- 6 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 crates/ui-egui/src/tools/art_history_fields_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds.rs b/crates/engine/src/cmd/retouch_cmds.rs index 6c891b8449..278e1cac02 100644 --- a/crates/engine/src/cmd/retouch_cmds.rs +++ b/crates/engine/src/cmd/retouch_cmds.rs @@ -411,7 +411,7 @@ pub fn specs() -> Vec { menu: &[], shortcut: None, params: brush_params!( - r#","state":row (a History panel row, as history.setSource),"snapshot":id (a history.newSnapshot id; default: the History panel's source, as paint.historyBrush; a source of another canvas size or colour mode is an error),"style":"tightShort|tightMedium|tightLong|looseMedium|looseLong|dab|tightCurl|looseCurl"="tightMedium","area":0..100=50,"tolerance":0..100=0,"opacity":0..100=100 (overrides the common 1..100: how strongly the history state is painted; 0 changes nothing; no flow, mode is Normal)"# + r#","state":row (a History panel row, as history.setSource),"snapshot":id (a history.newSnapshot id; default: the History panel's source, as paint.historyBrush; a source of another canvas size or colour mode is an error),"style":"tightShort|tightMedium|tightLong|looseMedium|looseLong|dab|tightCurl|looseCurl"="tightMedium","area":0..500=50,"tolerance":0..100=0,"opacity":0..100=100 (overrides the common 1..100: how strongly the history state is painted; 0 changes nothing; no flow, mode is Normal)"# ), enabled: has_pixel_layer, run: art_history::run, diff --git a/crates/engine/src/cmd/retouch_cmds/art_history.rs b/crates/engine/src/cmd/retouch_cmds/art_history.rs index cca503f536..2f3c14493b 100644 --- a/crates/engine/src/cmd/retouch_cmds/art_history.rs +++ b/crates/engine/src/cmd/retouch_cmds/art_history.rs @@ -204,7 +204,8 @@ pub fn run(s: &mut Session, p: &Value) -> Result { let hardness = ranged(p, "hardness", s.tools.brush.hardness * 100.0, 0.0, 100.0)? / 100.0; let opacity = ranged(p, "opacity", 100.0, 0.0, 100.0)? / 100.0; let flow = ranged(p, "flow", 100.0, 0.0, 100.0)? / 100.0; - let area = ranged(p, "area", 50.0, 0.0, 100.0)?; + // Area takes 0..500 px, as the reference's field does (#12630). + let area = ranged(p, "area", 50.0, 0.0, 500.0)?; // Percent of the channel range; 0 (paint everywhere) is the default, as in Photoshop. let tolerance = ranged(p, "tolerance", 0.0, 0.0, 100.0)? / 100.0; let style = style_of(p)?; diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index 005bf4793e..3ddf000387 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -176,7 +176,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // Art History has no Mode (the engine paints Normal) and no Flow. if tool == Tool::ArtHistoryBrush { let width = if t.pro { 62.0 } else { 66.0 }; - percent_field(ui, tl!("Opacity"), &mut brush.opacity, 1.0..=100.0, width); + percent_field(ui, tl!("Opacity"), &mut brush.opacity, 1.0..=100.0, width).on_hover_text(tl!("Set opacity for stroke")); } crate::brush_panel::commit_gesture(app, ui.ctx(), &before, &brush); widgets::vline(ui, 22.0); diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index 503bbe0a7d..8c83cab741 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -60,6 +60,9 @@ pub mod vector_ui; pub mod warp_preview; pub mod zoom_tool; +#[cfg(test)] +mod art_history_fields_tests; + #[cfg(test)] mod gradient_mode_greyed_tests; diff --git a/crates/ui-egui/src/tools/art_history_fields_tests.rs b/crates/ui-egui/src/tools/art_history_fields_tests.rs new file mode 100644 index 0000000000..1764e53bb0 --- /dev/null +++ b/crates/ui-egui/src/tools/art_history_fields_tests.rs @@ -0,0 +1,122 @@ +//! #12630: the Art History Brush's Area takes whole pixels 0..500 and Tolerance whole percents +//! 0..100; a value typed past either range becomes the closest one with the reference's "Closest +//! value inserted" alert. Opacity, Area and Tolerance carry the reference's tooltips, and the bar +//! has no hint text. + +use egui::accesskit::Role; +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use super::retouch_ui::ART_HISTORY_AREA_ALERT; +use crate::PhotocraftApp; +use crate::panels::options_bar::ZERO_TO_100; +use crate::state::{DialogKind, Tool}; + +/// The options bar with the Art History Brush active. +fn bar() -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 80, "height": 80})).unwrap(); + app.ui.tool = Tool::ArtHistoryBrush; + let mut h = Harness::builder().with_size(vec2(1800.0, 300.0)).build_ui_state( + |ui, app| { + crate::field_wheel::begin_frame(ui.ctx()); + crate::panels::options_bar(app, ui); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, Default::default()); + h.run_steps(4); + h +} + +/// Types `text` into the field labelled `label`, then Tabs out of it. +fn type_into(h: &mut Harness<'static, PhotocraftApp>, label: &str, text: &str) { + h.query_all_by_role(Role::SpinButton).find(|n| n.accesskit_node().label().as_deref() == Some(label)).expect("the field").click(); + h.run_steps(1); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(text.into())); + h.run_steps(1); + h.key_press(egui::Key::Tab); + h.run_steps(3); +} + +fn alerts(h: &Harness<'static, PhotocraftApp>) -> Vec { + h.state().ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message")?.as_str().map(str::to_owned)).collect() +} + +/// The descriptions (tooltips) of the controls with `role` labelled `label`. +fn tips(h: &Harness<'static, PhotocraftApp>, role: Role, label: &str) -> Vec { + h.query_all_by_role(role) + .filter(|n| n.accesskit_node().label().as_deref() == Some(label)) + .filter_map(|n| n.accesskit_node().description().map(|d| d.to_string())) + .collect() +} + +#[test] +fn area_past_0_500_takes_the_closest_value_and_alerts() { + for (typed, want) in [("600", 500.0), ("-5", 0.0)] { + let mut h = bar(); + type_into(&mut h, "Area", typed); + assert_eq!(h.state().ui.tool_options.art_history_area, want, "{typed}"); + assert_eq!(alerts(&h), vec![ART_HISTORY_AREA_ALERT.to_string()], "{typed}: one alert"); + } +} + +#[test] +fn area_in_range_is_a_whole_number_without_an_alert() { + for (typed, want) in [("500", 500.0), ("250", 250.0), ("0", 0.0), ("37.6", 38.0)] { + let mut h = bar(); + type_into(&mut h, "Area", typed); + assert_eq!(h.state().ui.tool_options.art_history_area, want, "{typed}"); + assert!(alerts(&h).is_empty(), "{typed} is in range: {:?}", alerts(&h)); + } +} + +#[test] +fn tolerance_past_0_100_takes_the_closest_value_and_alerts() { + for (typed, want) in [("150", 100.0), ("-3", 0.0)] { + let mut h = bar(); + type_into(&mut h, "Tolerance", typed); + assert_eq!(h.state().ui.tool_options.art_history_tolerance, want, "{typed}"); + assert_eq!(alerts(&h), vec![ZERO_TO_100.to_string()], "{typed}: one alert"); + } +} + +#[test] +fn tolerance_in_range_is_a_whole_number_without_an_alert() { + for (typed, want) in [("100", 100.0), ("12.4", 12.0)] { + let mut h = bar(); + type_into(&mut h, "Tolerance", typed); + assert_eq!(h.state().ui.tool_options.art_history_tolerance, want, "{typed}"); + assert!(alerts(&h).is_empty(), "{typed} is in range"); + } +} + +#[test] +fn opacity_area_and_tolerance_have_the_reference_tooltips() { + let h = bar(); + assert!(tips(&h, Role::SpinButton, "Opacity:").contains(&"Set opacity for stroke".to_string())); + assert!(tips(&h, Role::SpinButton, "Area").contains(&"Painting area diameter".to_string())); + assert!(tips(&h, Role::SpinButton, "Tolerance").contains(&"Painting tolerance".to_string())); + assert!(tips(&h, Role::Button, "Tolerance slider").contains(&"Painting tolerance".to_string()), "the slider arrow"); + assert!(tips(&h, Role::Button, "Area").is_empty(), "Area has no slider"); +} + +#[test] +fn the_bar_has_no_hint_text() { + let h = bar(); + assert!(h.query_by_label("Stylized dabs from a history state").is_none()); +} + +#[test] +fn the_command_takes_an_area_up_to_500() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 80, "height": 80})).unwrap(); + let stroke = |area: f64| json!({"points": [[10, 40], [70, 40]], "size": 8, "area": area}); + assert!(app.run("paint.artHistoryBrush", stroke(500.0)).is_ok()); + assert!(app.run("paint.artHistoryBrush", stroke(250.0)).is_ok()); + assert!(app.run("paint.artHistoryBrush", stroke(500.5)).is_err()); + assert!(app.run("paint.artHistoryBrush", stroke(-1.0)).is_err()); +} diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 944c9a28b9..53ad702e91 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -795,6 +795,9 @@ fn cam_amount_slider(ui: &mut egui::Ui, name: &str, value: &mut f32, lo: f32, hi }); } +/// The reference's alert for an Art History Brush Area typed past 0..500 px (#12630). +pub(crate) const ART_HISTORY_AREA_ALERT: &str = "An integer between 0 pixel and 500 Pixels is required. Closest value inserted."; + /// Opens the alert with `message` (English, translated here) unless it is already up. fn open_alert_once(app: &mut PhotocraftApp, message: &str) { let message = tl!(message).to_owned(); @@ -1140,12 +1143,22 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo ("looseCurl".to_string(), tl!("Loose Curl")), ]; crate::widgets::dropdown(ui, "art-history-style", tl!("Style"), &mut o.art_history_style, &styles, 130.0); + // Area: whole pixels 0..500, no slider; Tolerance: whole percents 0..100 with a slider + // arrow. Both alert on a typed value past their range, as the reference does (#12630). opt(ui, tl!("Area")); - crate::widgets::value_field(ui, &mut o.art_history_area, 0.0..=100.0, "", 50.0); + let (area, area_out) = crate::widgets::value_field_whole_alerting(ui, tl!("Area"), &mut o.art_history_area, 0.0..=500.0, "px", 66.0); + area.on_hover_text(tl!("Painting area diameter")); opt(ui, tl!("Tolerance")); - crate::widgets::value_field(ui, &mut o.art_history_tolerance, 0.0..=100.0, "", 50.0); - crate::widgets::vline(ui, 22.0); - opt(ui, tl!("Stylized dabs from a history state")); + let (tolerance, tolerance_out) = + crate::widgets::value_field_whole_alerting(ui, tl!("Tolerance"), &mut o.art_history_tolerance, 0.0..=100.0, "%", 58.0); + tolerance.on_hover_text(tl!("Painting tolerance")); + cam_amount_slider(ui, tl!("Tolerance slider"), &mut o.art_history_tolerance, 0.0, 100.0, "Painting tolerance"); + if area_out { + open_alert_once(app, ART_HISTORY_AREA_ALERT); + } + if tolerance_out { + open_alert_once(app, crate::panels::options_bar::ZERO_TO_100); + } } Tool::QuickSelection => { crate::widgets::checkbox(ui, &mut o.sample_all.quick_selection, tl!("Sample All Layers")); From a55396638cf9169c3b68e2151f0c1a1050753045 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 14 Nov 2026 02:23:18 +0100 Subject: [PATCH 3/3] Art History Brush: move its options into their own function Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/retouch_ui.rs | 63 ++++++++++++++------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 53ad702e91..aa698f1535 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -795,6 +795,38 @@ fn cam_amount_slider(ui: &mut egui::Ui, name: &str, value: &mut f32, lo: f32, hi }); } +/// The Art History Brush's Style, Area and Tolerance. +fn art_history_options(app: &mut PhotocraftApp, ui: &mut egui::Ui) { + let o = &mut app.ui.tool_options; + opt(ui, tl!("Style")); + let styles = [ + ("tightShort".to_string(), tl!("Tight Short")), + ("tightMedium".to_string(), tl!("Tight Medium")), + ("tightLong".to_string(), tl!("Tight Long")), + ("looseMedium".to_string(), tl!("Loose Medium")), + ("looseLong".to_string(), tl!("Loose Long")), + ("dab".to_string(), tl!("Dab")), + ("tightCurl".to_string(), tl!("Tight Curl")), + ("looseCurl".to_string(), tl!("Loose Curl")), + ]; + crate::widgets::dropdown(ui, "art-history-style", tl!("Style"), &mut o.art_history_style, &styles, 130.0); + // Area: whole pixels 0..500, no slider; Tolerance: whole percents 0..100 with a slider + // arrow. Both alert on a typed value past their range, as the reference does (#12630). + opt(ui, tl!("Area")); + let (area, area_out) = crate::widgets::value_field_whole_alerting(ui, tl!("Area"), &mut o.art_history_area, 0.0..=500.0, "px", 66.0); + area.on_hover_text(tl!("Painting area diameter")); + opt(ui, tl!("Tolerance")); + let (tolerance, tolerance_out) = crate::widgets::value_field_whole_alerting(ui, tl!("Tolerance"), &mut o.art_history_tolerance, 0.0..=100.0, "%", 58.0); + tolerance.on_hover_text(tl!("Painting tolerance")); + cam_amount_slider(ui, tl!("Tolerance slider"), &mut o.art_history_tolerance, 0.0, 100.0, "Painting tolerance"); + if area_out { + open_alert_once(app, ART_HISTORY_AREA_ALERT); + } + if tolerance_out { + open_alert_once(app, crate::panels::options_bar::ZERO_TO_100); + } +} + /// The reference's alert for an Art History Brush Area typed past 0..500 px (#12630). pub(crate) const ART_HISTORY_AREA_ALERT: &str = "An integer between 0 pixel and 500 Pixels is required. Closest value inserted."; @@ -1130,36 +1162,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo None => opt(ui, tl!("The History Brush source was deleted: set a new source in the History panel")), } } - Tool::ArtHistoryBrush => { - opt(ui, tl!("Style")); - let styles = [ - ("tightShort".to_string(), tl!("Tight Short")), - ("tightMedium".to_string(), tl!("Tight Medium")), - ("tightLong".to_string(), tl!("Tight Long")), - ("looseMedium".to_string(), tl!("Loose Medium")), - ("looseLong".to_string(), tl!("Loose Long")), - ("dab".to_string(), tl!("Dab")), - ("tightCurl".to_string(), tl!("Tight Curl")), - ("looseCurl".to_string(), tl!("Loose Curl")), - ]; - crate::widgets::dropdown(ui, "art-history-style", tl!("Style"), &mut o.art_history_style, &styles, 130.0); - // Area: whole pixels 0..500, no slider; Tolerance: whole percents 0..100 with a slider - // arrow. Both alert on a typed value past their range, as the reference does (#12630). - opt(ui, tl!("Area")); - let (area, area_out) = crate::widgets::value_field_whole_alerting(ui, tl!("Area"), &mut o.art_history_area, 0.0..=500.0, "px", 66.0); - area.on_hover_text(tl!("Painting area diameter")); - opt(ui, tl!("Tolerance")); - let (tolerance, tolerance_out) = - crate::widgets::value_field_whole_alerting(ui, tl!("Tolerance"), &mut o.art_history_tolerance, 0.0..=100.0, "%", 58.0); - tolerance.on_hover_text(tl!("Painting tolerance")); - cam_amount_slider(ui, tl!("Tolerance slider"), &mut o.art_history_tolerance, 0.0, 100.0, "Painting tolerance"); - if area_out { - open_alert_once(app, ART_HISTORY_AREA_ALERT); - } - if tolerance_out { - open_alert_once(app, crate::panels::options_bar::ZERO_TO_100); - } - } + Tool::ArtHistoryBrush => art_history_options(app, ui), Tool::QuickSelection => { crate::widgets::checkbox(ui, &mut o.sample_all.quick_selection, tl!("Sample All Layers")); crate::widgets::checkbox(ui, &mut o.enhance_edge, tl!("Enhance Edge"));