From 645457db9c6bba3abd10a61d65a48131bbbf8e35 Mon Sep 17 00:00:00 2001
From: rmsff <17902130+rmsff@users.noreply.github.com>
Date: Fri, 13 Nov 2026 17:19:39 +0300
Subject: [PATCH] Contact Sheet II: four groups like the reference dialog
Source Images, Document, Thumbnails and Use Filename as Caption, with
Mode, Bit Depth and Place as dropdowns, a pixels/inch / pixels/cm
resolution unit, and Units converting Width and Height. The params OK
sends are unchanged (#13683).
---
crates/ui-egui/src/dialogs.rs | 1 +
.../ui-egui/src/dialogs/contact_sheet_ui.rs | 107 ++++++++++++++++++
crates/ui-egui/src/dialogs/file_forms.rs | 27 +----
crates/ui-egui/src/dialogs/filter_dialog.rs | 3 +
4 files changed, 113 insertions(+), 25 deletions(-)
create mode 100644 crates/ui-egui/src/dialogs/contact_sheet_ui.rs
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 6fb92685cf9..0cec6b89fac 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -716,6 +716,7 @@ pub mod color_picker_ui;
pub mod color_range_ui;
pub mod color_table_ui;
pub(crate) mod conditional_mode_change_dialog;
+pub(crate) mod contact_sheet_ui;
pub mod count_group_name_ui;
pub mod credits;
pub mod dds_options_ui;
diff --git a/crates/ui-egui/src/dialogs/contact_sheet_ui.rs b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs
new file mode 100644
index 00000000000..43442e207ec
--- /dev/null
+++ b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs
@@ -0,0 +1,107 @@
+//! File › Automate › Contact Sheet II…, laid out like the reference application's dialog (#13683):
+//! the sections Source Images, Document, Thumbnails and Use Filename as Caption, top to bottom.
+//!
+//! The rows are the command's params, so OK, `ui.dialog.set` and `ui.dialog.confirm` work as for every form. Three
+//! of them are kept in the shape the dialog shows and turned into the command's at OK ([`command_params`]): the
+//! resolution's unit (the command takes pixels/inch), Bit Depth (`"8"` or `"16"`) and Place (`"across"` or `"down"`).
+
+use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, NumberUnit, Param, ParamKind};
+use craft::ui::runtime::env::{Label, UnitKind};
+use craft::ui::runtime::requests::PathKind;
+use photocraft_engine::prefs::Unit;
+use serde_json::{Map, Value, json};
+
+pub(crate) const COMMAND: &str = "file.automate.contactSheetII";
+
+const UNITS: [(&str, &str); 3] = [("inches", "inches"), ("cm", "cm"), ("pixels", "pixels")];
+const MODES: [(&str, &str); 4] = [("gray", "Grayscale"), ("rgb", "RGB Color"), ("cmyk", "CMYK Color"), ("lab", "Lab Color")];
+const DEPTHS: [(&str, &str); 2] = [("8", "8-bit"), ("16", "16-bit")];
+const PLACES: [(&str, &str); 2] = [("across", "across first"), ("down", "down first")];
+
+/// Choice options whose labels are `tl!` literals here.
+fn opts(list: &[(&'static str, &'static str)]) -> Vec<(String, Label)> {
+ list.iter().map(|(id, label)| ((*id).to_owned(), Label::from(tl!(label)))).collect()
+}
+
+/// The rows of the dialog, opening on the folder `dir`.
+pub(crate) fn rows(dir: String) -> Vec {
+ let resolution = vec![
+ NumberUnit::new("in", UnitKind::PixelsPerInch, tl!("pixels/inch"), 1.0),
+ NumberUnit::new("cm", UnitKind::PixelsPerCentimetre, tl!("pixels/cm"), 2.54),
+ ];
+ vec![
+ Param::section(tl!("Source Images")),
+ Param::new("input", tl!("Input"), ParamKind::text(dir)).browse(PathKind::Folder),
+ // The folder, then Include Subfolders (on) and, right below it, Group Images by Folder (off, greyed while
+ // Include Subfolders is off).
+ Param::new("includeSubfolders", tl!("Include Subfolders"), ParamKind::bool(true)),
+ Param::new("groupByFolder", tl!("Group Images by Folder"), ParamKind::bool(false))
+ .enabled_when("includeSubfolders", true)
+ .tooltip(tl!("Images in subfolders will start on a new Contact Sheet")),
+ Param::section(tl!("Document")),
+ Param::new("units", tl!("Units"), ParamKind::choice(opts(&UNITS), Some("inches".into()))),
+ Param::custom(UNITS_SHOWN, Label::Empty, follow_units).companions(["width", "height"]).full_width(),
+ Param::new("width", tl!("Width"), ParamKind::number(Some(0.0), Some(300_000.0), 8.0, 0.5, 2)),
+ Param::new("height", tl!("Height"), ParamKind::number(Some(0.0), Some(300_000.0), 10.0, 0.5, 2)),
+ Param::number_with_units("resolution", tl!("Resolution"), 300.0, 1.0, 2, resolution).bounds(Some(1.0), Some(10_000.0)),
+ Param::new("flatten", tl!("Flatten All Layers"), ParamKind::bool(false)),
+ Param::new("mode", tl!("Mode"), ParamKind::choice(opts(&MODES), Some("rgb".into()))),
+ Param::new("depth", tl!("Bit Depth"), ParamKind::choice(opts(&DEPTHS), Some("8".into()))),
+ Param::section(tl!("Thumbnails")),
+ Param::new("place", tl!("Place"), ParamKind::choice(opts(&PLACES), Some("across".into()))),
+ Param::new("columns", tl!("Columns"), ParamKind::int(Some(1), Some(100), 5)),
+ Param::new("rows", tl!("Rows"), ParamKind::int(Some(1), Some(100), 6)),
+ Param::new("rotateForBestFit", tl!("Rotate For Best Fit"), ParamKind::bool(false)),
+ Param::new("autoSpacing", tl!("Use Auto-Spacing"), ParamKind::bool(true)),
+ Param::section(tl!("Use Filename as Caption")),
+ Param::new("caption", tl!("Use Filename as Caption"), ParamKind::bool(true)),
+ Param::new("font", tl!("Font"), ParamKind::text(photocraft_text::fonts::DEFAULT_FAMILY)).enabled_when("caption", true),
+ Param::new("fontSize", tl!("Font size"), ParamKind::number(Some(1.0), None, 12.0, 1.0, 1)).unit(UnitKind::Points).enabled_when("caption", true),
+ ]
+}
+
+/// The units Width and Height were last shown in, kept by [`follow_units`].
+const UNITS_SHOWN: &str = "unitsShown";
+
+/// Follows the Units list: switching it converts Width and Height at the resolution, as the command reads them, so
+/// the sheet keeps its size: 8 x 10 in is 20.32 x 25.4 cm, and 2400 x 3000 px at 300 ppi. The row shows nothing;
+/// Units stays a plain list, so the dialog remembers it with the size.
+fn follow_units(ui: &mut egui::Ui, fields: &mut DialogFields, _: &mut CustomContext) -> egui::Response {
+ let units = fields.text("units").unwrap_or("inches").to_owned();
+ if let Some(shown) = fields.text(UNITS_SHOWN).filter(|shown| *shown != units).map(str::to_owned) {
+ let ppi = fields.number("resolution").unwrap_or(300.0);
+ let (from, to) = (unit_of(&shown), unit_of(&units));
+ for (key, default) in [("width", 8.0), ("height", 10.0)] {
+ let v = to.from_px(from.to_px(fields.number(key).unwrap_or(default), ppi, 0.0, 72.0), ppi, 0.0, 72.0);
+ // Rounded to the field's two decimals, so a round trip comes back to the value it left.
+ fields.set(key, if to == Unit::Pixels { v.round() } else { (v * 100.0).round() / 100.0 });
+ }
+ }
+ if fields.text(UNITS_SHOWN) != Some(units.as_str()) {
+ fields.set(UNITS_SHOWN, units);
+ }
+ ui.allocate_response(egui::Vec2::ZERO, egui::Sense::hover())
+}
+
+/// The unit a `units` value stands for, read as the command reads it (inches when unknown).
+fn unit_of(units: &str) -> Unit {
+ match units {
+ "cm" => Unit::Centimeters,
+ "mm" => Unit::Millimeters,
+ "px" | "pixels" => Unit::Pixels,
+ _ => Unit::Inches,
+ }
+}
+
+/// The dialog's values as the command takes them: the resolution in pixels/inch without its unit, `depth` a number
+/// and Place as `placeAcrossFirst`.
+pub(crate) fn command_params(map: &mut Map) {
+ map.remove("resolution.unit");
+ map.remove(UNITS_SHOWN);
+ if let Some(depth) = map.get("depth").and_then(Value::as_str).and_then(|d| d.parse::().ok()) {
+ map.insert("depth".into(), json!(depth));
+ }
+ if let Some(place) = map.remove("place") {
+ map.insert("placeAcrossFirst".into(), json!(place.as_str() != Some("down")));
+ }
+}
diff --git a/crates/ui-egui/src/dialogs/file_forms.rs b/crates/ui-egui/src/dialogs/file_forms.rs
index fca18f98391..dcf6d2fc2d0 100644
--- a/crates/ui-egui/src/dialogs/file_forms.rs
+++ b/crates/ui-egui/src/dialogs/file_forms.rs
@@ -13,7 +13,7 @@ use crate::PhotocraftApp;
use crate::dialogs::params;
use crate::menus::view_cmds::dialogs::label_of;
-const CONTACT_SHEET: &str = "file.automate.contactSheetII";
+const CONTACT_SHEET: &str = crate::dialogs::contact_sheet_ui::COMMAND;
const CREATE_DROPLET: &str = "file.automate.createDroplet";
const SCRIPT_EVENTS: &str = "file.scripts.scriptEventsManager";
const PACKAGE: &str = "file.package";
@@ -69,30 +69,7 @@ fn open_form(app: &mut PhotocraftApp, key: &'static str, title: &str, rows: Vec<
/// File › Automate › Contact Sheet II.
pub(crate) fn open_contact_sheet(app: &mut PhotocraftApp) -> DialogId {
- let rows = vec![
- Param::new("input", tl!("Input"), ParamKind::text(default_dir(app))).browse(PathKind::Folder),
- // Source Images: the folder, then Include Subfolders (on) and, right below it, Group Images by
- // Folder (off, greyed while Include Subfolders is off).
- Param::new("includeSubfolders", tl!("Include Subfolders"), ParamKind::bool(true)),
- Param::new("groupByFolder", tl!("Group Images by Folder"), ParamKind::bool(false))
- .enabled_when("includeSubfolders", true)
- .tooltip(tl!("Images in subfolders will start on a new Contact Sheet")),
- Param::new("units", tl!("Units"), ParamKind::choice(ids(&["inches", "cm", "pixels"]), Some("inches".into()))),
- Param::new("width", tl!("Width"), ParamKind::number(Some(0.0), None, 8.0, 0.5, 2)),
- Param::new("height", tl!("Height"), ParamKind::number(Some(0.0), None, 10.0, 0.5, 2)),
- Param::new("resolution", tl!("Resolution"), ParamKind::number(Some(1.0), None, 300.0, 1.0, 0)),
- Param::new("mode", tl!("Mode"), ParamKind::choice(ids(&["rgb", "gray", "cmyk", "lab"]), Some("rgb".into()))),
- Param::new("depth", tl!("Depth"), ParamKind::int(Some(1), None, 8)),
- Param::new("columns", tl!("Columns"), ParamKind::int(Some(1), None, 5)),
- Param::new("rows", tl!("Rows"), ParamKind::int(Some(1), None, 6)),
- Param::new("placeAcrossFirst", tl!("Place across first"), ParamKind::bool(true)),
- Param::new("autoSpacing", tl!("Auto spacing"), ParamKind::bool(true)),
- Param::new("rotateForBestFit", tl!("Rotate for best fit"), ParamKind::bool(false)),
- Param::new("caption", tl!("Caption"), ParamKind::bool(true)),
- Param::new("font", tl!("Font"), ParamKind::text(photocraft_text::fonts::DEFAULT_FAMILY)),
- Param::new("fontSize", tl!("Font size"), ParamKind::number(Some(1.0), None, 12.0, 1.0, 1)),
- Param::new("flatten", tl!("Flatten"), ParamKind::bool(false)),
- ];
+ let rows = crate::dialogs::contact_sheet_ui::rows(default_dir(app));
open_form(app, CONTACT_SHEET, tl!("Contact Sheet II"), rows)
}
diff --git a/crates/ui-egui/src/dialogs/filter_dialog.rs b/crates/ui-egui/src/dialogs/filter_dialog.rs
index eeb780c4fff..4c239fec547 100644
--- a/crates/ui-egui/src/dialogs/filter_dialog.rs
+++ b/crates/ui-egui/src/dialogs/filter_dialog.rs
@@ -715,6 +715,9 @@ pub(crate) fn command_params(command: &str, fields: &DialogFields) -> Value {
map.insert("centerX".into(), json!(x));
map.insert("centerY".into(), json!(y));
}
+ if command == crate::dialogs::contact_sheet_ui::COMMAND {
+ crate::dialogs::contact_sheet_ui::command_params(&mut map);
+ }
if command == crate::dialogs::image_processor_ui::COMMAND {
crate::dialogs::image_processor_ui::nest(&mut map);
}