Home: recent card no longer spins forever when its picture can't be made (#4655) (#4721)

* Home: stop a recent card spinning forever when its picture can't be made (#4655)

A recent design whose thumbnail job returned no picture (empty or unreadable design) kept the loading placeholder, which draws a spinner, with no retry. Record such keys as a terminal 'failed' state and draw a box placeholder instead; opening or saving the design clears it and tries again. Sample previews are untouched: a failed sample build still keeps its shipped picture.

* Format the gallery sample row

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-25 18:19:39 +00:00
1 parent 53c84eb3a7
commit ef1a400bb3
3 files changed
+51 -6

No files matched your search

+35 -4
View File
@@ -40,6 +40,10 @@ pub struct HomeState {
/// them back. Opening or saving a design clears it from here.
pub forgotten: std::collections::BTreeSet<String>,
thumbs: HashMap<String, Option<egui::TextureHandle>>,
/// Keys whose picture could not be made (an empty or unreadable design). Terminal: the card
/// shows a placeholder instead of spinning forever. Cleared when the design is opened or saved
/// (see `add_recent`), which asks for the picture again.
failed: std::collections::HashSet<String>,
samples: HashMap<usize, Session>,
/// Keys asked for and not made yet.
queued: Vec<String>,
@@ -79,6 +83,12 @@ impl HomeState {
self.recent.iter().filter(|p| self.thumbs.get(*p).is_some_and(Option::is_some)).count()
}
/// Whether a design's picture could not be made, so its card shows a placeholder rather than
/// a spinner that would otherwise turn forever.
fn thumb_failed(&self, key: &str) -> bool {
self.failed.contains(key)
}
pub fn ready_samples(&self) -> usize {
(0..solidcraft_engine::sample::samples().len()).filter(|i| self.thumbs.get(&format!("sample:{i}")).is_some_and(Option::is_some)).count()
}
@@ -100,6 +110,8 @@ impl HomeState {
self.thumbs.remove(path);
// Opening or saving a design undoes an earlier removal from the list.
self.forgotten.remove(path);
// A fresh open or save earns another attempt at the picture.
self.failed.remove(path);
}
/// Drop a design from the recent list and remember that the user did so, so a host that
@@ -255,8 +267,19 @@ pub(crate) fn remember_source(h: &mut HomeState, s: &Session, key: &str) {
}
pub(crate) fn install(h: &mut HomeState, ctx: &egui::Context, key: &str, img: Option<egui::ColorImage>) {
let tex = img.map(|i| ctx.load_texture(format!("thumb:{key}"), i, egui::TextureOptions::LINEAR));
h.thumbs.insert(key.to_string(), tex);
match img {
Some(i) => {
let tex = ctx.load_texture(format!("thumb:{key}"), i, egui::TextureOptions::LINEAR);
h.thumbs.insert(key.to_string(), Some(tex));
h.failed.remove(key);
}
// The job finished with no picture: an empty design, or one that could not be read. Mark
// it so the card stops spinning and shows a placeholder (#4655).
None => {
h.thumbs.insert(key.to_string(), None);
h.failed.insert(key.to_string());
}
}
}
/// Read a disposable picture without evaluating, importing or meshing a model.
@@ -438,8 +461,13 @@ fn poll(app: &mut SolveApp, ctx: &egui::Context) {
app.home.wanted = None;
app.set_status(format!("the sample could not be built ({key})"), true);
}
// A failed sample build does not discard its shipped preview.
if img.is_some() || !app.home.thumbs.contains_key(&key) {
// A failed sample build keeps its shipped preview, so never overwrite a sample that
// already has a picture with an empty result. A recent with no picture, though, must
// settle into a terminal "failed" state so its card stops spinning (#4655); `install`
// records that.
let is_sample = key.starts_with("sample:");
let already_ready = app.home.thumbs.get(&key).is_some_and(Option::is_some);
if img.is_some() || (!is_sample && !already_ready) || !app.home.thumbs.contains_key(&key) {
install(&mut app.home, ctx, &key, img);
}
if let (Some(s), Some(i)) = (session, key.strip_prefix("sample:").and_then(|i| i.parse::<usize>().ok())) {
@@ -821,6 +849,9 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option<File
when: &when,
workspace: app.tr("home.design_workspace"),
thumbnail: texture(app.home.thumbs.get(path).and_then(Option::as_ref)),
// A design whose picture could not be made shows a dimmed placeholder,
// distinct from the one shown while a picture is still loading (#4655).
thumbnail_failed: app.home.thumb_failed(path),
},
);
publish(&format!("home:recent:{index}"), &response);
+7 -1
View File
@@ -16,6 +16,9 @@ pub(crate) struct RecentRow<'a> {
pub when: &'a str,
pub workspace: &'a str,
pub thumbnail: Option<(TextureId, Vec2)>,
/// The design's picture could not be made (empty or unreadable). Draws a dimmed placeholder,
/// so it reads as "no preview" rather than as one still loading.
pub thumbnail_failed: bool,
}
#[derive(Clone, Copy)]
@@ -274,12 +277,15 @@ impl FileView {
let preview = Rect::from_min_size(inner.min, vec2(t.space_24 * 2.0, inner.height()).min(inner.size()));
thumbnail(ui, preview, row.thumbnail);
if row.thumbnail.is_none() {
// A design whose picture could not be made shows a fainter box, so it reads as "no
// preview" rather than as one still being drawn.
let opacity = if row.thumbnail_failed { 0.4 } else { 1.0 };
crate::icons::paint_accented(
ui.painter(),
Rect::from_center_size(preview.center(), Vec2::splat(t.space_24.min(preview.height()))),
"box",
None,
1.0,
opacity,
);
}
let left = (preview.right() + t.space_14).min(inner.right());
+9 -1
View File
@@ -300,6 +300,7 @@ const ELEMENTS: &[Element] = &[
when: "Open now",
workspace: "Design",
thumbnail: None,
thumbnail_failed: false,
},
);
}
@@ -309,7 +310,14 @@ const ELEMENTS: &[Element] = &[
FileView::recent_row(
ui,
"gallery:file:recent",
RecentRow { title: "Sample Plate", path: "Designs/sample-plate.solidcraft", when: "Open now", workspace: "Design", thumbnail: None },
RecentRow {
title: "Sample Plate",
path: "Designs/sample-plate.solidcraft",
when: "Open now",
workspace: "Design",
thumbnail: None,
thumbnail_failed: false,
},
);
}),
element!("file_sample", |ui, _| {