Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Integration: #2012 fit the hover preview to the drawn size; keep the zoomed whole frame canvas-sized

aiongg346a5be628e0
diff --git a/crates/ui-egui/src/headless.rs b/crates/ui-egui/src/headless.rs
index ea75f22d5..a29b85839 100644
--- a/crates/ui-egui/src/headless.rs
+++ b/crates/ui-egui/src/headless.rs
@@ -4387,6 +4387,43 @@ mod tests {
h.settle(SETTLE);
}
+ /// A hover preview gets the loupe's display fit: it is the size the photo is drawn at, as the
+ /// loupe render is, not a preview-level render the GPU shrinks.
+ #[test]
+ fn a_hover_preview_is_fitted_to_the_drawn_size() {
+ use crate::render::Slot;
+ let mut h = demo([1400.0, 900.0]);
+ let t = Duration::from_secs(10);
+ h.request("ui.set", json!({"view": "detail"}), t);
+ h.request("engine.execute", json!({"command": "panel.profiles"}), t);
+ h.settle(SETTLE);
+ h.step_until(SETTLE, |h| !h.app.renderer.is_pending(Slot::Main));
+ let r = h.request("ui.hoverWidget", json!({"id": "profileCell:lc.vivid"}), t);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step_until(SETTLE, |h| h.app.loupe_shown.map(|l| l.1) == Some("hover"));
+ let size = |s: Slot| h.app.renderer.textures.get(&s).map(|t| t.size);
+ let (main, hover) = (size(Slot::Main).expect("loupe render"), size(Slot::Hover).expect("hover render"));
+ assert!(main[0].max(main[1]) < lightcraft_engine::SourceLevel::Preview.max_edge(), "the loupe render is fitted: {main:?}");
+ assert!(hover[0].abs_diff(main[0]) <= 1 && hover[1].abs_diff(main[1]) <= 1, "hover {hover:?} vs loupe {main:?}");
+ }
+
+ /// Zoomed in under a window render, the hidden whole-frame render stays canvas-sized instead of
+ /// rising to the preview level.
+ #[test]
+ fn a_zoomed_view_keeps_its_whole_frame_render_canvas_sized() {
+ use crate::render::Slot;
+ let mut h = demo([1000.0, 700.0]);
+ let t = Duration::from_secs(10);
+ h.request("ui.set", json!({"view": "detail", "right": "none"}), t);
+ h.settle(SETTLE);
+ h.request("ui.clickWidget", json!({"id": "canvas:image", "fx": 0.5, "fy": 0.5}), t);
+ h.settle(SETTLE);
+ assert_eq!(h.app.ui.zoom, crate::state::Zoom::Percent(100.0));
+ h.step_until(SETTLE, |h| !h.app.renderer.is_pending(Slot::Main));
+ let main = h.app.renderer.textures.get(&Slot::Main).expect("whole-frame render").size;
+ assert!(main[0].max(main[1]) < lightcraft_engine::SourceLevel::Preview.max_edge(), "{main:?}");
+ }
+
#[test]
fn trackpad_navigation_keeps_the_image_cursor_between_events() {
let mut h = demo([1000.0, 700.0]);
diff --git a/crates/ui-egui/src/panels/detail.rs b/crates/ui-egui/src/panels/detail.rs
index 17b38b320..065868759 100644
--- a/crates/ui-egui/src/panels/detail.rs
+++ b/crates/ui-egui/src/panels/detail.rs
@@ -581,7 +581,8 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
// At rest the whole frame renders at no less than the preview source level: the source is then
// copied 1:1 (no resample in the pipeline, whose prefilter and bilinear pass soften detail near
// the output's limit) and shrunk once, by the Lanczos display fit below.
- let want = if interacting {
+ // (zoomed in under a window render, the whole frame is hidden: it stays canvas-sized)
+ let want = if interacting || plan.window_edge.is_some() {
plan.main_edge
} else {
// (a user's explicit Preview size below the preview level still caps it)
@@ -624,6 +625,8 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
// once it is ready (nothing is committed)
let hover_key = match app.hover_preview.clone() {
Some(h) if !interacting => app.session.preview_job(id, sw.max(8), sh.max(8), !crop_tool, &h.settings).map(|job| {
+ // (the same display fit as the After view, drawn texel for texel like it)
+ let job = job.with_display_fit((target_rect.width() * ppp).round() as usize, (target_rect.height() * ppp).round() as usize);
let key = job.key;
app.renderer.request(Slot::Hover, job, 105);
(key, h.label)