SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Home: recent card no longer spins forever when its picture can't be made (#4655) (#4721)
neosandeep24ef1a400bb3a3
diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rsindex 311a958feb..d5d4c8e126 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<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<Filewhen: &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);diff --git a/crates/ui-egui/src/ui_kit/file_view.rs b/crates/ui-egui/src/ui_kit/file_view.rsindex d9e34b3e81..57fafc3ad5 100644--- a/crates/ui-egui/src/ui_kit/file_view.rs+++ b/crates/ui-egui/src/ui_kit/file_view.rs@@ -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());diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rsindex d86a660f12..aecba440c5 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, _| {