Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/ui-egui/src/panels/detail/filmstrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ pub(crate) fn filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui, r: Rect) {
continue;
}
let resp = ui.interact(cr, egui::Id::unique(("film", id.0)), Sense::click_and_drag());
let failed = app.renderer.thumb(*id).is_none() && app.renderer.failure(Slot::Thumb(*id)).is_some();
// asked for first: a failure left by an earlier request is not this tile's verdict once a new one is on its way
crate::panels::grid::request_thumb(app, *id, (256.0 * ppp.min(2.0) / 2.0) as usize * 2, 8);
let failed = app.renderer.thumb(*id).is_none() && app.renderer.thumb_failure(*id).is_some();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
crate::widgets::announce(&resp, film_spoken(app.session.catalog.photo(*id).map_or("", |p| p.file_name.as_str()), failed));
register(ui, format!("film:{}", id.0), cr);
let state = app.session.selection.state_of(*id);
Expand All @@ -119,12 +121,13 @@ pub(crate) fn filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui, r: Rect) {
p.text(pos2(cr.right() - 8.0, cr.top() + 10.0), Align2::RIGHT_CENTER, &ph.format, t.semibold(8.5), t.text_dim);
}
let img_area = Rect::from_min_max(cr.min + vec2(10.0, 22.0), cr.max - vec2(10.0, 8.0));
crate::panels::grid::request_thumb(app, *id, (256.0 * ppp.min(2.0) / 2.0) as usize * 2, 8);
let thumb = app.renderer.thumb(*id);
if thumb.is_none() {
p.rect_filled(img_area, 0.0, t.skeleton);
if failed {
p.text(img_area.center(), Align2::CENTER_CENTER, "!", t.semibold(14.0), t.text);
} else if crate::panels::grid::thumb_may_arrive(app, *id) {
crate::panels::grid::paint_loading_cue(p, &t, img_area, img_area, "film:badge:loading:", id.0);
}
}
if let Some(tex) = thumb {
Expand Down
32 changes: 31 additions & 1 deletion crates/ui-egui/src/panels/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
Expand Down
25 changes: 25 additions & 0 deletions crates/ui-egui/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,12 @@ impl Renderer {
self.pool.wait(timeout)
}

/// Test seam: a failure left by an earlier request of `slot` for `photo` (a key no later job has).
#[cfg(test)]
pub(crate) fn record_failure_for_test(&mut self, slot: Slot, photo: PhotoId) {
self.failed.insert(slot, (0, "an earlier failure".into(), 0, photo));
}

/// Test seam: make the renderer look busy without starting a job (capture deadlines).
#[cfg(test)]
pub(crate) fn force_in_flight_for_test(&mut self, count: usize) {
Expand All @@ -1081,6 +1087,25 @@ impl Renderer {
self.failed.get(&slot).map(|f| f.1.as_str())
}

/// Why a photo has no grid thumbnail and won't get one: the thumbnail's own render failed, or the embedded
/// preview failed and nothing else is on its way (an unedited raw asks for no other: see `request_thumb`).
/// A new request of either kind (another size or look, a relinked file; an undone edit asks only for the
/// embedded preview, under a key of its own) is on its way too; a retry of the very request that failed
/// keeps the failure until it answers.
pub fn thumb_failure(&self, id: PhotoId) -> Option<&str> {
let (full, quick) = (Slot::Thumb(id), Slot::ThumbQuick(id));
if self.is_pending(full) && !self.retrying(full) {
return None;
}
if let Some((key, why, ..)) = self.failed.get(&full) {
// the full render failed: that stands unless a new embedded-preview request is on its way (it carries
// its job's key, so the key that failed is the retry)
return if self.pending.get(&quick).is_some_and(|p| p.0 != *key) { None } else { Some(why.as_str()) };
}
// else the embedded preview's failure, unless a new request of it is on its way
if self.is_pending(quick) && !self.retrying(quick) { None } else { self.failure(quick) }
}

/// Why the last render of `photo` for `slot` failed: a view slot shows one photo after
/// another, and another photo's error isn't this one's.
pub fn failure_of(&self, slot: Slot, photo: PhotoId) -> Option<&str> {
Expand Down
57 changes: 57 additions & 0 deletions crates/ui-egui/src/render/thumbnail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,3 +1945,60 @@ fn stepping_fast_drops_the_queued_before_render() {
assert!(!app.renderer.is_pending(slot), "{slot:?} still queued");
}
}

#[test]
fn thumb_failure_reports_only_a_thumbnail_that_will_not_arrive() {
let id = PhotoId(5);
let mut r = Renderer::default();
assert_eq!(r.thumb_failure(id), None, "nothing failed");
// An unedited raw asks only for the embedded preview: its failure is final.
r.failed.insert(Slot::ThumbQuick(id), (1, "no embedded preview".into(), 0, id));
assert_eq!(r.thumb_failure(id), Some("no embedded preview"));
// While the full render is still on its way, the cell is loading, not unreadable.
r.pending.insert(Slot::Thumb(id), (2, 10));
assert_eq!(r.thumb_failure(id), None, "a pending thumbnail may still arrive");
r.failed.insert(Slot::Thumb(id), (2, "decode failed".into(), 0, id));
assert_eq!(r.thumb_failure(id), Some("decode failed"));
}

#[test]
fn thumb_failure_waits_for_a_new_quick_request_but_not_for_a_retry_of_the_failed_one() {
let id = PhotoId(6);
let mut r = Renderer::default();
r.failed.insert(Slot::ThumbQuick(id), (1, "no embedded preview".into(), 0, id));
// the size changed: a new embedded-preview request (another key) is on its way, so the cell is loading
r.pending.insert(Slot::ThumbQuick(id), (3, 10));
assert_eq!(r.thumb_failure(id), None, "a replacement of the failed quick render is pending");
// the very request that failed is asked for again (after an eviction): until it answers the failure stands
r.pending.insert(Slot::ThumbQuick(id), (1, 10));
assert_eq!(r.thumb_failure(id), Some("no embedded preview"));
}

#[test]
fn thumb_failure_waits_for_a_new_full_request_but_not_for_a_retry_of_the_failed_one() {
let id = PhotoId(7);
let mut r = Renderer::default();
r.failed.insert(Slot::Thumb(id), (1, "decode failed".into(), 0, id));
// the size changed or the file was relinked: a replacement with another key is on its way, so the cell is loading
r.pending.insert(Slot::Thumb(id), (3, 10));
assert_eq!(r.thumb_failure(id), None, "a replacement of the failed full render is pending");
// the very request that failed is asked for again: until it answers the failure stands
r.pending.insert(Slot::Thumb(id), (1, 10));
assert_eq!(r.thumb_failure(id), Some("decode failed"));
}

#[test]
fn thumb_failure_waits_for_a_new_quick_request_after_a_full_failure_but_not_for_a_retry_of_the_failed_one() {
let id = PhotoId(8);
let mut r = Renderer::default();
// an edited raw's full render failed; its edit was undone, so only the embedded preview is asked for
r.failed.insert(Slot::Thumb(id), (1, "decode failed".into(), 0, id));
r.pending.insert(Slot::ThumbQuick(id), (3, 10));
assert_eq!(r.thumb_failure(id), None, "a quick request with another key is on its way: the cell is loading");
// the very request that failed is asked for again: until it answers the failure stands
r.pending.insert(Slot::ThumbQuick(id), (1, 10));
assert_eq!(r.thumb_failure(id), Some("decode failed"));
// nothing is on its way
r.pending.clear();
assert_eq!(r.thumb_failure(id), Some("decode failed"));
}
1 change: 1 addition & 0 deletions crates/ui-egui/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mod library_problem;
mod lifecycle_037;
mod lightroom_destination;
mod lights_out;
mod loading_cell;
mod mask_effects;
mod masking;
mod masking_layout;
Expand Down
162 changes: 162 additions & 0 deletions crates/ui-egui/src/tests/loading_cell.rs
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:"));
}
2 changes: 2 additions & 0 deletions crates/ui-egui/src/tests/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ fn the_thumbnail_placeholder_stands_apart_in_every_theme() {
}
let mark = contrast(t.text, t.skeleton);
assert!(mark >= 3.0, "{kind:?}: the failure mark on the placeholder is {mark:.2}:1");
let dots = contrast(t.icon, t.skeleton);
assert!(dots >= 3.0, "{kind:?}: the loading dots on the placeholder are {dots:.2}:1");
}
}

Expand Down
Loading
Loading