Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ui-egui/src/panels/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
let tree = app.caches.folder_tree(&app.session.catalog);
section(app, ui, s, tree.len(), |app, ui| {
reveal_chosen(app, ui, &tree);
folder_rows(app, ui, &tree, 0.0);
folder_rows(app, ui, &tree, 0.0, None);
})
}
SidebarSection::Keywords => {
let tree = app.caches.keyword_tree(&app.session.catalog);
section(app, ui, s, tree.len(), |app, ui| keyword_rows(app, ui, &tree, 0.0))
section(app, ui, s, tree.len(), |app, ui| keyword_rows(app, ui, &tree, 0.0, None))
}
};
placed.push(at);
Expand Down
21 changes: 15 additions & 6 deletions crates/ui-egui/src/panels/left/albums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::folders::{folder_menu, is_within};
use super::rows::{INDENT_STEP, Row, indent_x, set_tree_open, tree_open, tree_toggle};
use super::rows::{INDENT_STEP, Inside, Row, Said, indent_x, set_tree_open, tree_inside, tree_open, tree_toggle};
use super::{Album, AlbumId, Align2, Icon, LibrarySource, LightcraftApp, Rect, Sense, Tokens, json, pos2, register, vec2};

/// Albums: the tree of albums and the folders they are sorted into. `reveal`: an album just made,
Expand All @@ -13,14 +13,23 @@ pub(super) fn albums_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, reveal: Op
open_to.push(p);
cur = cat.album(p).and_then(|a| a.parent);
}
albums_tree(app, ui, &kids, None, 0.0, &open_to);
albums_tree(app, ui, &kids, None, 0.0, &open_to, None);
}

/// The albums inside each folder (`None`: the top level), in the order they are listed.
type AlbumKids = std::collections::HashMap<Option<AlbumId>, Vec<Album>>;

