FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
monitors: gentler, reversible wheel zoom
ReReddo2781df8b26b2
diff --git a/crates/ui-egui/src/panels/monitor_view.rs b/crates/ui-egui/src/panels/monitor_view.rsindex 501ead7a5..45809bfbd 100644--- a/crates/ui-egui/src/panels/monitor_view.rs+++ b/crates/ui-egui/src/panels/monitor_view.rs@@ -363,9 +363,10 @@ pub fn zoom_pan_input(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, area:if ui.rect_contains_pointer(area)&& let Some(p) = ctx.pointer_hover_pos(){- // as fast as the Timeline's own wheel zoom+ // about 10% per wheel notch (40 points), exponential in the wheel travel so a notch out+ // undoes a notch in exactlylet wheel = crate::panels::timeline::wheel_input(&ctx);- let f = if (wheel.pinch - 1.0).abs() > 1e-4 { wheel.pinch } else { (1.0 + wheel.delta.y * 0.01).clamp(0.5, 2.0) };+ let f = if (wheel.pinch - 1.0).abs() > 1e-4 { wheel.pinch } else { (wheel.delta.y * 1.1_f32.ln() / 40.0).exp().clamp(0.5, 2.0) };if (f - 1.0).abs() > 1e-4 && pic.width() > 0.0 && fw > 0.0 {let cur = pic.width() * ppp / fw;let z = (cur * f).clamp(ZOOMS[0].1, ZOOMS[ZOOMS.len() - 1].1);diff --git a/crates/ui-egui/tests/view_ui.rs b/crates/ui-egui/tests/view_ui.rsindex 92b34a1fc..30ce1c82c 100644--- a/crates/ui-egui/tests/view_ui.rs+++ b/crates/ui-egui/tests/view_ui.rs@@ -197,13 +197,21 @@ fn wheel_zooms_about_the_pointer_and_the_middle_button_pans() {let area = d.rect("program.picture");let centre = (area[0] + area[2] / 2.0, area[1] + area[3] / 2.0);let at = (area[0] + area[2] * 0.25, area[1] + area[3] * 0.4);- // 50 points up: 1.5 times; the point under the pointer stays under it- d.ok("ui.scroll", json!({"x": at.0, "y": at.1, "dx": 0.0, "dy": 50.0}));+ // one wheel notch (40 points) up: 10% larger; the point under the pointer stays under it+ d.ok("ui.scroll", json!({"x": at.0, "y": at.1, "dx": 0.0, "dy": 40.0}));d.frames(2);let p = d.program();- assert!((num(&p["zoom"]) - 1.5).abs() < 1e-4, "{p}");- let want = ((centre.0 - at.0) * 0.5, (centre.1 - at.1) * 0.5);+ assert!((num(&p["zoom"]) - 1.1).abs() < 1e-4, "{p}");+ let want = ((centre.0 - at.0) * 0.1, (centre.1 - at.1) * 0.1);assert!((num(&p["pan"][0]) - want.0).abs() < 1.0 && (num(&p["pan"][1]) - want.1).abs() < 1.0, "pan {} for {want:?}", p["pan"]);+ // a notch down, then up again, comes back to the same zoom+ d.ok("ui.scroll", json!({"x": at.0, "y": at.1, "dx": 0.0, "dy": -40.0}));+ d.frames(2);+ assert!((num(&d.program()["zoom"]) - 1.0).abs() < 1e-4, "{}", d.program());+ d.ok("ui.scroll", json!({"x": at.0, "y": at.1, "dx": 0.0, "dy": 40.0}));+ d.frames(2);+ let p = d.program();+ assert!((num(&p["zoom"]) - 1.1).abs() < 1e-4, "{p}");// the middle button drags the picture, whatever the toollet (zoom, pan) = (num(&p["zoom"]), [num(&p["pan"][0]), num(&p["pan"][1])]);@@ -225,7 +233,7 @@ fn wheel_zooms_about_the_pointer_and_the_middle_button_pans() {// zooming out stops at the menu's smallest level; Fit resets zoom and panfor _ in 0..12 {- d.ok("ui.scroll", json!({"x": centre.0, "y": centre.1, "dx": 0.0, "dy": -50.0}));+ d.ok("ui.scroll", json!({"x": centre.0, "y": centre.1, "dx": 0.0, "dy": -200.0}));}d.frames(2);assert!((num(&d.program()["zoom"]) - 0.1).abs() < 1e-6, "stops at 10%");