feat(thumbnail): embed a DWG preview on save, show it on the Start page

Generate a small wire-raster thumbnail when saving a DWG and embed it via
acadrust's preview API, so OCS drawings show a thumbnail in file browsers
and other CAD applications. Read the embedded preview back cheaply (file
header + preview bytes only, no full parse) to show a thumbnail per file
in the Start page's Recent Documents panel.

- io/thumbnail.rs: CPU rasterizer (current-layout wires -> BMP DIB) plus
  a preview-only reader/decoder (BMP/PNG -> iced handle) for the Start
  page.
- Embedded on save via stamp_thumbnail on both save paths.
- recent_thumbs cache filled on config load / recents change (never from
  a view); a thumbnail is drawn beside each recent file.

Requires acadrust at 3111694 (preview read/write), already pinned in
Cargo.lock.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-10 23:03:23 +03:00
commit 5c4ba97c5f
7 changed files with 326 additions and 10 deletions

View file

@ -17,9 +17,21 @@ impl OpenCADStudio {
self.recent_files.retain(|r| r != &path);
self.recent_files.insert(0, path);
self.recent_files.truncate(self.recent_limit);
self.refresh_recent_thumbs();
self.save_config();
}
/// Decode any not-yet-cached DWG preview thumbnails for the current recents
/// (cheap preview-only reads). Cached per path; safe to call repeatedly.
/// Call when the recents list changes — never from a `view`.
pub(super) fn refresh_recent_thumbs(&mut self) {
for path in self.recent_files.clone() {
self.recent_thumbs
.entry(path.clone())
.or_insert_with(|| crate::io::thumbnail::read_handle(&path));
}
}
/// Drop a path from the recents list (manual removal from the Start page).
pub(super) fn remove_recent(&mut self, path: &Path) {
self.recent_files.retain(|r| r.as_path() != path);