mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Move tool: no 1000 px cap on the screen-pixel nudge (CodeRabbit review on crates/ui-egui/src/tools/move_mods.rs:210)
A large document zooms out until its shorter side is 2 px on screen (zoom_levels::min), below 0.1 %, so one screen pixel can be more than 1000 document pixels (6000 at a 12,000 x 12,000 px document's lowest zoom). The step is now floor(1 / zoom), at least 1, with no upper cap; the zoom's own floor bounds it at half the shorter side. The rounding margin is now relative: an f32 zoom rung is a hair off its value (0.1 % is 1 / 999.99995), so the old absolute 1e-6 gave 999 at 0.1 % and 499 at 0.2 %. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
321c25ce47
commit
6d9ddc66e1
2 files changed
+21
-3
No files matched your search
@@ -200,14 +200,16 @@ pub fn abandon(app: &mut PhotocraftApp) {
|
||||
|
||||
/// The document pixels one plain arrow press moves layers by with the Move tool: one screen
|
||||
/// pixel, as in Photoshop (#9511). Zoomed out that is several document pixels (2 at 50 %, 4 at
|
||||
/// 25 %; 1 at 66.7 %: whole pixels only), zoomed in still one. ⇧'s 10 px don't scale. Free
|
||||
/// Transform keeps 1 px.
|
||||
/// 25 %; 1 at 66.7 %: whole pixels only), zoomed in still one. No cap: the zoom bottoms out
|
||||
/// with the document's shorter side 2 px on screen (`zoom_levels::min`), so a step is at most
|
||||
/// half that side. ⇧'s 10 px don't scale. Free Transform keeps 1 px.
|
||||
fn screen_pixel_step(app: &PhotocraftApp) -> f64 {
|
||||
let zoom = f64::from(app.current_zoom());
|
||||
if app.ui.transform.is_some() || !zoom.is_finite() || zoom <= 0.0 {
|
||||
return 1.0;
|
||||
}
|
||||
(1.0 / zoom + 1e-6).floor().clamp(1.0, 1000.0)
|
||||
// A relative margin: the f32 zoom is a hair off its rung (0.1 % is 1 / 999.99995).
|
||||
(1.0 / zoom * (1.0 + 1e-6)).floor().max(1.0)
|
||||
}
|
||||
|
||||
/// Arrow keys with the Move tool (or while Free Transform is active): nudge one screen pixel
|
||||
|
||||
@@ -539,3 +539,19 @@ fn a_nudge_is_one_screen_pixel() {
|
||||
assert_eq!(left_edge(&app, id), 8 + step - 10, "⇧← at {zoom}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #9511: below 0.1 % (a large document zooms out until its shorter side is 2 px) the nudge is
|
||||
/// still one screen pixel: 6000 document pixels at a 12,000 × 12,000 px document's lowest zoom,
|
||||
/// not capped at 1000. The ladder's f32 rungs (0.1 %, 0.2 %) still give whole steps (1000,
|
||||
/// not 999).
|
||||
#[test]
|
||||
fn a_nudge_is_one_screen_pixel_below_a_tenth_of_a_percent() {
|
||||
let lowest = crate::zoom_levels::min([12_000, 12_000]);
|
||||
for (zoom, step) in [(0.002, 500), (0.001, 1000), (0.0005, 2000), (lowest, 6000)] {
|
||||
let mut app = app_with_layer();
|
||||
let id = app.session.active().unwrap().active_layer.unwrap();
|
||||
app.ui.views[0].zoom = zoom;
|
||||
assert!(press(&mut app, egui::Key::ArrowRight, egui::Modifiers::NONE));
|
||||
assert_eq!(left_edge(&app, id), 8 + step, "→ at {zoom}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user