LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge origin/main into #522 (keep both new masking tests)
Brandon Thomas4c4e9b154f14
diff --cc crates/ui-egui/src/tests_masking.rsindex 6166bb21b,6a5f59e17..379282bc5--- a/crates/ui-egui/src/tests_masking.rs+++ b/crates/ui-egui/src/tests_masking.rs@@@ -39,46 -39,78 +39,118 @@@ fn develop(h: &Headless) -> lightcraft_(*h.app.session.develop_of(id).unwrap_or_default()).clone()}+#[test]+fn mask_adjustments_hide_overlay_without_disabling_the_mask() {+ use lightcraft_pipeline::Overlay;+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "linear", "start": [0.5, 0.2], "end": [0.5, 0.7]}));+ assert!(h.app.ui.mask_overlay);++ // Changing the shape needs the overlay; changing the image needs an unobscured preview.+ exec(&mut h, "mask.refine", json!({"value": 10.0}));+ assert!(h.app.ui.mask_overlay);+ let r = h.request("ui.clickWidget", json!({"id": "slider:exposure", "fx": 0.7}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(!h.app.ui.mask_overlay, "the exposure slider hides the overlay after release");+ let d = develop(&h);+ assert!(d.masks[0].adjust.exposure > 0.0);+ assert!(d.masks[0].visible, "hiding the overlay must not disable the mask");+ assert_eq!(crate::panels::detail::view_overlay(&h.app, &d), Overlay::None);+ let mask = d.masks[0].clone();++ let r = h.request("ui.key", json!({"key": "o"}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(h.app.ui.mask_overlay, "O can restore the overlay");+ assert_eq!(develop(&h).masks[0], mask, "toggling the overlay leaves the mask and its effect unchanged");+ assert!(matches!(crate::panels::detail::view_overlay(&h.app, &develop(&h)), Overlay::Mask { .. }));++ // Failed edits and global adjustments must not hide the mask overlay.+ assert!(h.app.run("mask.adjust", json!({"id": 999, "values": {"exposure": 1.0}})).is_err());+ assert!(h.app.ui.mask_overlay);+ exec(&mut h, "develop.set", json!({"control": "light.exposure", "value": 0.5}));+ assert!(h.app.ui.mask_overlay);++ // Numeric edits/resets and Amount use the same command path as the sliders.+ for values in [json!({"exposure": 0.0}), json!({"saturation": 20.0}), json!({"amount": 50.0})] {+ exec(&mut h, "view.maskOverlay", json!({"show": true}));+ exec(&mut h, "mask.adjust", json!({"values": values}));+ assert!(!h.app.ui.mask_overlay);+ }+ h.settle(SETTLE);+}++ #[test]+ fn radial_body_drag_moves_rotated_components_and_undoes_once() {+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "luminanceRange"}));+ exec(&mut h, "mask.addComponent", json!({"kind": "radial", "op": "add", "center": [0.45, 0.5], "rx": 0.22, "ry": 0.1, "angle": 40}));+ let before = develop(&h);+ // Well away from the pin and edge/rotation grips, inside a rotated ellipse.+ pointer(+ &mut h,+ json!([{"kind": "down", "x": 0.51, "y": 0.56}, {"kind": "drag", "x": 0.54, "y": 0.58},+ {"kind": "drag", "x": 0.61, "y": 0.66}, {"kind": "up", "x": 0.61, "y": 0.66}]),+ );+ let after = develop(&h);+ let MaskShape::Radial { center, rx, ry, angle, feather, invert } = &after.masks[0].components[1].shape else { panic!("radial") };+ assert!((center.x - 0.55).abs() < 0.005 && (center.y - 0.6).abs() < 0.005, "{center:?}");+ let MaskShape::Radial { rx: old_rx, ry: old_ry, angle: old_angle, feather: old_feather, invert: old_invert, .. } =+ &before.masks[0].components[1].shape+ else {+ panic!("radial")+ };+ assert_eq!((rx, ry, angle, feather, invert), (old_rx, old_ry, old_angle, old_feather, old_invert));+ assert_eq!(after.masks[0].components[0], before.masks[0].components[0], "only the hit component moves");+ exec(&mut h, "edit.undo", json!({}));+ assert_eq!(develop(&h), before, "one undo reverses the entire drag");+ exec(&mut h, "edit.redo", json!({}));+ assert_eq!(develop(&h), after);+ // The bounding-box corner is outside the ellipse, even for an inverted radial mask.+ exec(&mut h, "mask.component", json!({"component": 1, "action": "invert"}));+ let outside_before = develop(&h);+ pointer(+ &mut h,+ json!([{"kind": "down", "x": 0.35, "y": 0.75}, {"kind": "drag", "x": 0.4, "y": 0.8},+ {"kind": "up", "x": 0.4, "y": 0.8}]),+ );+ assert_eq!(develop(&h), outside_before, "outside the ellipse must not move it");+ // Hiding pins does not disable dragging the selected ellipse body.+ exec(&mut h, "view.maskPins", json!({"show": false}));+ pointer(+ &mut h,+ json!([{"kind": "down", "x": 0.61, "y": 0.66}, {"kind": "drag", "x": 0.66, "y": 0.71},+ {"kind": "up", "x": 0.66, "y": 0.71}]),+ );+ let MaskShape::Radial { center, .. } = develop(&h).masks[0].components[1].shape.clone() else { panic!("radial") };+ assert!((center.x - 0.6).abs() < 0.005 && (center.y - 0.65).abs() < 0.005, "{center:?}");+ }++ #[test]+ fn radial_body_drag_keeps_resize_and_rotation_handles() {+ let mut h = detail("panel.masking");+ exec(&mut h, "mask.add", json!({"kind": "radial", "center": [0.5, 0.5], "rx": 0.18, "ry": 0.1}));+ for handle in [1, 5] {+ let widget = format!("maskHandle:1:0:{handle}");+ let rect = h.app.widgets.iter().find(|(id, _)| *id == widget).unwrap().1;+ let image = h.app.image_rect.unwrap();+ let q = rect.center();+ let x = (q.x - image.left()) / image.width();+ let y = (q.y - image.top()) / image.height();+ pointer(+ &mut h,+ json!([{"kind": "down", "x": x, "y": y}, {"kind": "drag", "x": x + 0.03, "y": y + 0.03},+ {"kind": "up", "x": x + 0.03, "y": y + 0.03}]),+ );+ let MaskShape::Radial { center, rx, angle, .. } = develop(&h).masks[0].components[0].shape.clone() else { panic!("radial") };+ assert!((center.x - 0.5).abs() < 0.005 && (center.y - 0.5).abs() < 0.005, "a handle must not translate the mask");+ if handle == 1 {+ assert!(rx > 0.19, "resize grip changes radius");+ } else {+ assert!(angle.abs() > 1.0, "rotation grip changes angle");+ }+ }+ }+#[test]fn mask_overlay_keys_and_pins() {use lightcraft_pipeline::{MaskView, Overlay};