From ef1a400bb3a3c2b212aed041a905f63c7b714e2b Mon Sep 17 00:00:00 2001 From: neosandeep24 <103883917+neosandeep24@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:19:39 +0000 Subject: [PATCH] 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 --------- Co-authored-by: bherbruck Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/home.rs | 39 +++++++++++++++++++++++--- crates/ui-egui/src/ui_kit/file_view.rs | 8 +++++- crates/ui-egui/src/ui_kit/gallery.rs | 10 ++++++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 311a958fe..d5d4c8e12 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -40,6 +40,10 @@ pub struct HomeState { /// them back. Opening or saving a design clears it from here. pub forgotten: std::collections::BTreeSet, thumbs: HashMap>, + /// 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, samples: HashMap, /// Keys asked for and not made yet. queued: Vec, @@ -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) { - 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::().ok())) { @@ -821,6 +849,9 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option { 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()); diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs index d86a660f1..aecba440c 100644 --- a/crates/ui-egui/src/ui_kit/gallery.rs +++ b/crates/ui-egui/src/ui_kit/gallery.rs @@ -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, _| {