diff --git a/crates/ui-egui/src/dialogs/adjust_dialog/tests.rs b/crates/ui-egui/src/dialogs/adjust_dialog/tests.rs index 6b83cc623a4..1ecae26d66e 100644 --- a/crates/ui-egui/src/dialogs/adjust_dialog/tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_dialog/tests.rs @@ -369,6 +369,7 @@ fn command_click_adds_nothing_without_the_modifier_on_a_full_curve_or_with_an_ey let mut app = app_with_image(); let id = open(&mut app, "image.adjustments.curves").unwrap(); let before = params(&mut app, id); + crate::canvas::testing::clear_of_dialogs(&mut app, [8.0, 8.0]); click(&mut app, 8.0, 8.0, egui::Modifiers::NONE); assert_eq!(params(&mut app, id), before, "no modifier, no point"); @@ -381,6 +382,7 @@ fn command_click_adds_nothing_without_the_modifier_on_a_full_curve_or_with_an_ey let mut app = app_with_image(); let id = open(&mut app, "image.adjustments.curves").unwrap(); arm(&mut app, id, TonePicker::Black); + crate::canvas::testing::clear_of_dialogs(&mut app, [8.0, 8.0]); click(&mut app, 8.0, 8.0, egui::Modifiers::COMMAND); assert_eq!(channel_points(&mut app, "points").len(), 2, "the armed eyedropper samples instead"); assert_eq!(channel_points(&mut app, "red")[0], [176.0, 0.0]); @@ -460,22 +462,30 @@ fn command_click_adds_nothing_in_lab_or_on_a_targeted_mask() { } } +/// `ui.pointer` drives an armed Curves picker as the mouse does: a hover samples nothing, the press samples and the +/// release samples nothing more; the picker stays armed. #[test] fn ui_pointer_drives_an_armed_curves_picker() { let mut app = app_with_image(); let id = open(&mut app, "image.adjustments.curves").unwrap(); arm(&mut app, id, TonePicker::Black); let before = channel_points(&mut app, "red"); - pointer(&mut app, crate::canvas::ToolEvent::Move { x: 48.0, y: 8.0, pressure: 1.0 }, egui::Modifiers::NONE); + let pointer = |app: &mut PhotocraftApp, kind: &str, x: f64, y: f64| { + crate::canvas::testing::control(app, "ui.pointer", json!({"events": [{"kind": kind, "x": x, "y": y}]})); + }; + crate::canvas::testing::clear_of_dialogs(&mut app, [8.0, 8.0]); + pointer(&mut app, "move", 12.0, 8.0); assert_eq!(channel_points(&mut app, "red"), before, "pointer move does not sample"); - pointer(&mut app, crate::canvas::ToolEvent::Down { x: 8.0, y: 8.0, pressure: 1.0 }, egui::Modifiers::NONE); + pointer(&mut app, "down", 8.0, 8.0); let red = channel_points(&mut app, "red"); assert!((red[0][0] - 176.0).abs() < 0.6 && red[0][1] == 0.0, "{red:?}"); assert_ne!(red, before, "pointer down samples"); - pointer(&mut app, crate::canvas::ToolEvent::Up { x: 48.0, y: 8.0 }, egui::Modifiers::NONE); - assert_eq!(channel_points(&mut app, "red"), red, "pointer up does not sample again"); + // Back to the curve before the press: a release that sampled would set it again. + set_params(&mut app, id, &json!({"red": before})); + pointer(&mut app, "up", 8.0, 8.0); + assert_eq!(channel_points(&mut app, "red"), before, "pointer up does not sample again"); assert!(picker_armed(&app)); } @@ -703,7 +713,8 @@ fn rabbit_levels_live_mask_preview_matches_commit() { set_field(&mut app, id, "gamma", json!(2)); let before = app.session.active().unwrap().doc.clone(); let idx = app.session.active_index().unwrap(); - let (preview, _) = crate::adjust_preview::display_doc(&mut app, idx).expect("the dialog previews on the canvas"); + crate::canvas::ensure_filter_preview(&mut app, idx, &ctx).expect("the dialog previews on the canvas"); + let preview = app.filter_preview.as_ref().and_then(|p| p.result.clone()).expect("the CPU proxy preview"); assert!(std::sync::Arc::ptr_eq(&before, &app.session.active().unwrap().doc)); ok(&mut app, &ctx, id).unwrap(); let after = &app.session.active().unwrap().doc; diff --git a/crates/ui-egui/src/dialogs/adjust_editors/values.rs b/crates/ui-egui/src/dialogs/adjust_editors/values.rs index 6efab6b80ea..d2ad98ecc37 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/values.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/values.rs @@ -514,9 +514,10 @@ fn write_params(value: &AdjustValue, cx: &ValueCx) -> Value { } AdjustValue::GradientMap { value } => write_gradient_map(&mut out, value), AdjustValue::SelectiveColor { value } => { - // The rows carry every range: the single-colour form and `relative` the dialog was opened with would be - // read after them (and over them) by the engine. - for key in ["colors", "cyan", "magenta", "yellow", "black", "relative"] { + // The rows carry every range: the single-colour values and `relative` the dialog was opened with would be + // read after them (and over them) by the engine. `colors`, the chosen row, stays: without those values it + // changes nothing. + for key in ["cyan", "magenta", "yellow", "black", "relative"] { out.remove(key); } out.insert("method".into(), json!(if value.method == SelectiveMethod::Absolute { "absolute" } else { "relative" })); diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index 66caae676c8..5015b19e864 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -345,10 +345,9 @@ pub fn open(app: &mut PhotocraftApp) -> Result { /// `select.refineEdge` works on the active layer of the active document, so its edits must not run there. pub(crate) fn stale(app: &PhotocraftApp) -> Option<&'static str> { let (_, document, opened_on, _) = app.select_mask_target.as_ref()?; - let st = app.session.active()?; - if st.doc.id != *document { + let Some(st) = app.session.active().filter(|st| st.doc.id == *document) else { return Some(tl!("Select and Mask was closed: its document is no longer the active one")); - } + }; let layer = st.active_layer.filter(|id| st.doc.layer(*id).is_some()); (layer != Some(*opened_on)).then_some(tl!("Select and Mask was closed: another layer was selected")) } diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index 5f0e15500df..f551065a089 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -39,19 +39,11 @@ fn fields(app: &mut PhotocraftApp) -> Value { ui(app, json!({})) } -/// Runs `n` frames of the dialog host with the app's per-frame checks, as the app does: a request starts its preview -/// job and a stale workspace closes in a frame. +/// Runs `n` frames of the app (its key route, document area and hosted dialogs, with the app's per-frame checks): the +/// workspace asks for its preview in its pass, and the framework's job runtime runs only inside the app's frame. fn frames(app: &mut PhotocraftApp, n: usize) { - let ctx = app.ctx().clone(); for _ in 0..n { - let mut output = ctx.run_ui( - egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0))), ..Default::default() }, - |ui| { - crate::distort_ui::drop_foreign(app, ui.ctx()); - crate::dialogs::run(app, ui); - }, - ); - output.textures_delta.clear(); + crate::canvas::testing::frame(app); } } @@ -166,12 +158,16 @@ fn remember_settings() { frames(&mut app, 2); app.session.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap(); open(&mut app).unwrap(); + // The workspace reads the stored settings in its first pass. + frames(&mut app, 1); let s = workspace(&app).settings(); assert_eq!((s.refine.radius, s.view, s.overlay_color), (7.0, MaskViewMode::Overlay, [0, 0, 255])); ui(&mut app, json!({"remember": false})); ui(&mut app, json!({"commit": true})); + frames(&mut app, 2); app.session.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap(); open(&mut app).unwrap(); + frames(&mut app, 1); let s = workspace(&app).settings(); assert_eq!((s.refine.radius, s.view), (0.0, MaskViewMode::OnionSkin)); }