Scale Effects: title "Scale Layer Effects" and a popup-slider percent field (#14996)

The dialog now reads "Scale Layer Effects" and its Scale row is a whole-percent
field whose arrow opens a linear 1..1000 slider, instead of the schema row's
always-shown logarithmic slider. Other wide-range rows keep their slider.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
This commit is contained in:
NaufalDzzandOpenBot committed 2026-11-19 11:57:36 +00:00
1 parent 057297bb0b
commit 47e4c5543e
3 files changed
+108 -3

No files matched your search

+2
View File
@@ -745,6 +745,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;
+35 -3
View File
@@ -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);
@@ -363,6 +369,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`]).
@@ -531,7 +561,9 @@ pub fn open(app: &mut PhotocraftApp, command: &str) -> Result<DialogId, String>
let fields = fields(app, command, &params);
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(&params, &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);
@@ -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<PhotocraftApp>> {
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<PhotocraftApp>| crate::dialogs::run(app, ui), app);
PhotocraftApp::setup_context(&h.ctx, crate::theme::AppTheme::pro());
h.run();
h
}
fn sliders(h: &Harness<'_, Box<PhotocraftApp>>) -> usize {
h.query_all_by_role(Role::Slider).count()
}
fn scale(h: &Harness<'_, Box<PhotocraftApp>>) -> 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");
}