From ccdb1084e14994012d2ef2255b7739c53bb70a64 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 30 Nov 2026 22:21:32 +0100 Subject: [PATCH] Use one file-backed photo for slideshow crop geometry coverage --- crates/ui-egui/src/tests/fixtures.rs | 14 ++++++++++---- crates/ui-egui/src/tests/slideshow.rs | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/tests/fixtures.rs b/crates/ui-egui/src/tests/fixtures.rs index 0b07b543db..6a3cb06b9d 100644 --- a/crates/ui-egui/src/tests/fixtures.rs +++ b/crates/ui-egui/src/tests/fixtures.rs @@ -17,6 +17,7 @@ use crate::{LightcraftApp, Services}; pub(crate) struct SyntheticLibrary { dir: PathBuf, photos: Vec, + size: [usize; 2], } impl SyntheticLibrary { @@ -27,11 +28,16 @@ impl SyntheticLibrary { /// A fresh folder for `tag`, with `n` distinct 64×48 gradient PNGs (`a.png`, `b.png`, …). pub(crate) fn with_photos(tag: &str, n: usize) -> SyntheticLibrary { + Self::with_dimensions(tag, n, [64, 48]) + } + + /// A file-backed gradient large enough for tests that exercise very narrow crops. + pub(crate) fn with_dimensions(tag: &str, n: usize, size: [usize; 2]) -> SyntheticLibrary { assert!((1..=26).contains(&n), "fixture photo names use a through z"); let dir = std::env::temp_dir().join(format!("lc-ui-fixture-{tag}-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); - let (w, h) = (64usize, 48usize); + let [w, h] = size; let mut photos = Vec::new(); for i in 0..n { let name = format!("{}.png", char::from(b'a' + i as u8)); @@ -47,7 +53,7 @@ impl SyntheticLibrary { std::fs::write(&path, png).unwrap(); photos.push(path); } - SyntheticLibrary { dir, photos } + SyntheticLibrary { dir, photos, size } } /// A session whose library holds only the fixture photos, the first active and selected, with @@ -64,8 +70,8 @@ impl SyntheticLibrary { Source::File { path: path.to_string_lossy().into_owned() }, path.file_name().map_or("photo.png", |n| n.to_str().unwrap_or("photo.png")), "PNG", - 64, - 48, + self.size[0] as u32, + self.size[1] as u32, &captured, ); photo.captured = Some(captured); diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index 6d90cf6848..8c4a5ca0fb 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -456,7 +456,10 @@ fn pan_and_zoom_draws_every_frame_only_once_its_slide_is_ready() { /// beside it stays where it is and the photo still shows inside it. #[test] fn pan_and_zoom_moves_only_the_visible_photo_at_any_aspect() { - let mut h = grid(); + // Keep even the thinnest crop above a source pixel, without rendering a demo catalog. + let library = SyntheticLibrary::with_dimensions("slideshow-crop-aspects", 1, [1500, 1000]); + let mut h = Headless::new(library.app(), [1000.0, 700.0], 1.0); + h.step(); run(&mut h, "slideshow.layout", json!({"margins": 0.1, "backdropColor": "#ff0000"})); run(&mut h, "slideshow.playback", json!({"panAndZoom": true, "panAndZoomAmount": 1.0})); let id = h.app.session.visible_cloned()[0];