Repository navigation
LR-VIEW-PHOTOGRID: a thumbnail still loading shows a quiet cue, unlike an unreadable one #3345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1f15537
0c2ac7a
05fecef
5886637
0a4a1b5
568d5c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -854,14 +854,44 @@ fn paint_cell_thumbnail(app: &mut LightcraftApp, p: &egui::Painter, t: &Tokens, | |
| p.rect_filled(ph, 0.0, t.skeleton); | ||
| // not drawn yet (or unreadable): the selection is still visible | ||
| selection_ring(p, t, ph, state); | ||
| if app.renderer.failure(Slot::Thumb(id)).is_some() { | ||
| if app.renderer.thumb_failure(id).is_some() { | ||
| // unreadable / missing file | ||
| p.text(ph.center(), Align2::CENTER_CENTER, "!", t.semibold(18.0), t.text); | ||
| } else if thumb_may_arrive(app, id) { | ||
| paint_loading_cue(p, t, img_rect, ph, "badge:loading:", id.0); | ||
| } | ||
| ph | ||
| } | ||
| } | ||
|
|
||
| /// Whether a thumbnail of `id` can still arrive, so its placeholder says so with the loading cue: no | ||
| /// thumbnail job is ever asked for a video (`Session::thumb_job`: the image decoders can't read one), and | ||
| /// its placeholder stays plain. | ||
| pub(crate) fn thumb_may_arrive(app: &LightcraftApp, id: PhotoId) -> bool { | ||
| !app.session.catalog.photo(id).is_some_and(|p| p.is_video()) | ||
| } | ||
|
|
||
| /// A quiet cue on a thumbnail's placeholder while the picture is still on its way (an unreadable one | ||
| /// says "!" instead): three small dots in the middle, in the icon color (3:1 on every theme's placeholder). It stands still, so | ||
| /// Reduce motion has nothing to stop. It is left off tiles too small to hold it: judged by the | ||
| /// `tile` (the placeholder's cell, smaller than 32 pt either way) and by the `rect` (the | ||
| /// placeholder, which must have room for the dots). Registered as `{prefix}{id}` (the grid's | ||
| /// `badge:loading:{id}`, the filmstrip's `film:badge:loading:{id}`). | ||
| pub(crate) fn paint_loading_cue(p: &egui::Painter, t: &Tokens, tile: Rect, rect: Rect, prefix: &str, id: u64) { | ||
| const RADIUS: f32 = 1.75; | ||
| const GAP: f32 = 7.0; | ||
| const CUE_W: f32 = 2.0 * (GAP + RADIUS); | ||
| const CUE_H: f32 = 2.0 * RADIUS; | ||
| if tile.width().min(tile.height()) < 32.0 || rect.width() < CUE_W || rect.height() < CUE_H { | ||
| return; | ||
| } | ||
| let middle = rect.center(); | ||
| for dx in [-GAP, 0.0, GAP] { | ||
| p.circle_filled(middle + vec2(dx, 0.0), RADIUS, t.icon); | ||
| } | ||
| crate::widgets::register_geometry(p.ctx(), format!("{prefix}{id}"), Rect::from_center_size(middle, vec2(2.0 * (GAP + RADIUS), 2.0 * RADIUS))); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2. Expose thumbnail loading state in the tile accessibility node. The new dots are painted geometry only. The Grid and filmstrip accessibility nodes do not distinguish a pending tile from an ordinary one, and Grid does not expose the failed state either. Add translated status from the same state used for painting. The held and failed fixture can check the resulting tile semantics. |
||
| } | ||
|
|
||
| fn paint_cell_caption(app: &LightcraftApp, p: &egui::Painter, t: &Tokens, photo: &lightcraft_catalog::Photo, r: Rect, square: bool) { | ||
| if square && app.ui.show_filenames { | ||
| let m = &photo.meta; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| //! A grid cell whose thumbnail is still on its way says so, quietly, and differs from one whose file | ||
| //! can't be read (which says "!"): until the failure is known the two were the same plain skeleton. | ||
| //! The cue is still (nothing to stop for a Reduce motion setting) and drawn from the theme's own colors. | ||
|
|
||
| use std::cell::Cell; | ||
| use std::rc::Rc; | ||
| use std::time::Duration; | ||
|
|
||
| use lightcraft_catalog::{Op, Photo, PhotoId, Source}; | ||
| use lightcraft_engine::Session; | ||
|
|
||
| use crate::headless::{Headless, RenderGate}; | ||
| use crate::render::Slot; | ||
| use crate::state::ViewMode; | ||
| use crate::{LightcraftApp, Services}; | ||
|
|
||
| const SETTLE: Duration = Duration::from_secs(60); | ||
|
|
||
| /// Twelve photos whose files are not there, with every thumbnail render held until the returned gate | ||
| /// opens, and then failed (as an unreadable file's would): the cells are loading, then unreadable, at | ||
| /// the test's say. | ||
| fn app_with_held_thumbnails(view: ViewMode) -> (Headless, Rc<Cell<bool>>) { | ||
| app_with_held_files(view, "jpg", "JPEG") | ||
| } | ||
|
|
||
| /// [`app_with_held_thumbnails`] for files of another kind (`extension` and catalog `format`). | ||
| fn app_with_held_files(view: ViewMode, extension: &str, format: &str) -> (Headless, Rc<Cell<bool>>) { | ||
| let mut s = Session::new(); | ||
| for i in 0..12u64 { | ||
| let name = format!("IMG_{i:03}.{extension}"); | ||
| let path = format!("/lightcraft-loading-cell-test/{name}"); | ||
| let p = Photo::new(PhotoId(i + 1), Source::File { path }, &name, format, 6000, 4000, "2026-01-01T00:00:00"); | ||
| s.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap(); | ||
| } | ||
| let mut h = Headless::new(LightcraftApp::new(s, Services { png: None, ..Default::default() }), [1000.0, 700.0], 1.0); | ||
| h.app.ui.thumb_size = 160.0; | ||
| h.app.ui.view = view; | ||
| let open = Rc::new(Cell::new(false)); | ||
| h.app.renderer.set_offload(Box::new(RenderGate::failing(open.clone(), |s| matches!(s, Slot::Thumb(_) | Slot::ThumbQuick(_))))); | ||
| (h, open) | ||
| } | ||
|
|
||
| fn ids(h: &Headless, prefix: &str) -> Vec<String> { | ||
| h.app.widgets.iter().filter(|(w, _)| w.starts_with(prefix)).map(|(w, _)| w.clone()).collect() | ||
| } | ||
|
|
||
| /// Frames until the grid has its cells. | ||
| fn first_grid_frame(h: &mut Headless) { | ||
| for _ in 0..20 { | ||
| h.step(); | ||
| if !ids(h, "thumb:").is_empty() { | ||
| return; | ||
| } | ||
| } | ||
| panic!("the grid was never drawn"); | ||
| } | ||
|
|
||
| /// Given a grid whose thumbnails have not arrived, when a frame is drawn, then each cell carries the loading cue; and once the | ||
| /// files turn out unreadable the cue is gone and the cells say so instead. | ||
| #[test] | ||
| fn a_cell_still_loading_differs_from_one_that_failed() { | ||
| for view in [ViewMode::PhotoGrid, ViewMode::SquareGrid] { | ||
| let (mut h, open) = app_with_held_thumbnails(view); | ||
| first_grid_frame(&mut h); | ||
| let loading = ids(&h, "badge:loading:"); | ||
| assert!(loading.len() >= 6, "{view:?}: the cells on screen are loading: {loading:?}"); | ||
| assert!(!h.painted_text().iter().any(|t| t == "!"), "{view:?}: none of them has failed yet"); | ||
|
|
||
| open.set(true); | ||
| assert!(h.settle(SETTLE)); | ||
| assert!(ids(&h, "badge:loading:").is_empty(), "{view:?}: the cue goes once the failure is known: {:?}", ids(&h, "badge:loading:")); | ||
| assert!(h.painted_text().iter().any(|t| t == "!"), "{view:?}: an unreadable cell says so"); | ||
| } | ||
| } | ||
|
|
||
| /// The cue sits inside its cell's placeholder, small and centered. | ||
| #[test] | ||
| fn the_loading_cue_is_a_small_mark_in_the_middle_of_the_cell() { | ||
| let (mut h, _open) = app_with_held_thumbnails(ViewMode::SquareGrid); | ||
| first_grid_frame(&mut h); | ||
| let cell = |id: &str| h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r).unwrap(); | ||
| let id = ids(&h, "badge:loading:").remove(0); | ||
| let photo = id.trim_start_matches("badge:loading:"); | ||
| let cue = cell(&id); | ||
| let thumb = cell(&format!("thumb:{photo}")); | ||
| assert!(thumb.contains_rect(cue), "{cue:?} in {thumb:?}"); | ||
| assert!(cue.width() < thumb.width() / 3.0 && cue.height() < thumb.height() / 3.0, "quiet: {cue:?} in {thumb:?}"); | ||
| assert!((cue.center() - thumb.center()).length() < 14.0, "centered: {cue:?} in {thumb:?}"); | ||
| } | ||
|
|
||
| /// The filmstrip's tiles tell loading from unreadable the same way. | ||
| #[test] | ||
| fn the_filmstrip_tells_loading_from_unreadable_too() { | ||
| let (mut h, open) = app_with_held_thumbnails(ViewMode::PhotoGrid); | ||
| let r = h.request("ui.set", serde_json::json!({"view": "detail"}), SETTLE); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| h.step(); | ||
| assert!(!ids(&h, "film:badge:loading:").is_empty(), "the tiles are loading: {:?}", ids(&h, "film:")); | ||
| open.set(true); | ||
| assert!(h.settle(SETTLE)); | ||
| assert!(ids(&h, "film:badge:loading:").is_empty(), "gone once the failure is known"); | ||
| } | ||
|
|
||
| /// A failure left by an earlier request is not this tile's verdict: the filmstrip asks for its | ||
| /// thumbnail before it reads the failure, so its first frame says loading, not "!". | ||
| #[test] | ||
| fn a_filmstrip_tile_asks_for_its_thumbnail_before_it_reads_an_old_failure() { | ||
| let (mut h, _open) = app_with_held_thumbnails(ViewMode::Detail); | ||
| for i in 1..=12u64 { | ||
| h.app.renderer.record_failure_for_test(Slot::ThumbQuick(PhotoId(i)), PhotoId(i)); | ||
| } | ||
| // the first frame that draws the strip: nothing was asked for yet | ||
| let mut drawn = false; | ||
| for _ in 0..20 { | ||
| h.step(); | ||
| if !ids(&h, "film:").is_empty() { | ||
| drawn = true; | ||
| break; | ||
| } | ||
| } | ||
| assert!(drawn, "the strip is drawn"); | ||
| assert!(!h.painted_text().iter().any(|t| t == "!"), "no tile says it can't be opened on an old failure"); | ||
| } | ||
|
|
||
| /// The smallest square cells still hold the cue: its size is judged against the cell, and the cue | ||
| /// itself must fit the placeholder left inside it. | ||
| #[test] | ||
| fn the_smallest_square_cells_still_show_the_loading_cue() { | ||
| let (mut h, _open) = app_with_held_thumbnails(ViewMode::SquareGrid); | ||
| h.app.ui.thumb_size = crate::state::THUMB_SIZE_MIN; | ||
| first_grid_frame(&mut h); | ||
| let cues = ids(&h, "badge:loading:"); | ||
| assert!(!cues.is_empty(), "the cells on screen are loading and say so: {:?}", ids(&h, "thumb:")); | ||
| for id in cues { | ||
| let photo = id.trim_start_matches("badge:loading:"); | ||
| let cue = h.app.widgets.iter().find(|(w, _)| *w == id).map(|(_, r)| *r).unwrap(); | ||
| let cell = h.app.widgets.iter().find(|(w, _)| *w == format!("thumb:{photo}")).map(|(_, r)| *r).unwrap(); | ||
| assert!(cell.contains_rect(cue), "{cue:?} in {cell:?}"); | ||
| } | ||
| } | ||
|
|
||
| /// No thumbnail job is ever asked for a video (the image decoders can't read one), so its placeholder is not | ||
| /// "on its way": it stays the plain skeleton it was, in both grids and the filmstrip, before and after the | ||
| /// renders are let through. | ||
| #[test] | ||
| fn a_video_placeholder_never_shows_the_loading_cue() { | ||
| for view in [ViewMode::PhotoGrid, ViewMode::SquareGrid] { | ||
| let (mut h, open) = app_with_held_files(view, "mp4", "MP4"); | ||
| first_grid_frame(&mut h); | ||
| assert!(ids(&h, "badge:loading:").is_empty(), "{view:?}: a video has no thumbnail coming: {:?}", ids(&h, "badge:loading:")); | ||
| open.set(true); | ||
| assert!(h.settle(SETTLE)); | ||
| assert!(ids(&h, "badge:loading:").is_empty(), "{view:?}: {:?}", ids(&h, "badge:loading:")); | ||
| assert!(!h.painted_text().iter().any(|t| t == "!"), "{view:?}: nothing failed: a video is never read as an image"); | ||
| } | ||
| let (mut h, _open) = app_with_held_files(ViewMode::PhotoGrid, "mp4", "MP4"); | ||
| let r = h.request("ui.set", serde_json::json!({"view": "detail"}), SETTLE); | ||
| assert_eq!(r["ok"], true, "{r}"); | ||
| h.step(); | ||
| assert!(!ids(&h, "film:").is_empty(), "the strip is drawn"); | ||
| assert!(ids(&h, "film:badge:loading:").is_empty(), "the filmstrip's video tiles stay plain: {:?}", ids(&h, "film:badge:loading:")); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.