diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 6455264b37..4cd8bd960a 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -747,6 +747,8 @@ mod paths_export_document_bounds_tests; pub(crate) mod pattern_fill_ui; pub mod preset_group_prompt; pub mod rasterize_prompt; +#[cfg(test)] +mod scale_effects_layout_tests; pub mod screen_picker; pub mod select_mask_ui; pub mod shape_dialog; diff --git a/crates/ui-egui/src/dialogs/filter_dialog.rs b/crates/ui-egui/src/dialogs/filter_dialog.rs index 10785249b4..4962c83ca9 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog.rs @@ -10,12 +10,14 @@ use std::sync::Arc; +use craft::behavior::NumberCodec; use craft::host::{PickRequest, Picked}; -use craft::ui::contract::Bind; +use craft::ui::contract::{Bind, Show as _}; use craft::ui::dialog::{DialogId, dialog_id}; use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult}; -use craft::ui::runtime::env::{Label, UnitKind}; +use craft::ui::runtime::env::{Env, Label, UnitKind}; use craft::ui::runtime::requests::PathKind; +use craft::ui::text::NumberField; use photocraft_doc::Document; use photocraft_engine::color_cmds::ColorSettings; use serde_json::{Map, Value, json}; @@ -26,6 +28,7 @@ mod rows; pub(crate) use rows::{REPLACE_COLOR, replace_color_sample}; const MATCH_COLOR: &str = "image.adjustments.matchColor"; +const SCALE_EFFECTS: &str = "layer.layerStyle.scaleEffects"; #[cfg(test)] pub(crate) const MATCH_COLOR_DESTINATION: &str = "__matchColorDestination"; @@ -302,6 +305,9 @@ pub(crate) fn params(app: &mut PhotocraftApp, command: &str, spec: &str) -> Vec< let kind = if command == "layer.layerStyle.globalLight" { ParamKind::angle_in(min, max, default, 0) } else { ParamKind::angle(default) }; p = Param::new(p.key, p.label, kind); } + if command == SCALE_EFFECTS && p.key == "scale" { + return scale_effects_row(p); + } if let ParamKind::Range { max, .. } = p.kind { if is_pixel_param_of(command, &p.key) { p = p.unit(UnitKind::Pixels); @@ -369,6 +375,30 @@ pub(crate) fn params(app: &mut PhotocraftApp, command: &str, spec: &str) -> Vec< list } +/// Scale Layer Effects' row, as in Photoshop (#14996): a whole-percent field whose arrow opens a linear slider over +/// the range, where the schema's range row would draw an always-shown logarithmic slider for 1..1000. +fn scale_effects_row(p: Param) -> Param { + let ParamKind::Range { min, max, default, .. } = p.kind else { return p }; + let label = p.label; + Param::custom("scale", label.clone(), move |ui, fields, _| { + let value = fields.number("scale").unwrap_or(default); + let codec = NumberCodec::new(Env::of(ui).units().reader(None), 0); + let shown = NumberField::new(label.clone(), Bind::given(Some(value))) + .codec(codec) + .range(min..=max) + .step(1.0) + .commit_decimals(0) + .unit("%") + .popup_slider(min..=max) + .show(ui); + if let Some(v) = shown.edit.value().copied().flatten() { + fields.set("scale", v.round()); + } + shown.edit.response + }) + .opens_with(default) +} + /// The values `command`'s dialog opens with before the remembered ones: the open document's, the /// session's and the captured editing target. Each is the dialog's own opening state, so the Alt /// reset restores them too (through [`reset_values`]). @@ -548,7 +578,9 @@ pub fn open(app: &mut PhotocraftApp, command: &str) -> Result let fields = fields(app, command, ¶ms); let captured = if command == MATCH_COLOR { json!(app.session.active().map(|st| (st.doc.id, st.active_layer))) } else { Value::Null }; let reset = reset_values(¶ms, &fields); - let build = builder(app, command, title_of(spec.label), params, reset); + // Photoshop titles the Scale Effects… dialog with the longer name (#14996). + let title = if command == SCALE_EFFECTS { Label::from(tl!("Scale Layer Effects")) } else { title_of(spec.label) }; + let build = builder(app, command, title, params, reset); let id = crate::dialogs::params::open_param(app, command, fields, captured, build); if command == MATCH_COLOR { reconcile_match_color(app); diff --git a/crates/ui-egui/src/dialogs/scale_effects_layout_tests.rs b/crates/ui-egui/src/dialogs/scale_effects_layout_tests.rs new file mode 100644 index 0000000000..a76502fad6 --- /dev/null +++ b/crates/ui-egui/src/dialogs/scale_effects_layout_tests.rs @@ -0,0 +1,71 @@ +//! #14996: Scale Layer Effects is titled as in Photoshop and its one row is a whole-percent field whose arrow opens a +//! linear slider, instead of the schema dialog's always-shown logarithmic slider for 1..1000. + +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use crate::{PhotocraftApp, Services}; + +const SCALE_EFFECTS: &str = "layer.layerStyle.scaleEffects"; + +/// The app with a document open and `command`'s dialog shown through `dialogs::run`. +fn dialog(command: &str) -> Harness<'static, Box> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default()); + app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); + super::filter_dialog::open(&mut app, command).unwrap(); + let mut h = Harness::builder() + .with_context(app.ctx().clone()) + .with_size(egui::vec2(900.0, 700.0)) + .build_ui_state(|ui, app: &mut Box| crate::dialogs::run(app, ui), app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::AppTheme::pro()); + h.run(); + h +} + +fn sliders(h: &Harness<'_, Box>) -> usize { + h.query_all_by_role(Role::Slider).count() +} + +fn scale(h: &Harness<'_, Box>) -> f64 { + h.get_by_role_and_label(Role::SpinButton, "Scale").accesskit_node().numeric_value().expect("the Scale field has a number") +} + +#[test] +fn the_dialog_is_titled_scale_layer_effects() { + let h = dialog(SCALE_EFFECTS); + assert!(h.query_by_role_and_label(Role::Dialog, "Scale Layer Effects").is_some()); + assert!(h.query_by_role_and_label(Role::Dialog, "Scale Effects").is_none()); +} + +#[test] +fn the_scale_row_is_a_field_with_a_popup_slider_and_no_drawn_slider() { + let h = dialog(SCALE_EFFECTS); + assert_eq!(scale(&h), 100.0); + assert_eq!(sliders(&h), 0, "no slider is drawn under the field"); + assert!(h.query_by_role_and_label(Role::Button, "Slider").is_some(), "the field has the popup-slider arrow"); +} + +#[test] +fn the_popup_slider_runs_linearly_over_1_to_1000_and_sets_the_field() { + let mut h = dialog(SCALE_EFFECTS); + h.get_by_role_and_label(Role::Button, "Slider").click(); + h.run(); + let track = h.get_by_role(Role::Slider).rect(); + let middle = track.center(); + h.hover_at(middle); + h.drag_at(middle); + h.run(); + h.drop_at(middle); + h.run(); + let value = scale(&h); + assert!((450.0..=550.0).contains(&value), "the middle of a linear 1..1000 slider is about 500, got {value}"); + assert_eq!(value.fract(), 0.0, "whole percents"); +} + +#[test] +fn other_wide_range_rows_keep_their_drawn_slider() { + let h = dialog("filter.blur.gaussianBlur"); + assert_eq!(sliders(&h), 1, "Gaussian Blur's 0.1..1000 radius keeps today's slider"); +}