diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index b3e6eecb687..131aec626e8 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -696,7 +696,14 @@ fn handle_dialog_canvas_input(app: &mut PhotocraftApp, input: DialogCanvasInput< .flatten() .map(|m| crate::workspace_ui::sticky_mods(app, m)) .filter(|m| m.command); - let dialog_hand = app.ui.tool == Tool::Hand && !picking && !range_picking && !refine_brushing && !pinning && !shadow_drag && curve_point_press.is_none(); + let dialog_hand = app.ui.tool == Tool::Hand + && !picking + && !range_picking + && !refine_brushing + && !pinning + && !shadow_drag + && !gradient_drag + && curve_point_press.is_none(); // ⌘Space / ⌥Space zoom under the dialog as they do without one, before Space pans (#6460). // With the Hand tool, ⌘ alone is Zoom In (#6434); under Curves that press is the dialog's // point (#7325), not a zoom. diff --git a/crates/ui-egui/src/dialogs/layer_style.rs b/crates/ui-egui/src/dialogs/layer_style.rs index 1ea91511146..4f329901762 100644 --- a/crates/ui-egui/src/dialogs/layer_style.rs +++ b/crates/ui-egui/src/dialogs/layer_style.rs @@ -551,19 +551,25 @@ pub fn drag_gradient(f: &mut Map, start: bool, total: [f64; 2], b const KEY: &str = "__gradientDrag"; let Some(id) = f.get("selected").and_then(Value::as_str).map(str::to_string).filter(|_| drags_gradient(f)) else { return }; let Some(p) = entry(f, &id).and_then(|e| e.get("params")) else { return }; + // The offset as stored (None: centred, never set). + let stored = + p.get("offset").and_then(Value::as_array).map(|a| [a.first().and_then(Value::as_f64).unwrap_or(0.0), a.get(1).and_then(Value::as_f64).unwrap_or(0.0)]); if start || f.get(KEY).is_none() { - let at = p - .get("offset") - .and_then(Value::as_array) - .map_or([0.0, 0.0], |a| [a.first().and_then(Value::as_f64).unwrap_or(0.0), a.get(1).and_then(Value::as_f64).unwrap_or(0.0)]); - f.insert(KEY.into(), json!(at)); + f.insert(KEY.into(), json!(stored.unwrap_or([0.0, 0.0]))); } let Some([x0, y0]) = f.get(KEY).and_then(Value::as_array).and_then(|a| Some([a.first()?.as_f64()?, a.get(1)?.as_f64()?])) else { return }; let [w, h] = [bounds[0].max(1.0), bounds[1].max(1.0)]; - let (x, y) = (x0 + total[0] / w, y0 + total[1] / h); + // Kept within what the renderer takes (±4 of the layer's size), so the next drag starts from + // where the gradient shows. + let (x, y) = ((x0 + total[0] / w).clamp(-4.0, 4.0), (y0 + total[1] / h).clamp(-4.0, 4.0)); if !(x.is_finite() && y.is_finite()) { return; } + // A press that has not moved the gradient (or a drag back to where it began, with nothing + // written since) leaves the stored offset as it is, to its full precision. + if x == x0 && y == y0 && stored == Some([x0, y0]) { + return; + } set_param(f, &id, "offset", json!([(x * 1000.0).round() / 1000.0, (y * 1000.0).round() / 1000.0])); } diff --git a/crates/ui-egui/src/dialogs/layer_style/tests.rs b/crates/ui-egui/src/dialogs/layer_style/tests.rs index 2c777d9ef6f..d6b4c5907aa 100644 --- a/crates/ui-egui/src/dialogs/layer_style/tests.rs +++ b/crates/ui-egui/src/dialogs/layer_style/tests.rs @@ -62,6 +62,19 @@ fn dragging_on_the_image_moves_the_selected_gradient_overlay() { drag_gradient(&mut f, true, [0.0, 0.0], [200.0, 100.0]); drag_gradient(&mut f, false, [20.0, 0.0], [200.0, 100.0]); assert_eq!(offset(&f, "fx1"), Some(json!([-0.4, 0.0]))); + // A press that moves nothing keeps a precise offset as it is; a drag that comes back to where + // it began still writes, since the gradient moved in between. The offset stays within ±4. + f.insert("selected".into(), json!("fx2")); + set_param(&mut f, "fx2", "offset", json!([0.123456, 0.1])); + drag_gradient(&mut f, true, [0.0, 0.0], [200.0, 100.0]); + drag_gradient(&mut f, false, [0.0, 0.0], [200.0, 100.0]); + assert_eq!(offset(&f, "fx2"), Some(json!([0.123456, 0.1])), "nothing moved: nothing rounded"); + drag_gradient(&mut f, false, [20.0, 0.0], [200.0, 100.0]); + assert_eq!(offset(&f, "fx2"), Some(json!([0.223, 0.1]))); + drag_gradient(&mut f, false, [0.0, 0.0], [200.0, 100.0]); + assert_eq!(offset(&f, "fx2"), Some(json!([0.123, 0.1])), "back at the start: the start is written"); + drag_gradient(&mut f, false, [100_000.0, -100_000.0], [200.0, 100.0]); + assert_eq!(offset(&f, "fx2"), Some(json!([4.0, -4.0])), "clamped as the renderer clamps"); // Not on a gradient page: nothing moves. f.insert("selected".into(), json!(BLENDING)); assert!(!drags_gradient(&f));