Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #6150: File Info: the reference app field order and labels (#6125, #6126)

aiongg5e80f833c156
diff --cc crates/ui-egui/src/view_cmds/tests.rs
index 3e579e0c6,7036c018a..05c1f1bb6
--- a/crates/ui-egui/src/view_cmds/tests.rs
+++ b/crates/ui-egui/src/view_cmds/tests.rs
@@@ -610,146 -507,27 +610,171 @@@ fn esc_leaves_full_screen_modes_unless_
assert!(app.session.active().unwrap().doc.selection.is_some());
}
+#[test]
+fn creating_a_selection_restores_hidden_extras() {
+ let mut hidden = Vec::new();
+ for (command, params) in [
+ ("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})),
+ ("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20, "ellipse": true})),
+ ("select.lasso", json!({"points": [[10,10], [30,10], [20,30]]})),
+ ("select.magneticLasso", json!({"points": [[10,10], [30,10], [20,30]], "trace": false})),
+ ("select.magicWand", json!({"x": 10, "y": 10})),
+ ("select.quick", json!({"points": [[10,10]], "size": 8})),
+ ("select.loadSelection", json!({"channel": "transparency"})),
+ ("select.loadLuminosity", json!({})),
+ ] {
+ let (mut app, ctx) = app_with(1);
+ app.run("edit.fill", json!({"color": "#cc4422"})).unwrap();
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ assert!(!app.ui.view.extras, "explicit hide remains effective before a new selection");
+ app.run(command, params).unwrap();
+ assert!(app.session.active().unwrap().doc.selection.is_some(), "{command} creates a selection");
+ if !app.ui.view.shows(app.ui.view.show.selection_edges) || checked(&app, "view.extras") != Some(true) {
+ hidden.push(command);
+ }
+ }
+ assert!(hidden.is_empty(), "new selections stayed hidden after Extras was disabled: {hidden:?}");
+}
+
+#[test]
+fn failed_selection_and_unrelated_edits_keep_extras_hidden() {
+ let (mut app, ctx) = app_with(1);
+ app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ assert!(!app.ui.view.extras);
+ assert!(app.run("select.rect", json!({"x": "invalid"})).is_err());
+ assert!(!app.ui.view.extras, "failed selection must not change the view");
+ app.run("edit.fill", json!({"color": "#cc4422"})).unwrap();
+ assert!(!app.ui.view.extras, "painting an existing hidden selection keeps it hidden");
+ app.run("select.deselect", json!({})).unwrap();
+ assert!(!app.ui.view.extras, "deselecting has no new outline to reveal");
+}
+
+#[test]
+fn new_selection_preserves_individual_show_preferences() {
+ let (mut app, ctx) = app_with(1);
+ app.ui.view.show.selection_edges = false;
+ app.ui.view.show.pixel_grid = false;
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
+ assert!(app.ui.view.extras);
+ assert!(!app.ui.view.show.selection_edges);
+ assert!(!app.ui.view.show.pixel_grid);
+}
+
+#[test]
+fn object_selection_finding_nothing_keeps_extras_hidden() {
+ let (mut app, ctx) = app_with(1);
+ app.run("edit.fill", json!({"color": "#ffffff"})).unwrap();
+ app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ let result = app.run("select.object", json!({"point": [3,3]})).unwrap();
+ assert_eq!(result["changed"], false);
+ assert!(app.session.active().unwrap().doc.selection.is_some());
+ assert!(!app.ui.view.extras, "finding no object must not reveal an old selection");
+}
+
+#[test]
+fn object_selection_restores_extras_when_it_finds_an_object() {
+ let (mut app, ctx) = app_with(0);
+ app.run("file.new", json!({"width": 200, "height": 160})).unwrap();
+ app.run("edit.fill", json!({"color": "#4073b3"})).unwrap();
+ app.run("select.rect", json!({"x": 55, "y": 35, "width": 90, "height": 90, "ellipse": true})).unwrap();
+ app.run("edit.fill", json!({"color": "#e64d26"})).unwrap();
+ app.run("select.deselect", json!({})).unwrap();
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ assert!(!app.ui.view.extras);
+ let result = app.run("select.object", json!({"rect": [45,25,110,110]})).unwrap();
+ assert_eq!(result["changed"], true, "the fixture must produce a new object selection");
+ let selection = app.session.active().unwrap().doc.selection.as_ref().unwrap();
+ assert!(selection.sample_channel(100, 80, 0) > 0.5, "the central object is selected");
+ assert!(app.ui.view.shows(app.ui.view.show.selection_edges));
+}
+
+/// #6017: a click into another tile activated that document and moved it to the first tile, so
+/// the two side-by-side documents swapped places. Each document keeps its tile; with more
+/// documents than tiles, the shown run slides just enough to include the active one.
+#[test]
+fn arranged_documents_keep_their_tiles() {
+ let rect = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(900.0, 600.0));
+ let (mut app, _) = app_with(3);
+ app.ui.view.arrange = "tileAllVertically".into();
+ for active in 0..3 {
+ app.session.set_active(active);
+ let shown = crate::canvas::arranged_cells(&app, rect).unwrap();
+ let order: Vec<usize> = shown.iter().map(|(d, _)| *d).collect();
+ assert_eq!(order, vec![0, 1, 2], "active {active}");
+ assert!(shown.windows(2).all(|w| w[0].1.left() < w[1].1.left()), "document 0 on the left");
+ }
+ app.ui.view.arrange = "twoUpVertical".into();
+ // As `documents` draws them: the shown run is kept from frame to frame.
+ let docs = |app: &mut PhotocraftApp, active: usize| {
+ app.session.set_active(active);
+ let shown: Vec<usize> = crate::canvas::arranged_cells(app, rect).unwrap().iter().map(|(d, _)| *d).collect();
+ app.arrange_start = shown[0];
+ shown
+ };
+ assert_eq!(docs(&mut app, 0), vec![0, 1]);
+ assert_eq!(docs(&mut app, 1), vec![0, 1], "the second tile's document stays on the right");
+ assert_eq!(docs(&mut app, 2), vec![1, 2], "the third document slides in next to the second");
+ assert_eq!(docs(&mut app, 1), vec![1, 2], "a click into the visible document 1 leaves the tiles as they are");
+ assert_eq!(docs(&mut app, 0), vec![0, 1], "a hidden document slides in from the left");
+ assert_eq!(docs(&mut app, 1), vec![0, 1]);
+}
+
+/// #6017: rulers showed in the active tile only; the other tile had none and no room for them.
+#[test]
+fn every_arranged_tile_has_rulers() {
+ use egui_kittest::Harness;
+ let (mut app, _) = app_with(2);
+ app.ui.view.arrange = "tileAllVertically".into();
+ app.ui.extras.rulers = true;
+ let mut h = Harness::builder().with_size(egui::vec2(1000.0, 600.0)).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ return;
+ }
+ egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run_steps(4);
+ let right = h.state().last_canvas_rect.center().x;
+ // Ruler labels are 9 pt text: some lie in each half of the document area.
+ let mut labels = [0, 0];
+ for s in &h.output().shapes {
+ if let egui::Shape::Text(t) = &s.shape
+ && t.galley.job.sections.first().is_some_and(|sec| sec.format.font_id.size == 9.0)
+ && t.galley.text().chars().all(|c| c.is_ascii_digit())
+ {
+ labels[usize::from(t.pos.x > right)] += 1;
+ }
+ }
+ assert!(labels[0] > 0 && labels[1] > 0, "ruler labels per tile: {labels:?}");
+}
++
+ #[test]
+ fn file_info_dialog_matches_photoshop_field_order_and_labels() {
+ crate::i18n::with_language(crate::i18n::Lang::EN, || {
+ let (mut app, ctx) = app_with(1);
+ let d = menu(&mut app, &ctx, "file.fileInfo", json!({})).unwrap()["dialog"].as_u64().unwrap();
+ let fields = app.ui.dialog_mut(d).unwrap().fields.clone();
+ assert_eq!(
+ form_keys(&fields).iter().map(String::as_str).collect::<Vec<_>>(),
+ ["title", "author", "authorTitle", "description", "keywords", "copyrightStatus", "copyright", "copyrightUrl"]
+ );
+ let labels = fields["__labels"].as_object().unwrap();
+ assert_eq!(labels["title"], "Document Title");
+ assert_eq!(labels["copyright"], "Copyright Notice");
+ assert_eq!(labels["copyrightUrl"], "Copyright Info URL");
+ });
+ }
+
+ #[test]
+ fn form_keys_orders_by_order_then_catalogue() {
+ let f = json!({"zeta": "", "alpha": "", "mid": "", "__order": ["mid", "zeta", "ghost"]}).as_object().unwrap().clone();
+ assert_eq!(form_keys(&f).iter().map(String::as_str).collect::<Vec<_>>(), ["mid", "zeta", "alpha"]);
+ let f = json!({"zeta": "", "alpha": ""}).as_object().unwrap().clone();
+ assert_eq!(form_keys(&f).iter().map(String::as_str).collect::<Vec<_>>(), ["alpha", "zeta"]);
+ }