Merge #16395 into the merge queue batch

Auto-Align Layers: Projection radios, Lens Correction group and description line
This commit is contained in:
David Mann committed 2026-11-27 22:30:20 +01:00
commit d84dbf1ef1
4 files changed
+573 -2

No files matched your search

+3
View File
@@ -744,6 +744,9 @@ mod arbitrary_ruler_prefill_tests;
pub mod assign_profile_layers_alert;
#[cfg(test)]
mod assign_profile_layers_alert_tests;
#[cfg(test)]
mod auto_align_dialog_tests;
pub(crate) mod auto_align_ui;
pub(crate) mod bitmap_dialog;
pub mod blend_options;
pub mod blur_pins;
@@ -0,0 +1,276 @@
//! #14196: Edit › Auto-Align Layers opens the reference application's dialog: a Projection group of six radios over
//! three columns (Auto, Perspective, Collage / Cylindrical, Spherical, Reposition) with Auto selected on a fresh
//! start, a Lens Correction group (Vignette Removal, Geometric Distortion, both off; Collage and Reposition grey and
//! clear them), the selected projection's description line and the warnings under them, OK and Cancel. No
//! Interpolation or Registration rows, Alt keeps Cancel a Cancel, and the last run's projection (also a scripted
//! one) is what the dialog reopens with.
use craft::ui::dialog::DialogId;
use egui::accesskit::{Role, Toggled};
use egui::{Event, Modifiers, vec2};
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use photocraft_doc::LayerId;
use serde_json::{Value, json};
use crate::PhotocraftApp;
use crate::new_layer_ui::testing::{fields, set, top};
const COMMAND: &str = "edit.autoAlignLayers";
/// The radios in reading order: the first row, then the second.
const RADIOS: [&str; 6] = ["Auto", "Perspective", "Collage", "Cylindrical", "Spherical", "Reposition"];
type H = Harness<'static, Box<PhotocraftApp>>;
/// The deterministic texture of the engine's Auto-Align tests, written into layer `id` at offset (dx, dy).
fn paint_texture(app: &mut PhotocraftApp, id: LayerId, dx: i32, dy: i32) {
app.session
.edit("tex", |doc, _| {
let surf = doc.layer_mut(id).unwrap().surface_mut().unwrap();
let mut seed = 99u64;
let mut rnd = || {
seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
(seed >> 33) as f64 / (1u64 << 31) as f64
};
surf.fill_rect(photocraft_geom::Rect::new(dx, dy, dx + 240, dy + 180), &[0.4, 0.4, 0.4, 1.0]);
for _ in 0..120 {
let (x, y) = ((rnd() * 220.0) as i32, (rnd() * 160.0) as i32);
let (sw, sh) = (4 + (rnd() * 14.0) as i32, 4 + (rnd() * 10.0) as i32);
let v = rnd() as f32;
surf.fill_rect(photocraft_geom::Rect::new(dx + x, dy + y, dx + x + sw, dy + y + sh), &[v, 1.0 - v, v * 0.5, 1.0]);
}
Ok(())
})
.unwrap();
}
/// A 300x240 document with two textured layers, the second offset, both selected: Auto-Align can run on it.
fn two_layers(app: &mut PhotocraftApp) {
app.run("file.new", json!({"width": 300, "height": 240, "background": "transparent"})).unwrap();
let mut ids = Vec::new();
for (name, dx, dy) in [("A", 20, 20), ("B", 31, 13)] {
app.run("layer.new.layer", json!({"name": name})).unwrap();
let id = app.session.active().unwrap().active_layer.unwrap();
paint_texture(app, id, dx, dy);
ids.push(id);
}
app.run("layer.select", json!({"layer": ids[0].0})).unwrap();
app.run("layer.select", json!({"layer": ids[1].0, "mode": "add"})).unwrap();
}
/// The whole app with the two-layer document, before the dialog opens.
fn harness() -> H {
let mut h = Harness::builder().with_size(vec2(1600.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(|cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default());
app.background_jobs = false;
two_layers(&mut app);
app
});
h.run_steps(3);
h
}
/// Opens the dialog through the menu and draws a few frames.
fn open(h: &mut H) -> DialogId {
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, COMMAND, json!({})).unwrap();
let id = top(h.state());
h.run_steps(4);
id
}
fn dialog() -> (H, DialogId) {
let mut h = harness();
let id = open(&mut h);
(h, id)
}
fn radio(h: &H, label: &str) -> egui::Rect {
h.get_by_role_and_label(Role::RadioButton, label).rect()
}
fn checked(h: &H, role: Role, label: &str) -> bool {
h.get_by_role_and_label(role, label).accesskit_node().toggled() == Some(Toggled::True)
}
fn disabled(h: &H, role: Role, label: &str) -> bool {
h.get_by_role_and_label(role, label).accesskit_node().is_disabled()
}
fn sent(h: &H, id: DialogId) -> Value {
crate::filter_dialog::command_params(COMMAND, fields(h.state(), id))
}
fn shows(h: &H, text: &str) -> bool {
h.query_all_by_label(text).next().is_some()
}
#[test]
fn six_projection_radios_stand_three_by_two_with_auto_selected() {
let (h, _) = dialog();
let rects: Vec<egui::Rect> = RADIOS.iter().map(|label| radio(&h, label)).collect();
for row in [&rects[0..3], &rects[3..6]] {
for r in &row[1..] {
assert!((r.center().y - row[0].center().y).abs() < 4.0, "one row: {row:?}");
}
assert!(row[0].right() < row[1].left() && row[1].right() < row[2].left(), "left to right: {row:?}");
}
assert!(rects[3].top() > rects[0].bottom(), "Cylindrical, Spherical and Reposition stand under the first row");
for col in 0..3 {
assert!((rects[col].left() - rects[col + 3].left()).abs() < 4.0, "column {col} lines up");
}
assert!(checked(&h, Role::RadioButton, "Auto"), "a fresh dialog selects Auto");
for label in &RADIOS[1..] {
assert!(!checked(&h, Role::RadioButton, label), "{label} starts clear");
}
}
#[test]
fn the_description_line_follows_the_selected_radio() {
let (mut h, id) = dialog();
assert!(shows(&h, "Determine the best projection automatically."));
for (label, line) in [
("Perspective", "Only allow perspective image transform."),
("Collage", "Allow image rotation, scale and translation."),
("Cylindrical", "Only allow cylindrical image transform."),
("Spherical", "Only allow spherical image transform."),
("Reposition", "Only allow image translation."),
] {
h.get_by_role_and_label(Role::RadioButton, label).click();
h.run_steps(3);
assert!(shows(&h, line), "{label}: {line}");
assert!(!shows(&h, "Determine the best projection automatically."), "{label}: one description line");
assert_eq!(sent(&h, id)["projection"], json!(label.to_lowercase()));
}
}
#[test]
fn lens_correction_has_two_clear_boxes_that_collage_and_reposition_grey_and_clear() {
let (mut h, id) = dialog();
assert!(shows(&h, "Projection") && shows(&h, "Lens Correction"), "the two groups are named");
for label in ["Vignette Removal", "Geometric Distortion"] {
assert!(!checked(&h, Role::CheckBox, label), "{label} starts off");
}
h.get_by_role_and_label(Role::CheckBox, "Geometric Distortion").click();
h.run_steps(3);
assert!(checked(&h, Role::CheckBox, "Geometric Distortion"));
assert_eq!(sent(&h, id)["geometricCorrection"], json!(true), "Geometric Distortion drives geometricCorrection");
for picked in ["Collage", "Reposition"] {
h.get_by_role_and_label(Role::RadioButton, picked).click();
h.run_steps(3);
assert!(disabled(&h, Role::CheckBox, "Geometric Distortion") && disabled(&h, Role::CheckBox, "Vignette Removal"), "{picked} greys both");
assert!(!checked(&h, Role::CheckBox, "Geometric Distortion"), "{picked} clears it");
assert_eq!(sent(&h, id)["geometricCorrection"], json!(false));
}
h.get_by_role_and_label(Role::RadioButton, "Auto").click();
h.run_steps(3);
assert!(!disabled(&h, Role::CheckBox, "Geometric Distortion"), "Auto enables it again");
assert!(!checked(&h, Role::CheckBox, "Geometric Distortion"), "still cleared");
}
#[test]
fn no_interpolation_or_registration_rows_and_the_command_keeps_them() {
let (h, id) = dialog();
assert!(h.query_by_label("Interpolation").is_none(), "no Interpolation row");
assert!(h.query_by_label("Registration").is_none(), "no Registration row");
let params = sent(&h, id);
assert!(params.get("interpolation").is_none() && params.get("registration").is_none(), "the command's defaults apply: {params}");
let spec = photocraft_engine::commands::find(COMMAND).unwrap();
let keys: Vec<String> = craft::ui::patterns::form_dialogs::Param::parse_list(spec.params).into_iter().map(|p| p.key).collect();
assert!(keys.iter().any(|k| k == "interpolation") && keys.iter().any(|k| k == "registration"), "{keys:?}");
}
#[test]
fn the_metadata_warning_shows_for_layers_without_camera_metadata() {
let (h, _) = dialog();
assert!(
shows(
&h,
"Warning: Could not detect camera metadata. Use the \"File > Scripts > Load Images into Stack...\" script to preserve metadata for Vignette Removal and/or Geometric Distortion."
),
"the document has no EXIF"
);
assert!(
!shows(
&h,
"Warning: For better Vignette Removal results, shoot with the same camera, lens, aperture, resolution, orientation, focal length and focus settings."
),
"Vignette Removal is off"
);
}
/// The text block's lines: the description, the metadata warning, then the vignette warning while it is ticked.
#[test]
fn the_text_block_lists_the_warnings_in_order() {
use super::auto_align_ui::{METADATA_WARNING, VIGNETTE_WARNING, lines};
assert_eq!(lines("reposition", false, true), vec!["Only allow image translation."]);
assert_eq!(lines("auto", false, false), vec!["Determine the best projection automatically.", METADATA_WARNING]);
assert_eq!(lines("auto", true, false), vec!["Determine the best projection automatically.", METADATA_WARNING, VIGNETTE_WARNING]);
assert_eq!(lines("spherical", true, true), vec!["Only allow spherical image transform.", VIGNETTE_WARNING]);
}
#[test]
fn alt_keeps_cancel_and_escape_cancels() {
let (mut h, _) = dialog();
h.event(Event::ModifiersChanged(Modifiers::ALT));
h.run_steps(2);
assert!(h.query_by_label("Reset").is_none(), "Alt does not turn Cancel into Reset");
h.get_by_role_and_label(Role::Button, "Cancel");
h.event(Event::ModifiersChanged(Modifiers::NONE));
h.run_steps(2);
let before = h.state().session.active().unwrap().history.past_len();
h.key_press(egui::Key::Escape);
h.run_steps(3);
assert!(h.query_by_label("Only allow image translation.").is_none() && !shows(&h, "Lens Correction"), "Escape closes the dialog");
assert_eq!(h.state().session.active().unwrap().history.past_len(), before, "Escape leaves the history alone");
}
#[test]
fn ok_runs_and_the_dialog_reopens_with_the_projection_and_ticks_it_ran_with() {
let (mut h, id) = dialog();
h.get_by_role_and_label(Role::RadioButton, "Perspective").click();
h.run_steps(2);
h.get_by_role_and_label(Role::CheckBox, "Geometric Distortion").click();
h.run_steps(2);
let before = h.state().session.active().unwrap().history.past_len();
crate::dialogs::testing::confirm(h.state_mut(), id).unwrap();
h.run_steps(3);
assert_eq!(h.state().session.active().unwrap().history.past_len(), before + 1, "OK runs Auto-Align");
let id = open(&mut h);
assert!(checked(&h, Role::RadioButton, "Perspective"), "reopens with Perspective");
assert!(checked(&h, Role::CheckBox, "Geometric Distortion"), "and the tick confirmed with OK");
assert_eq!(sent(&h, id)["projection"], json!("perspective"));
}
#[test]
fn a_scripted_run_decides_the_projection_the_dialog_reopens_with() {
let mut h = harness();
// An OK with Geometric Distortion ticked first, so the script's run has something to replace.
let id = open(&mut h);
h.get_by_role_and_label(Role::CheckBox, "Geometric Distortion").click();
h.run_steps(2);
crate::dialogs::testing::confirm(h.state_mut(), id).unwrap();
h.run_steps(3);
h.state_mut().run(COMMAND, json!({"projection": "reposition"})).unwrap();
h.run_steps(2);
let id = open(&mut h);
assert!(checked(&h, Role::RadioButton, "Reposition"), "the scripted projection");
assert!(!checked(&h, Role::CheckBox, "Geometric Distortion"), "a run without the lens keys leaves the box clear");
assert!(shows(&h, "Only allow image translation."));
assert_eq!(sent(&h, id)["projection"], json!("reposition"));
}
#[test]
fn an_agent_sets_the_projection_by_its_id_and_a_bad_one_is_refused() {
let (mut h, id) = dialog();
set(h.state_mut(), id, "projection", json!("cylindrical")).unwrap();
h.run_steps(3);
assert!(checked(&h, Role::RadioButton, "Cylindrical"));
assert_eq!(sent(&h, id)["projection"], json!("cylindrical"));
// An unknown id never reaches the command: the row keeps a projection it knows.
let _ = set(h.state_mut(), id, "projection", json!("sideways"));
h.run_steps(3);
let projection = sent(&h, id)["projection"].as_str().unwrap().to_owned();
assert!(RADIOS.iter().any(|r| r.to_lowercase() == projection), "{projection}");
}
+285
View File
@@ -0,0 +1,285 @@
//! Edit › Auto-Align Layers: the reference application's dialog (#14196). A Projection group of six radios with a
//! small picture under each (3 x 2), a Lens Correction group with Vignette Removal and Geometric Distortion, and a
//! text block at the foot: the selected projection's description and the warnings. OK and Cancel; Alt does not turn
//! Cancel into Reset.
//!
//! It stays the command's schema dialog (`filter_dialog::open`), so Enter / Escape, `ui.dialog.*`, action step
//! dialogs and the no-match alert work as for every other command dialog; only its rows and buttons differ. The
//! command keeps its `interpolation` and `registration` params for scripts: the dialog has no rows for them, so the
//! command's own defaults apply.
//!
//! Memory: the projection lives in a hidden radio row ([`LAST`]) the framework remembers on OK beside the two boxes.
//! A run that did not come from this dialog (a script, the control channel, an action step) lands in the session's
//! journal; opening the dialog copies the last journaled run into those remembered values, so it reopens with the
//! projection (and the lens keys) that run used.
use craft::behavior::ColumnWidth;
use craft::ui::choice::{Radio, RadioGroup};
use craft::ui::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _};
use craft::ui::display::{Shade, Text};
use craft::ui::layout_components::{Grid, Stack};
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamKind};
use craft::ui::runtime::env::Label;
use craft::ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
use egui::{Color32, Pos2, Rect, Shape, Stroke, pos2, vec2};
use serde_json::{Map, Value};
use crate::PhotocraftApp;
use crate::theme::Tokens;
pub const COMMAND: &str = "edit.autoAlignLayers";
/// The projection the command runs with. The custom row writes it; an agent's `ui.dialog.set` may too.
pub const PROJECTION: &str = "projection";
/// The hidden radio row that keeps the projection the framework remembers (a custom row's value is not remembered).
pub const LAST: &str = "__projection";
/// The Geometric Distortion box: the command's `geometricCorrection`.
pub const GEOMETRIC: &str = "geometricCorrection";
/// The Vignette Removal box: the command's `vignetteRemoval`, once the engine takes it (#14197).
pub const VIGNETTE: &str = "vignetteRemoval";
/// The projections in the reference application's order, row by row over three columns: id, label and the
/// description line it shows while selected.
pub const PROJECTIONS: [(&str, &str, &str); 6] = [
("auto", "Auto", "Determine the best projection automatically."),
("perspective", "Perspective", "Only allow perspective image transform."),
("collage", "Collage", "Allow image rotation, scale and translation."),
("cylindrical", "Cylindrical", "Only allow cylindrical image transform."),
("spherical", "Spherical", "Only allow spherical image transform."),
("reposition", "Reposition", "Only allow image translation."),
];
/// The projections that grey and clear both Lens Correction boxes.
const NO_LENS: [&str; 2] = ["collage", "reposition"];
const COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content];
/// The picture under each radio, in points.
const PICTURE: egui::Vec2 = vec2(64.0, 40.0);
/// The text under the boxes when the layers carry no camera metadata.
pub const METADATA_WARNING: &str = "Warning: Could not detect camera metadata. Use the \"File > Scripts > Load Images into Stack...\" script to preserve metadata for Vignette Removal and/or Geometric Distortion.";
/// The text under the boxes while Vignette Removal is ticked.
pub const VIGNETTE_WARNING: &str =
"Warning: For better Vignette Removal results, shoot with the same camera, lens, aperture, resolution, orientation, focal length and focus settings.";
/// `id` when it names one of the six projections.
fn known(id: &str) -> Option<&'static str> {
PROJECTIONS.iter().map(|(p, _, _)| *p).find(|p| *p == id)
}
/// Whether the projection `id` lets the Lens Correction boxes take input.
pub fn lens_allowed(id: &str) -> bool {
!NO_LENS.contains(&id)
}
/// Whether the engine's command takes `vignetteRemoval` yet (#14197); until then the box is shown disabled.
pub fn vignette_supported() -> bool {
photocraft_engine::commands::find(COMMAND).is_some_and(|c| Param::parse_list(c.params).iter().any(|p| p.key == VIGNETTE))
}
/// The projection the dialog's values hold: the row's own value (text, or the JSON string `ui.dialog.set` writes),
/// else the remembered one, else Auto.
pub fn projection(fields: &DialogFields) -> &'static str {
let own = match fields.get(PROJECTION) {
Some(FieldValue::Text(id)) => known(id),
Some(FieldValue::Json(Value::String(id))) => known(id),
_ => None,
};
own.or_else(|| fields.text(LAST).and_then(known)).unwrap_or("auto")
}
/// The save key the schema dialog remembers this command's values under.
fn remembered_key() -> SaveKey {
SaveKey::named(super::params::memory_scope(COMMAND))
}
/// Whether the active document carries camera metadata (a camera make or model in its EXIF).
fn has_camera_metadata(app: &PhotocraftApp) -> bool {
app.session.active().and_then(|st| st.doc.metadata.exif.as_ref()).is_some_and(|exif| {
let info = photocraft_algo::exif::read(exif);
info.make.is_some_and(|m| !m.trim().is_empty()) || info.model.is_some_and(|m| !m.trim().is_empty())
})
}
/// Copies the session's last journaled run of the command into the values the dialog remembers, so a run from a
/// script, the control channel or an action step decides what the dialog reopens with, as one confirmed with OK
/// does. Keys the run left out are their defaults: a scripted run without the lens keys leaves both boxes clear.
pub(crate) fn adopt_last_run(app: &PhotocraftApp) {
let Some((_, params)) = app.session.journal.iter().rev().find(|(id, _)| id == COMMAND) else { return };
let ctx = app.ctx();
let key = remembered_key();
let mut saved = saved_value::<Option<DialogFields>>(ctx, &key).unwrap_or_default();
let id = params.get(PROJECTION).and_then(Value::as_str).and_then(known).unwrap_or("auto");
let lens = lens_allowed(id);
let flag = |k: &str| lens && params.get(k).and_then(Value::as_bool).unwrap_or(false);
saved.set(LAST, FieldValue::Text(id.to_owned()));
saved.set(GEOMETRIC, FieldValue::Bool(flag(GEOMETRIC)));
saved.set(VIGNETTE, FieldValue::Bool(flag(VIGNETTE)));
set_saved_value(ctx, &key, Some(saved));
}
/// The dialog's rows, in place of the schema's: the Projection group, the Lens Correction group and the text block.
/// Opening also adopts the last journaled run ([`adopt_last_run`]).
pub(crate) fn params(app: &PhotocraftApp) -> Vec<Param> {
adopt_last_run(app);
let metadata = has_camera_metadata(app);
let lens: Vec<String> = PROJECTIONS.iter().map(|(id, _, _)| *id).filter(|id| lens_allowed(id)).map(str::to_owned).collect();
let vignette_on: Vec<String> = if vignette_supported() { lens.clone() } else { Vec::new() };
let options = PROJECTIONS.iter().map(|(id, label, _)| ((*id).to_owned(), Label::from(crate::i18n::t(label).to_string()))).collect();
vec![
Param::section(tl!("Projection")),
// The remembered projection: never shown, never sent (keys under `__` are not command params).
Param::new(LAST, tl!("Projection"), ParamKind::radio(options, Some("auto".into()))).visible_when("__hidden", true),
Param::custom(PROJECTION, tl!("Projection"), |ui, fields, _| projection_row(ui, fields)).full_width(),
Param::section(tl!("Lens Correction")),
Param::new(VIGNETTE, tl!("Vignette Removal"), ParamKind::bool(false)).enabled_when_in(LAST, vignette_on),
Param::new(GEOMETRIC, tl!("Geometric Distortion"), ParamKind::bool(false)).enabled_when_in(LAST, lens),
Param::custom("__notes", Label::Empty, move |ui, fields, _| notes(ui, fields, metadata)).full_width(),
]
}
/// The command params of the dialog's values: the projection the row shows (the remembered one when the row never
/// drew), no lens correction under Collage or Reposition, and no `vignetteRemoval` until the engine takes it.
pub(crate) fn command_params(map: &mut Map<String, Value>, fields: &DialogFields) {
let id = projection(fields);
map.insert(PROJECTION.into(), Value::String(id.to_owned()));
if !lens_allowed(id) {
map.insert(GEOMETRIC.into(), Value::Bool(false));
map.insert(VIGNETTE.into(), Value::Bool(false));
}
if !vignette_supported() {
map.remove(VIGNETTE);
}
}
/// Keeps the values in step with the projection: both keys hold it as text, and Collage or Reposition clears the
/// Lens Correction boxes (switching back leaves them clear).
fn settle(fields: &mut DialogFields, id: &str) {
if fields.get(PROJECTION) != Some(&FieldValue::Text(id.to_owned())) {
fields.set(PROJECTION, FieldValue::Text(id.to_owned()));
}
if fields.text(LAST) != Some(id) {
fields.set(LAST, FieldValue::Text(id.to_owned()));
}
if !lens_allowed(id) {
for key in [GEOMETRIC, VIGNETTE] {
if fields.bool(key) != Some(false) {
fields.set(key, FieldValue::Bool(false));
}
}
}
}
/// The six radios over three columns, each with its picture under it. A press on a picture selects nothing.
fn projection_row(ui: &mut egui::Ui, fields: &mut DialogFields) -> egui::Response {
let current = projection(fields);
settle(fields, current);
let group = RadioGroup::new(tl!("Projection").to_owned(), Bind::given(current.to_owned())).show(ui, |ui, _| {
Grid::new(COLUMNS).gap(Gap::Section).show(ui, |ui, _| {
for (id, label, _) in PROJECTIONS {
Stack::new().show(ui, |ui, _| {
Radio::new(id.to_owned()).label(crate::i18n::t(label).to_string()).show(ui);
picture(ui, id);
});
}
});
});
if let Some(picked) = group.output.value().and_then(|id| known(id)) {
settle(fields, picked);
}
group.output.response.clone()
}
/// The lines of the text block at the foot, in English: the projection `id`'s description, the metadata warning when
/// the layers carry no camera `metadata`, then the vignette warning while `vignette` is ticked.
pub fn lines(id: &str, vignette: bool, metadata: bool) -> Vec<&'static str> {
let mut out: Vec<&'static str> = PROJECTIONS.iter().filter(|(p, _, _)| *p == id).map(|(_, _, d)| *d).collect();
if !metadata {
out.push(METADATA_WARNING);
}
if vignette {
out.push(VIGNETTE_WARNING);
}
out
}
/// The text block at the foot ([`lines`]): the description, then the warnings, dimmer.
fn notes(ui: &mut egui::Ui, fields: &mut DialogFields, metadata: bool) -> egui::Response {
let shown = lines(projection(fields), fields.bool(VIGNETTE) == Some(true), metadata);
Stack::new()
.show(ui, |ui, _| {
for (k, line) in shown.iter().enumerate() {
let text = Text::new(crate::i18n::t(line).to_string());
if k == 0 {
text.show(ui)
} else {
text.shade(Shade::Muted).show(ui)
};
}
})
.output
}
/// The small line drawing under a projection's radio (look only; it takes no press).
fn picture(ui: &mut egui::Ui, id: &str) {
let (rect, _) = ui.allocate_exact_size(PICTURE, egui::Sense::hover());
let t = Tokens::get(ui.ctx());
let painter = ui.painter_at(rect);
painter.rect_filled(rect, t.radius_sm, t.field);
let ink = Stroke::new(1.0, t.icon);
let fill = t.accent_soft;
let c = rect.center();
let image = Rect::from_center_size(c, vec2(22.0, 15.0));
let poly = |points: Vec<Pos2>| Shape::convex_polygon(points, fill, ink);
match id {
"auto" => {
painter.rect(image, 0.0, fill, ink, egui::StrokeKind::Inside);
for (corner, out) in [
(image.left_top(), vec2(-6.0, -5.0)),
(image.right_top(), vec2(6.0, -5.0)),
(image.left_bottom(), vec2(-6.0, 5.0)),
(image.right_bottom(), vec2(6.0, 5.0)),
] {
painter.arrow(corner, out, ink);
}
}
"perspective" => {
painter.add(poly(vec![pos2(c.x - 26.0, c.y - 6.0), pos2(c.x - 12.0, c.y - 10.0), pos2(c.x - 12.0, c.y + 10.0), pos2(c.x - 26.0, c.y + 6.0)]));
painter.rect(Rect::from_center_size(c, vec2(22.0, 20.0)), 0.0, fill, ink, egui::StrokeKind::Inside);
painter.add(poly(vec![pos2(c.x + 12.0, c.y - 10.0), pos2(c.x + 26.0, c.y - 6.0), pos2(c.x + 26.0, c.y + 6.0), pos2(c.x + 12.0, c.y + 10.0)]));
}
"collage" => {
let turn = egui::emath::Rot2::from_angle(-0.3);
let corners = [vec2(-11.0, -7.5), vec2(11.0, -7.5), vec2(11.0, 7.5), vec2(-11.0, 7.5)];
painter.add(poly(corners.iter().map(|v| c + turn * *v).collect()));
let (a, b) = (pos2(c.x + 10.0, c.y + 14.0), pos2(c.x + 24.0, c.y + 4.0));
painter.arrow(a, b - a, ink);
painter.arrow(b, a - b, ink);
}
"cylindrical" => {
let mut top: Vec<Pos2> =
(0..=8).map(|k| k as f32 / 8.0).map(|s| pos2(c.x - 18.0 + 36.0 * s, c.y - 10.0 + 4.0 * (s - 0.5).powi(2) * 4.0 - 4.0)).collect();
let bottom: Vec<Pos2> =
(0..=8).rev().map(|k| k as f32 / 8.0).map(|s| pos2(c.x - 18.0 + 36.0 * s, c.y + 10.0 - 4.0 * (s - 0.5).powi(2) * 4.0 + 4.0)).collect();
top.extend(bottom);
painter.add(Shape::closed_line(top.clone(), ink));
painter.add(Shape::line(vec![pos2(c.x, c.y - 14.0), pos2(c.x, c.y + 14.0)], Stroke::new(1.0, t.text_faint)));
}
"spherical" => {
// An image whose corners are pulled in: each side bows inward.
let (l, r, tp, b) = (c.x - 16.0, c.x + 16.0, c.y - 12.0, c.y + 12.0);
let side = |from: Pos2, to: Pos2, bow: egui::Vec2| -> Vec<Pos2> {
(0..8).map(|k| k as f32 / 8.0).map(|s| from + (to - from) * s - bow * (1.0 - (2.0 * s - 1.0).powi(2))).collect()
};
let mut outline = side(pos2(l, tp), pos2(r, tp), vec2(0.0, -4.0));
outline.extend(side(pos2(r, tp), pos2(r, b), vec2(4.0, 0.0)));
outline.extend(side(pos2(r, b), pos2(l, b), vec2(0.0, 4.0)));
outline.extend(side(pos2(l, b), pos2(l, tp), vec2(-4.0, 0.0)));
painter.add(Shape::closed_line(outline, ink));
}
_ => {
// Reposition: the image with blocks around it.
painter.rect(image, 0.0, fill, ink, egui::StrokeKind::Inside);
for offset in [vec2(-20.0, -9.0), vec2(20.0, -9.0), vec2(-20.0, 9.0), vec2(20.0, 9.0)] {
painter.rect(Rect::from_center_size(c + offset, vec2(10.0, 8.0)), 0.0, Color32::TRANSPARENT, ink, egui::StrokeKind::Inside);
}
}
}
}
+9 -2
View File
@@ -380,6 +380,10 @@ pub(crate) fn params(app: &mut PhotocraftApp, command: &str, spec: &str) -> Vec<
if command == super::rotate_canvas_ui::COMMAND {
list = super::rotate_canvas_ui::params();
}
// Auto-Align Layers: the Projection and Lens Correction groups and the text block (#14196).
if command == super::auto_align_ui::COMMAND {
list = super::auto_align_ui::params(app);
}
rows::custom_rows(app, command, &mut list);
if command == color_settings_presets::COMMAND {
// The Settings menu: Custom, a greyed group label and the named setups in groups (#14229).
@@ -583,8 +587,8 @@ fn builder(
.reset_to(reset.clone())
.layout(ParamLayout::Stacked)
.previews(preview)
// Alt keeps Rotate Canvas's Cancel a Cancel, as in the reference application (#14462).
.alt_resets(key != super::rotate_canvas_ui::COMMAND)
// Alt keeps Rotate Canvas's and Auto-Align's Cancel a Cancel, as in the reference application (#14462, #14196).
.alt_resets(key != super::rotate_canvas_ui::COMMAND && key != super::auto_align_ui::COMMAND)
.alert_title(tl!("PhotoCraft"));
if let Some(canvas) = canvas {
dialog = dialog.canvas(canvas);
@@ -741,6 +745,9 @@ pub(crate) fn command_params(command: &str, fields: &DialogFields) -> Value {
if command == super::rotate_canvas_ui::COMMAND {
super::rotate_canvas_ui::command_params(&mut map);
}
if command == super::auto_align_ui::COMMAND {
super::auto_align_ui::command_params(&mut map, fields);
}
// After dialog keys have been reshaped into command keys (Image Processor's jpeg/width
// becomes jpeg.width, and so on). Doing this earlier dropped those rows.
// Drop display-only and other keys a closed schema does not take (Bitmap's Input row is