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

#882: pixel-exact Composition viewer at 100 % and above

# Conflicts:
#	crates/ui-egui/src/menus.rs
This commit is contained in:
Brandon Thomas
2026-10-12 04:22:01 -04:00
5 changed files with 107 additions and 19 deletions
+32 -11
View File
@@ -776,15 +776,6 @@ fn toggle(slot: &mut bool, p: &Value) -> 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> {
@@ -914,13 +905,15 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
// 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})
}
@@ -2003,10 +1996,38 @@ fn menu_entry(app: &EffectcraftApp, ui: &mut egui::Ui, e: &MenuEntry) -> egui::R
ui.add_enabled(enabled, b)
}
/// View ▸ Zoom In / Zoom Out: the next standard magnification (as a share of screen pixels, so
/// 100 % is one comp pixel per screen pixel at any display scaling) above or below `cur`, which is
/// in points per comp pixel like the result (#882).
fn zoom_step(cur: f32, ppp: 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];
let ppp = if ppp.is_finite() && ppp > 0.0 { ppp } else { 1.0 };
let shown = cur * ppp;
let next = if zoom_in {
STEPS.iter().copied().find(|s| *s > shown + 1e-3).unwrap_or(32.0)
} else {
STEPS.iter().rev().copied().find(|s| *s < shown - 1e-3).unwrap_or(0.015)
};
next / ppp
}
#[cfg(test)]
mod tests {
use super::*;
/// #882: at 125 % / 150 % display scaling Zoom In reaches 100 % (one comp pixel per screen
/// pixel), not 100 % in points (125 % / 150 % on screen).
#[test]
fn zoom_steps_land_on_whole_screen_magnifications() {
for ppp in [1.0f32, 1.25, 1.5, 2.0] {
let at_100 = zoom_step(0.7 / ppp, ppp, true);
assert!((at_100 * ppp - 1.0).abs() < 1e-6, "ppp {ppp}: {}", at_100 * ppp);
assert!((zoom_step(at_100, ppp, true) * ppp - 1.5).abs() < 1e-6);
assert!((zoom_step(at_100, ppp, false) * ppp - 0.66).abs() < 1e-6);
}
assert!(zoom_step(1.0, 0.0, true).is_finite());
}
#[test]
fn shortcut_passes_share_frame_start_modifiers() {
let ctx = egui::Context::default();