Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Sidebar: names end in an ellipsis at the count; bars end at the panel edge

Nathaniel Ledford46c4a2709d92
diff --git a/crates/ui-egui/src/panels/left.rs b/crates/ui-egui/src/panels/left.rs
index 3e98e2d79..253ca4d6e 100644
--- a/crates/ui-egui/src/panels/left.rs
+++ b/crates/ui-egui/src/panels/left.rs
@@ -17,6 +17,9 @@ pub(crate) fn content_width(ctx: &egui::Context) -> f32 {
ctx.data(|d| d.get_temp::<f32>(egui::Id::new("left-content-width"))).unwrap_or(0.0)
}
+/// The most a row asks for its name: longer ones are cut when there is no more room.
+const MAX_NAME_NEED: f32 = 140.0;
+
/// A row says how wide it needs to be.
fn note_width(ui: &egui::Ui, w: f32) {
ui.data_mut(|d| {
@@ -60,9 +63,14 @@ fn row_named(
None => said.to_string(),
};
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, selected, &name));
- let inner = r.shrink2(vec2(8.0, 0.0));
+ // what is visible of the row: when the sidebar is scrolled sideways its bars and counts end at
+ // the panel's edge, not at the end of the (wider) content
+ let visible_right: f32 = ui.data(|d| d.get_temp(egui::Id::new("left-visible-right"))).unwrap_or(f32::MAX);
+ let edge = r.right().min(visible_right);
+ let inner = Rect::from_min_max(r.min + vec2(8.0, 0.0), pos2((r.right() - 8.0).min(edge - 8.0).max(r.left() + 8.0), r.bottom()));
if selected {
ui.painter().rect_filled(inner, 4.0, t.canvas);
+ register(ui.ctx(), format!("highlight:{id}"), inner);
} else if resp.hovered() {
ui.painter().rect_filled(inner, 4.0, t.hover.gamma_multiply(0.6));
}
@@ -72,27 +80,27 @@ fn row_named(
icon,
if selected { t.text } else { t.icon },
);
- let label_rect = ui.painter().text(
- pos2(r.left() + 42.0 + indent, r.center().y),
- Align2::LEFT_CENTER,
- label,
- t.font(13.5),
- if selected { t.text } else { t.text_label },
- );
- let mut needed = label_rect.right() - r.left() + 18.0;
- if let Some(n) = count.filter(|_| app.ui.show_counts) {
- // the count stays at the visible edge when the sidebar is scrolled sideways
- let visible_right: f32 = ui.data(|d| d.get_temp(egui::Id::new("left-visible-right"))).unwrap_or(f32::MAX);
- let galley = ui.painter().layout_no_wrap(n.to_string(), t.font(12.5), t.text_dim);
- let right = r.right().min(visible_right) - 18.0;
- let rect = Rect::from_min_size(pos2(right - galley.size().x, r.center().y - galley.size().y / 2.0), galley.size());
- if label_rect.right() + 6.0 > rect.left() {
- // a long name runs under it: the count gets the row's colour behind it
- ui.painter().rect_filled(rect.expand2(vec2(6.0, 2.0)), 3.0, if selected { t.canvas } else { t.chrome });
- }
- ui.painter().galley(rect.min, galley, t.text_dim);
- register(ui.ctx(), format!("count:{id}"), rect);
+ let font = t.font(13.5);
+ let color = if selected { t.text } else { t.text_label };
+ let count_galley = count.filter(|_| app.ui.show_counts).map(|n| ui.painter().layout_no_wrap(n.to_string(), t.font(12.5), t.text_dim));
+ let label_left = r.left() + 42.0 + indent;
+ let count_left = count_galley.as_ref().map_or(edge - 18.0, |g| edge - 18.0 - g.size().x);
+ // the name gives way to the count: cut with an ellipsis, in full on hover
+ let room = count_left - 8.0 - label_left;
+ let measure = |s: &str| ui.painter().layout_no_wrap(s.to_string(), font.clone(), color).size().x;
+ let full_w = measure(label);
+ let shown = if full_w <= room { label.to_string() } else { crate::widgets::elide_head(label, room.max(0.0), measure) };
+ let label_rect = ui.painter().text(pos2(label_left, r.center().y), Align2::LEFT_CENTER, &shown, font.clone(), color);
+ register(ui.ctx(), format!("label:{id}"), label_rect);
+ let resp = if shown != label { resp.on_hover_text(label) } else { resp };
+ // a row asks for room for its name up to a share of a panel, so one very long name does not
+ // make everything scroll: depth does that
+ let mut needed = 42.0 + indent + full_w.min(MAX_NAME_NEED) + 18.0;
+ if let Some(galley) = count_galley {
+ let rect = Rect::from_min_size(pos2(edge - 18.0 - galley.size().x, r.center().y - galley.size().y / 2.0), galley.size());
needed += rect.width() + 16.0;
+ register(ui.ctx(), format!("count:{id}"), rect);
+ ui.painter().galley(rect.min, galley, t.text_dim);
}
note_width(ui, needed);
let _ = app;
diff --git a/crates/ui-egui/src/tests_panels.rs b/crates/ui-egui/src/tests_panels.rs
index a8a65e624..ecb5cb5c0 100644
--- a/crates/ui-egui/src/tests_panels.rs
+++ b/crates/ui-egui/src/tests_panels.rs
@@ -479,3 +479,59 @@ fn a_long_folder_name_never_runs_under_the_photo_count() {
let (title, count) = (widget(&h, "grid:title"), widget(&h, "grid:count"));
assert!(title.right() + 8.0 <= count.left(), "title {title:?} vs count {count:?}");
}
+
+fn tooltip_shown(h: &Headless) -> bool {
+ h.view.ctx.memory(|m| m.areas().visible_layer_ids().into_iter().any(|l| l.order == egui::Order::Tooltip))
+}
+
+const LONG_NAME: &str = "Aliah Ira Polanco-Grylls and a name much longer than any sidebar row can show";
+
+/// A name never runs past the photo count: it is cut with an ellipsis, in full on hover.
+#[test]
+fn a_long_name_stops_at_the_count_and_shows_in_full_on_hover() {
+ let mut h = folders_app(&[&format!("/pics/{LONG_NAME}/a.jpg"), "/pics/short/b.jpg"]);
+ click(&mut h, "libraryFolderToggle:/pics");
+ let (long, short) = (format!("/pics/{LONG_NAME}"), "/pics/short".to_string());
+ let (label, count) = (widget(&h, &format!("label:libfolder:{long}")), widget(&h, &format!("count:libfolder:{long}")));
+ assert!(label.right() + 4.0 <= count.left(), "label {label:?} stays left of the count {count:?}");
+ let short_label = widget(&h, &format!("label:libfolder:{short}"));
+ assert!(short_label.width() < label.width(), "a name that fits is not cut");
+ // hovering the cut one shows the whole name; a name that fits needs no tooltip of its own
+ let c = widget(&h, &format!("source:libfolder:{long}")).center();
+ let r = h.request("ui.move", json!({"x": c.x, "y": c.y}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ assert!(h.step_until(Duration::from_secs(5), tooltip_shown), "the full name appears on hover");
+}
+
+/// More room shows more of the name.
+#[test]
+fn widening_the_sidebar_shows_more_of_a_long_name() {
+ let mut h = folders_app(&[&format!("/pics/{LONG_NAME}/a.jpg"), "/pics/short/b.jpg"]);
+ click(&mut h, "libraryFolderToggle:/pics");
+ let id = format!("label:libfolder:/pics/{LONG_NAME}");
+ let narrow = widget(&h, &id).width();
+ let r = h.request("ui.set", json!({"leftWidth": 480.0}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ h.step();
+ assert!(widget(&h, &id).width() > narrow + 100.0, "a wider panel shows more of it");
+}
+
+/// A long name alone does not make the sidebar scroll sideways: depth does.
+#[test]
+fn a_long_name_alone_does_not_make_the_sidebar_scroll() {
+ let h = folders_app(&[&format!("/{LONG_NAME}/a.jpg")]);
+ let panel = widget(&h, "panel:left_panel");
+ assert!(crate::panels::left::content_width(&h.view.ctx) <= panel.width(), "a name takes at most what a row can show");
+}
+
+/// The selection bar ends at the panel's edge, not past it, when the content is wider.
+#[test]
+fn the_selection_bar_stays_inside_the_panel() {
+ let deep = "/a/b/c/d/e/f/g/h/i/j/k/l/m";
+ let mut h = folders_app(&[&format!("{deep}/x/1.jpg"), &format!("{deep}/y/2.jpg")]);
+ click(&mut h, "source:libfolder:/a/b/c/d/e/f/g/h/i/j/k/l");
+ let panel = widget(&h, "panel:left_panel");
+ let bar = widget(&h, "highlight:libfolder:/a/b/c/d/e/f/g/h/i/j/k/l");
+ assert!(bar.right() <= panel.right(), "the bar {bar:?} ends inside the panel {panel:?}");
+}
diff --git a/docs/parity.md b/docs/parity.md
index d8b90a3cc..2a524c432 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -718,7 +718,7 @@ From `08-lightroom-classic-extras.md` (Classic-only features) and part 2 of `06-
| LRC-LIB-CATALOG-PANEL | Catalog sets | P1 | ✅ | `cmd:library.source` (`missing`) | all, recently added, picks, recently deleted, missing photos (when any) |
| LRC-LIB-CATALOG-LOCK | Catalog open in one program at a time | P1 | ✅ | `cmd:app.openLibrary`, `crates/catalog/src/lock.rs`, `crates/engine/src/library.rs` (`open_library`) | exclusive OS lock on `catalog.lock` for the session (app and `lightcraft-cli --library`); a second opener is refused with who has it (`catalog.lock.owner`: program, process, computer); released by the OS on a crash, so never stale; file systems without locks open unprotected with a warning; no read-only mode; the browser build (OPFS) has no guard across tabs yet. A library that can't be opened at launch (locked, unreadable, newer format, drive missing) shows a window — Try Again, Choose Another Library…, Continue Without Saving (then a banner; nothing written), Quit — instead of a silent demo session (`crates/ui-egui/src/panels/library_problem.rs`) |
| LRC-LIB-FOLDERS | Disk folder tree | P1 | ✅ | `cmd:library.browse`, `cmd:folder.rename`, `cmd:folder.move`, `crates/ui-egui/src/panels/left.rs` (`local_section`, `folder_tree`) | standard places + the browsed folder + Browse Folder…, each an expandable tree of subfolders, breadcrumb navigation; context menu: Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked; one undo step each: undo / redo move the folder back and forth, refused when the destination is taken) |
-| LRC-LIB-LIBFOLDERS | Library folders | P1 | ✅ | `cmd:library.folders`, `cmd:library.source` (`libraryFolder`), `cmd:library.filter` (`libraryFolder`), `cmd:library.removeFolder`, `cmd:folder.rename`, `cmd:folder.move`, `crates/catalog/src/folders.rs`, `crates/ui-egui/src/panels/left.rs` (`folders_section`, `folder_menu_for_library`, `row_menu`), `crates/ui-egui/src/tests_panels.rs` | sidebar Folders: the folders the library's photos were imported from, with photo counts (subfolders included), as another way to explore the library next to By Date and Keywords; Local stays the way to browse any folder on disk. Each disk is a row of its own and starts open: a drive letter, a Windows share (`\\server\share`, `\\?\UNC\…`, `\\wsl$\…`), a macOS share or disk (`/Volumes/tokyo`), a Linux mount (`/media`, `/run/media`, `/mnt`, gvfs `smb-share:…`, `/net/<host>`), NFS (`/Network/Servers/<host>`), else “This Computer” — told apart from the stored paths alone, so an offline share lists like a mounted one and the sidebar never waits on a network. Only folders that hold imported photos are listed (browsed, deleted and demo photos don't count); every folder is a row of its own (`Users` → `me` → `Pictures`), and a folder that holds nothing itself and leads to one folder starts open; every level indents one step more than its parent however deep it goes: the whole sidebar (Albums, Local, By Date, Folders, Keywords) scrolls sideways when its widest row is wider than the panel (rows are measured one frame behind; Create Album and the counts stay at the visible edge); the grid title is cut with the full name on hover; click makes the folder the source, like an album or a Local folder (its photos and those of the folders inside it fill the grid, titled “photos/travel”; the filter bar narrows it further; `library.source` `libraryFolder` + `path`; kept with the library's view), and its row is always opened into view; the shown folder follows a rename or move and their undo (engine-tested; the sidebar test covers rename), is dropped back to All Photos when it is removed or no longer holds a photo, and a smart album made from the view keeps it, also when its rules are edited (the editor has no folder field). Only a folder that shows exactly its own photos can be shown (not the startup disk, not `/Volumes`-like folders above disks, not an empty one). A row that would cover other disks' photos too (the startup disk, `/Volumes`, `/mnt`…) only opens. Right-click (row or triangle): Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked, as in Local) and Remove from Library… (asks; moves the folder's photos to Recently Deleted, one undo step, no file touched); a disk row offers Remove Disk from Library… (the command needs `disk: true` for a whole disk or a folder spanning several). Limits: names are compared as written (macOS `/Volumes/tokyo` vs `/Volumes/TOKYO` are two disks; `/Volumes/Macintosh HD/…` and `/…` two rows); no disk capacity / online status; no “include subfolders” switch (a folder always includes the ones inside it); creating a folder and moving photos between folders are not here |
+| LRC-LIB-LIBFOLDERS | Library folders | P1 | ✅ | `cmd:library.folders`, `cmd:library.source` (`libraryFolder`), `cmd:library.filter` (`libraryFolder`), `cmd:library.removeFolder`, `cmd:folder.rename`, `cmd:folder.move`, `crates/catalog/src/folders.rs`, `crates/ui-egui/src/panels/left.rs` (`folders_section`, `folder_menu_for_library`, `row_menu`), `crates/ui-egui/src/tests_panels.rs` | sidebar Folders: the folders the library's photos were imported from, with photo counts (subfolders included), as another way to explore the library next to By Date and Keywords; Local stays the way to browse any folder on disk. Each disk is a row of its own and starts open: a drive letter, a Windows share (`\\server\share`, `\\?\UNC\…`, `\\wsl$\…`), a macOS share or disk (`/Volumes/tokyo`), a Linux mount (`/media`, `/run/media`, `/mnt`, gvfs `smb-share:…`, `/net/<host>`), NFS (`/Network/Servers/<host>`), else “This Computer” — told apart from the stored paths alone, so an offline share lists like a mounted one and the sidebar never waits on a network. Only folders that hold imported photos are listed (browsed, deleted and demo photos don't count); every folder is a row of its own (`Users` → `me` → `Pictures`), and a folder that holds nothing itself and leads to one folder starts open; every level indents one step more than its parent however deep it goes: the whole sidebar (Albums, Local, By Date, Folders, Keywords) scrolls sideways when its widest row is wider than the panel (rows are measured one frame behind; Create Album and the counts stay at the visible edge); a name that does not fit ends in an ellipsis at the count (the full name on hover; a row asks for room for at most 140 pt of its name, so depth, not one long name, makes the sidebar scroll), as does the grid title; selection and hover bars end at the panel's edge; click makes the folder the source, like an album or a Local folder (its photos and those of the folders inside it fill the grid, titled “photos/travel”; the filter bar narrows it further; `library.source` `libraryFolder` + `path`; kept with the library's view), and its row is always opened into view; the shown folder follows a rename or move and their undo (engine-tested; the sidebar test covers rename), is dropped back to All Photos when it is removed or no longer holds a photo, and a smart album made from the view keeps it, also when its rules are edited (the editor has no folder field). Only a folder that shows exactly its own photos can be shown (not the startup disk, not `/Volumes`-like folders above disks, not an empty one). A row that would cover other disks' photos too (the startup disk, `/Volumes`, `/mnt`…) only opens. Right-click (row or triangle): Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked, as in Local) and Remove from Library… (asks; moves the folder's photos to Recently Deleted, one undo step, no file touched); a disk row offers Remove Disk from Library… (the command needs `disk: true` for a whole disk or a folder spanning several). Limits: names are compared as written (macOS `/Volumes/tokyo` vs `/Volumes/TOKYO` are two disks; `/Volumes/Macintosh HD/…` and `/…` two rows); no disk capacity / online status; no “include subfolders” switch (a folder always includes the ones inside it); creating a folder and moving photos between folders are not here |
| LRC-LIB-COLLECTIONS | Collections & sets | P1 | ✅ | `cmd:album.create`, `cmd:album.createSmart`, `cmd:album.toggleTarget`, `cmd:album.setTarget`, `cmd:album.clearQuick` | albums + folders (sets), smart albums (rule editor; rules incl. File Path — the whole string, either separator, case-insensitive), Quick Collection and target album (B in the grids adds / removes the selection; album menu ▸ Set as Target Album; the target is marked +) |
| LRC-LIB-SMARTCOLL | Smart-collection rules | P1 | ✅ | `cmd:album.createSmart`, `cmd:album.setRules`, `cmd:album.ruleFields`, `cmd:dialog.smartAlbum`, `crates/catalog/src/rules.rs`, `crates/ui-egui/src/panels/rules_editor.rs` | rule editor: match all / any / none, nested groups (⌥+ or + Group), 30 fields (rating, flag, label, type, edits, keywords, any text, filename, file path, format, title, caption, camera, lens, location, creator, copyright, copyright status, capture / import / edit date, ISO, aperture, focal length, megapixels, GPS, virtual copy, album) with text / number / date / in-the-last operators; live match count; also usable as a library filter (`ruleSet`) |
| LRC-LIB-PUBLISH | Publish services | P2 | ⬜ | | |