Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #888 from vangel76/fix-882-viewer-pixel-exact

Brandon Thomas617412b555a3
diff --cc crates/ui-egui/src/menus.rs
index 00fdc3892,35e2512db..951f827d0
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@@ -776,16 -737,6 +776,7 @@@ fn toggle(slot: &mut bool, p: &Value) -
json!(*slot)
}
- /// The next View ▸ Zoom In / Zoom Out magnification (points per pixel) after `cur`.
- fn zoom_step(cur: f32, zoom_in: bool) -> f32 {
- const STEPS: [f32; 16] = [0.015, 0.03, 0.0625, 0.125, 0.25, 0.333, 0.5, 0.66, 1.0, 1.5, 2.0, 3.0, 4.0, 8.0, 16.0, 32.0];
- if zoom_in {
- STEPS.iter().copied().find(|s| *s > cur + 1e-3).unwrap_or(32.0)
- } else {
- STEPS.iter().rev().copied().find(|s| *s < cur - 1e-3).unwrap_or(0.015)
- }
- }
+
/// Perform a frontend command (from `Event::Frontend`).
pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Value) -> Result<Value, String> {
let now = ctx.input(|i| i.time);
@@@ -910,17 -859,10 +901,19 @@@
}
r
}
+ // Zoom In / Zoom Out act on the focused viewer: the Layer panel when it has focus, else
+ // the Composition viewer.
+ "view.zoomIn" | "view.zoomOut" if app.ui.focused == PanelKind::Layer => {
+ let cur = app.ui.layer_zoom.unwrap_or_else(|| crate::panels::layer_panel::last_fit(ctx));
- let next = zoom_step(cur, id == "view.zoomIn");
++ // The Layer panel zooms in points (pixels-per-point 1).
++ let next = zoom_step(cur, 1.0, id == "view.zoomIn");
+ app.ui.layer_zoom = Some(next);
+ json!({"zoom": next, "panel": "layer"})
+ }
"view.zoomIn" | "view.zoomOut" => {
+ let ppp = ctx.pixels_per_point();
let cur = v.zoom.unwrap_or_else(|| crate::panels::viewer::last_fit(ctx));
- let next = zoom_step(cur, id == "view.zoomIn");
+ let next = zoom_step(cur, ppp, id == "view.zoomIn");
v.zoom = Some(next);
json!({"zoom": next})
}