/// `open_to`: folders forced open this frame (the way down to an album that was just made).
fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, parent: Option<AlbumId>, indent: f32, open_to: &[AlbumId]) {
/// `above`: what holds for these rows from the folders above them ([`tree_inside`]).
fn albums_tree(
app: &mut LightcraftApp,
ui: &mut egui::Ui,
all: &AlbumKids,
parent: Option<AlbumId>,
indent: f32,
open_to: &[AlbumId],
above: Option<Said>,
) {
// 64 folders deep at most (16 points a level): a catalog that loops must not overflow the stack
if indent > 64.0 * INDENT_STEP {
return;
Expand All @@ -29,7 +38,7 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare
for a in kids {
if a.folder {
let open_id = egui::Id::unique(("folder-open", a.id.0));
let mut open = tree_open(ui, open_id, true);
let mut open = tree_open(ui, open_id, true, above);
if open_to.contains(&a.id) && !open {
open = true;
set_tree_open(ui, open_id, true);
Expand All @@ -47,7 +56,7 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare
let draw_open = open;
let mut toggled = false;
if has_children {
let tri = tree_toggle(ui, &resp, indent, open_id, &mut open, format!("albumToggle:{}", a.id.0), &a.name);
let tri = tree_toggle(ui, &resp, indent, open_id, &mut open, format!("albumToggle:{}", a.id.0), &a.name, Inside::OpensAndFolds);
toggled = tri.clicked();
// the triangle sits on the row and takes its clicks: the menu opens from it too
folder_menu(app, &tri, a);
Expand All @@ -58,7 +67,7 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare
}
folder_menu(app, &resp, a);
if draw_open {
albums_tree(app, ui, all, Some(a.id), indent + INDENT_STEP, open_to);
albums_tree(app, ui, all, Some(a.id), indent + INDENT_STEP, open_to, tree_inside(ui, open_id, above));
}
} else {
let sel = app.session.source == LibrarySource::Album(a.id);
Expand Down
27 changes: 18 additions & 9 deletions crates/ui-egui/src/panels/left/dates.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
use super::rows::{INDENT_STEP, Row, tree_open, tree_toggle};
use super::rows::{INDENT_STEP, Inside, Row, Said, tree_inside, tree_open, tree_toggle};
use super::{Icon, LibrarySource, LightcraftApp, json};

/// By Date: year → month → day; a click filters by that prefix, the triangle opens a level.
pub(super) fn date_rows(app: &mut LightcraftApp, ui: &mut egui::Ui) {
let groups = app.caches.date_groups(&app.session.catalog);
for g in groups.iter() {
if date_row(app, ui, &g.year, &crate::i18n::date_group_label(&g.year, true), g.count, 0.0) {
if date_row(app, ui, &g.year, &crate::i18n::date_group_label(&g.year, true), g.count, 0.0, None) {
let in_the_year = tree_inside(ui, date_open_id(&g.year), None);
for (m, n) in &g.months {
let label = crate::i18n::date_group_label(m, true);
if date_row(app, ui, m, &label, *n, INDENT_STEP) {
if date_row(app, ui, m, &label, *n, INDENT_STEP, in_the_year) {
for (d, n) in g.days.iter().filter(|(d, _)| d.starts_with(m.as_str())) {
let label = crate::i18n::date_group_label(d, true);
date_row(app, ui, d, &label, *n, 2.0 * INDENT_STEP);
date_row(app, ui, d, &label, *n, 2.0 * INDENT_STEP, None);
}
}
}
}
}
}

/// The id of the open state of the By Date row `key`.
fn date_open_id(key: &str) -> egui::Id {
egui::Id::unique(("date-open", key.to_string()))
}

/// One By Date row (`key`: `YYYY`, `YYYY-MM` or `YYYY-MM-DD`); returns whether it is open.
fn date_row(app: &mut LightcraftApp, ui: &mut egui::Ui, key: &str, label: &str, count: usize, indent: f32) -> bool {
let open_id = egui::Id::unique(("date-open", key.to_string()));
let mut open = tree_open(ui, open_id, false);
/// `above`: what holds for it from the rows above it ([`tree_inside`]).
fn date_row(app: &mut LightcraftApp, ui: &mut egui::Ui, key: &str, label: &str, count: usize, indent: f32, above: Option<Said>) -> bool {
let open_id = date_open_id(key);
let mut open = tree_open(ui, open_id, false, above);
let sel = app.session.filter.date.as_deref() == Some(key);
let resp = Row::new(&format!("date:{key}"), Icon::Clock, label).count(Some(count)).selected(sel).indent(indent).show(app, ui);
if key.len() < 10 {
// (the name carries the year, so two Marches in different years differ in a screen reader's list of triangles)
tree_toggle(ui, &resp, indent, open_id, &mut open, format!("dateToggle:{key}"), &crate::i18n::date_group_label(key, false));
// (the name carries the year, so two Marches in different years differ in a screen reader's list of triangles;
// a year's months open and fold with it, a month's days have nothing to open)
let inside = if key.len() < 7 { Inside::OpensAndFolds } else { Inside::Alone };
tree_toggle(ui, &resp, indent, open_id, &mut open, format!("dateToggle:{key}"), &crate::i18n::date_group_label(key, false), inside);
}
if resp.clicked() {
let v = if sel { serde_json::Value::Null } else { json!(key) };
Expand Down
22 changes: 13 additions & 9 deletions crates/ui-egui/src/panels/left/folders.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::albums::pointer_over_row;
use super::local::{is_builtin_place, same_folder, subfolders};
use super::rows::{INDENT_STEP, LIBFOLDER_REVEALED, Row, out_of_sight, set_tree_open, tree_open, tree_toggle};
use super::rows::{INDENT_STEP, Inside, LIBFOLDER_REVEALED, Row, Said, out_of_sight, set_tree_open, tree_inside, tree_open, tree_toggle};
use super::{Album, FolderNode, Icon, LibrarySource, LightcraftApp, Tokens, json, register, vec2};

/// A folder on disk with a disclosure triangle: click browses it, the triangle lists its
Expand All @@ -21,11 +21,12 @@ pub(super) fn folder_tree(
current: Option<&str>,
reveal: bool,
transient: bool,
above: Option<Said>,
) {
let open_id = egui::Id::unique(("folder-open", place.to_string(), path.to_string()));
let sel = current.is_some_and(|c| same_folder(c, path));
let on_the_way = !sel && current.is_some_and(|c| lightcraft_catalog::query::folder_within(c, path));
let mut open = tree_open(ui, open_id, false);
let mut open = tree_open(ui, open_id, false, above);
if reveal && on_the_way {
// opened once per browsed folder: collapsing it again afterwards sticks
let revealed_id = egui::Id::unique(("folder-revealed", place.to_string(), path.to_string()));
Expand All @@ -40,7 +41,7 @@ pub(super) fn folder_tree(
// at the tree's own indent, as in Albums and Folders: the triangle sits in the gutter and the
// icon lines up with the rows above
let resp = Row::new(&format!("local:{path}"), Icon::Folder, name).selected(sel).indent(indent).show(app, ui).on_hover_text(path);
let tr = tree_toggle(ui, &resp, indent, open_id, &mut open, format!("folderToggle:{path}"), name);
let tr = tree_toggle(ui, &resp, indent, open_id, &mut open, format!("folderToggle:{path}"), name, Inside::Folds);
if !tr.clicked()
&& resp.clicked()
&& let Err(e) = app.run("library.browse", json!({"path": path}))
Expand Down Expand Up @@ -96,8 +97,9 @@ pub(super) fn folder_tree(
});
}
if open && indent < INDENT_STEP * 8.0 {
let inside = tree_inside(ui, open_id, above);
for (n, p) in subfolders(ui, path).iter() {
folder_tree(app, ui, place, n, p, indent + INDENT_STEP, current, reveal, false);
folder_tree(app, ui, place, n, p, indent + INDENT_STEP, current, reveal, false, inside);
}
}
}
Expand Down Expand Up @@ -287,7 +289,7 @@ pub(super) fn reveal_chosen(app: &LightcraftApp, ui: &egui::Ui, tree: &[FolderNo
for n in nodes {
if lightcraft_catalog::query::folder_within(chosen, &n.path) && !same_folder(chosen, &n.path) {
let key = lightcraft_catalog::query::folder_key(&n.path);
ui.data_mut(|d| d.insert_temp(egui::Id::unique(("libfolder-open", key)), true));
set_tree_open(ui, egui::Id::unique(("libfolder-open", key)), true);
open_above(ui, &n.children, chosen);
}
}
Expand All @@ -305,22 +307,24 @@ pub(crate) fn folder_row_of<'a>(tree: &'a [FolderNode], dir: &str) -> Option<&'a
.find_map(|n| if same_folder(&n.path, dir) { Some(n) } else { folder_row_of(&n.children, dir) })
}

pub(super) fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode], indent: f32) {
/// The rows of the Folders tree. `above`: what holds for these rows from the rows above them
/// ([`tree_inside`]).
pub(super) fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode], indent: f32, above: Option<Said>) {
for n in nodes {
let key = lightcraft_catalog::query::folder_key(&n.path);
let open_id = egui::Id::unique(("libfolder-open", key.clone()));
// a disk starts open, and so does a folder that holds nothing itself and leads to one
// folder (`Users` → `me`): the first row where the library branches is what you look for
let leads_on = n.own == 0 && n.children.len() == 1;
let mut open = tree_open(ui, open_id, n.volume || leads_on);
let mut open = tree_open(ui, open_id, n.volume || leads_on, above);
// a row whose path would cover other disks' photos too only opens and closes
let name = if n.selectable { n.name.clone() } else { crate::i18n::tr("This Computer").to_string() };
let id = format!("libfolder:{}", n.path);
if !out_of_sight(app, ui, &id, &name, Some(n.count), indent, n.label.is_some()) {
folder_row(app, ui, n, &id, &name, indent, open_id, &mut open);
}
if open && !n.children.is_empty() {
folder_rows(app, ui, &n.children, indent + INDENT_STEP);
folder_rows(app, ui, &n.children, indent + INDENT_STEP, tree_inside(ui, open_id, above));
}
}
}
Expand All @@ -341,7 +345,7 @@ fn folder_row(app: &mut LightcraftApp, ui: &mut egui::Ui, n: &FolderNode, id: &s
folder_drop_target(app, ui, &resp, n, open_id, open);
let mut toggled = false;
if !n.children.is_empty() {
let tr = tree_toggle(ui, &resp, indent, open_id, open, format!("libraryFolderToggle:{}", n.path), name);
let tr = tree_toggle(ui, &resp, indent, open_id, open, format!("libraryFolderToggle:{}", n.path), name, Inside::OpensAndFolds);
toggled = tr.clicked();
// the triangle sits on the row and takes its clicks: the menu opens from it too
row_menu(app, &tr, n);
Expand Down
14 changes: 8 additions & 6 deletions crates/ui-egui/src/panels/left/keywords.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use super::dates::browse_all_photos;
use super::rows::{INDENT_STEP, Row, out_of_sight, tree_open, tree_toggle};
use super::rows::{INDENT_STEP, Inside, Row, Said, out_of_sight, tree_inside, tree_open, tree_toggle};
use super::{Icon, KeywordNode, LightcraftApp, json};

/// "Keywords": the library's keyword tree with photo counts (`a|b|c` keywords nest). A click
/// filters the grid by the keyword (children included), the triangle opens a level, and the
/// context menu renames, merges or deletes the keyword across the library.
pub(super) fn keyword_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[KeywordNode], indent: f32) {
pub(super) fn keyword_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[KeywordNode], indent: f32, above: Option<Said>) {
for n in nodes {
// leaves (most keywords) have no open state to look up
let open_id = (!n.children.is_empty()).then(|| egui::Id::unique(("kw-open", n.path.to_lowercase())));
let mut open = open_id.is_some_and(|k| tree_open(ui, k, false));
let mut open = open_id.is_some_and(|k| tree_open(ui, k, false, above));
let id = format!("keyword:{}", n.path);
if !out_of_sight(app, ui, &id, &n.name, Some(n.count), indent, false) {
keyword_row(app, ui, n, &id, indent, open_id, &mut open);
}
if open {
keyword_rows(app, ui, &n.children, indent + INDENT_STEP);
if let Some(k) = open_id.filter(|_| open) {
keyword_rows(app, ui, &n.children, indent + INDENT_STEP, tree_inside(ui, k, above));
}
}
}
Expand All @@ -25,7 +25,9 @@ fn keyword_row(app: &mut LightcraftApp, ui: &mut egui::Ui, n: &KeywordNode, id:
let sel = app.session.filter.keyword.as_deref().is_some_and(|k| k.eq_ignore_ascii_case(&n.path));
let resp = Row::new(id, Icon::Tag, &n.name).count(Some(n.count)).selected(sel).indent(indent).show(app, ui);
if let Some(k) = open_id {
tree_toggle(ui, &resp, indent, k, open, format!("keywordToggle:{}", n.path), &n.name);
// (no keyword inside it has keywords of its own: there is nothing inside it to say of)
let inside = if n.children.iter().any(|c| !c.children.is_empty()) { Inside::OpensAndFolds } else { Inside::Alone };
tree_toggle(ui, &resp, indent, k, open, format!("keywordToggle:{}", n.path), &n.name, inside);
}
let resp = resp.on_hover_text(if n.children.is_empty() { n.path.clone() } else { format!("{} (includes the keywords below it)", n.path) });
if resp.clicked() {
Expand Down
6 changes: 3 additions & 3 deletions crates/ui-egui/src/panels/left/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(super) fn local_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, now: &Local
for (i, (name, path)) in local.places.iter().enumerate() {
let transient = local.browse_root.as_deref() == Some(path.as_str());
let reveal = local.owner == Some(i);
folder_tree(app, ui, path, name, path, 0.0, current, reveal, transient);
folder_tree(app, ui, path, name, path, 0.0, current, reveal, transient, None);
}
if app.services.pick_folder.is_some() && Row::new("local:browse", Icon::Plus, crate::i18n::tr("Browse Folder…")).show(app, ui).clicked() {
let picked = app.services.pick_folder.as_mut().and_then(|f| f());
Expand Down Expand Up @@ -372,7 +372,7 @@ mod tests {
egui::ScrollArea::vertical().show(ui, |ui| {
for index in 0..500 {
let path = format!("/lightcraft-test/folder-{index:04}");
super::folder_tree(&mut app, ui, &path, &format!("Folder {index}"), &path, 0.0, None, false, false);
super::folder_tree(&mut app, ui, &path, &format!("Folder {index}"), &path, 0.0, None, false, false, None);
}
});
});
Expand Down Expand Up @@ -560,7 +560,7 @@ mod tests {
let raw = HeadlessView::raw_input(egui::vec2(300.0, 200.0), 1.0, frame as f64 / 60.0, vec![]);
view.run(raw, |ui| {
super::Row::new("all", super::Icon::Photos, "All Photos").show(&mut app, ui);
super::folder_tree(&mut app, ui, path, "Pictures", path, 0.0, None, false, false);
super::folder_tree(&mut app, ui, path, "Pictures", path, 0.0, None, false, false, None);
});
widgets = crate::widgets::take_registry(&view.ctx);
}
Expand Down
Loading
Loading