diff --git a/crates/ui-egui/src/print_view.rs b/crates/ui-egui/src/print_view.rs index 7c1ab85fb1..245c126ae9 100644 --- a/crates/ui-egui/src/print_view.rs +++ b/crates/ui-egui/src/print_view.rs @@ -729,8 +729,13 @@ fn paint_cell( } let clip = painter.with_clip_rect(avail.intersect(painter.clip_rect())); let tex = photo.and_then(|id| { - let px = (shown.width().max(shown.height()) * 2.0).clamp(64.0, 1024.0) as usize; - crate::panels::grid::request_thumb(app, id, px, 10); + // Use the library's thumbnail when there is one. A thumbnail is kept at one size, so asking + // for another size here every frame made the preview and the grid behind the dialog + // re-render each other's thumbnail for as long as the dialog stayed open. + if app.renderer.thumb(id).is_none() { + let px = (shown.width().max(shown.height()) * 2.0).clamp(64.0, 1024.0) as usize; + crate::panels::grid::request_thumb(app, id, px, 10); + } app.renderer.thumb(id).map(|tex| tex.tex.id()) }); match tex { diff --git a/crates/ui-egui/src/tests_print.rs b/crates/ui-egui/src/tests_print.rs index 6dbea7a40e..a75191d038 100644 --- a/crates/ui-egui/src/tests_print.rs +++ b/crates/ui-egui/src/tests_print.rs @@ -298,3 +298,26 @@ fn the_print_dialog_fits_the_window_with_its_buttons_on_screen() { } } } + +#[test] +fn the_print_preview_does_not_rebuild_thumbnails_every_frame() { + let mut h = demo(Services { png: None, ..Default::default() }); + let before = h.app.renderer.thumb_jobs_built; + cmd(&mut h, "dialog.print", json!({})); + for style in ["contactSheet", "picturePackage", "singleImage"] { + cmd(&mut h, "print.set", json!({"layout": {"style": style}})); + if style == "picturePackage" { + // the same photo in cells of different sizes + cmd(&mut h, "print.cell.add", json!({"width": 2.0, "height": 2.5})); + cmd(&mut h, "print.cell.add", json!({"width": 5.0, "height": 7.0})); + } + assert!(h.settle(Duration::from_secs(5)), "{style}: the dialog settles"); + let built = h.app.renderer.thumb_jobs_built; + for _ in 0..60 { + h.step(); + } + assert_eq!(h.app.renderer.thumb_jobs_built, built, "{style}: no thumbnail is rebuilt while nothing changes"); + assert_eq!(h.app.renderer.in_flight(), 0, "{style}"); + } + assert!(h.app.renderer.thumb_jobs_built - before < 50, "{} jobs", h.app.renderer.thumb_jobs_built - before); +}