Use one file-backed photo for slideshow crop geometry coverage

This commit is contained in:
skylartaylor committed 2026-11-30 22:21:32 +01:00
1 parent be3982c005
commit ccdb1084e1
2 files changed
+14 -5

No files matched your search

+10 -4
View File
@@ -17,6 +17,7 @@ use crate::{LightcraftApp, Services};
pub(crate) struct SyntheticLibrary {
dir: PathBuf,
photos: Vec<PathBuf>,
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);
+4 -1
View File
@@ -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];