LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-BEHAV-SIDEBAR-REORDER: drag sidebar sections by their header, Move Up / Down, Recently Deleted joins My Photos
Nathaniel Ledford5ac3e556ace5
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex a8643db1e..73b11a2b7 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -316,10 +316,25 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequestok(Value::Null)}"ui.set" => {+ // an arrangement of the sidebar is checked, not made whole as a settings file's is+ let sidebar = match p.get("sidebar").map(crate::sidebar::SidebarLayout::parse).transpose() {+ Ok(s) => s,+ Err(e) => return err(e),+ };let mut v = serde_json::to_value(&app.ui).unwrap_or_default();lightcraft_develop::presets::deep_merge(&mut v, p);match serde_json::from_value::<crate::UiState>(v) {Ok(mut u) => {+ if let Some(sidebar) = sidebar {+ u.sidebar = sidebar;+ }+ // `collapsedSidebar`, as scripts from before `sidebar` set it: the folded sections+ if let Some(ids) = p.get("collapsedSidebar").and_then(Value::as_array) {+ for section in crate::sidebar::SidebarSection::ALL {+ u.sidebar.set_collapsed(section, ids.iter().any(|id| id.as_str() == Some(section.id())));+ }+ }+ u.collapsed_sidebar.clear();u.toast = app.ui.toast.clone();u.dialog = app.ui.dialog.clone();u.status = app.ui.status.clone();diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex cc7d13f15..7609d3939 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1072,6 +1072,7 @@ impl LightcraftApp {pick::poll(self, &ctx);panels::grid::drag_feedback(self, &ctx);panels::left::album_drag_feedback(self, &ctx);+ panels::left::section_drag_feedback(self, &ctx);panels::keyword_list::drag_feedback(self, &ctx);panels::toast(self, &ctx);self.widgets = widgets::take_registry(&ctx);diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 22c27b808..9d7231e0e 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -138,6 +138,7 @@ pub const UI_COMMANDS: &[UiCommand] = &[("dialog.smartAlbum", "New Smart Albumβ¦", None, "File"),("view.photoCounts", "Show Photo Counts", None, "View"),("view.sidebarSection", "Show Sidebar Section", None, ""),+ ("view.sidebarMoveSection", "Move Sidebar Section", None, ""),("view.sidebarReset", "Reset Sidebar Sections", None, ""),("view.slideshow", "Slideshow", Some("Cmd+Alt+Enter"), "View"),("view.secondWindow", "Second Window", Some("Cmd+F11"), "Window"),@@ -370,6 +371,33 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re}Ok(json!({"section": section.id(), "show": !layout.is_hidden(section), "collapsed": layout.is_collapsed(section)}))}+ "view.sidebarMoveSection" => {+ // {section, direction: up | down} one place among the shown sections, or+ // {section, before: <section> | null} just above another section (null: last)+ let section = match sidebar_section_param(id, p) {+ Ok(s) => s,+ Err(e) => return Some(Err(e)),+ };+ let layout = &mut app.ui.sidebar;+ let moved = match (p.get("direction"), p.get("before")) {+ (Some(d), None) => match d.as_str() {+ Some("up") => layout.move_by(section, true),+ Some("down") => layout.move_by(section, false),+ _ => return Some(Err(format!("{id}: `direction` must be \"up\" or \"down\", not {d}"))),+ },+ (None, Some(Value::Null)) => layout.move_before(section, None),+ (None, Some(b)) => {+ let before = b.as_str().and_then(crate::sidebar::SidebarSection::from_id);+ let Some(before) = before else {+ return Some(Err(format!("{id}: `before` must be a section ({}) or null, not {b}", crate::sidebar::SidebarSection::ids())));+ };+ layout.move_before(section, Some(before))+ }+ _ => return Some(Err(format!("{id}: give either `direction` (up|down) or `before` (a section, or null for last)"))),+ };+ let order: Vec<&str> = layout.sections().iter().map(|s| s.id.id()).collect();+ Ok(json!({"section": section.id(), "moved": moved, "order": order}))+ }"view.sidebarReset" => {// every section shown and open, in the usual orderapp.ui.sidebar = Default::default();diff --git a/crates/ui-egui/src/panels/left.rs b/crates/ui-egui/src/panels/left.rsindex 35e2ab9f3..0ae4afa78 100644--- a/crates/ui-egui/src/panels/left.rs+++ b/crates/ui-egui/src/panels/left.rs@@ -188,12 +188,109 @@ const SECTION_HEADER: f32 = 34.0;/// One sidebar section: the gap above it, its header, and (while it is open) the rows `body`/// draws. Every section goes through here, so they all fold, space and announce themselves alike.-fn section(app: &mut LightcraftApp, ui: &mut egui::Ui, section: SidebarSection, body: impl FnOnce(&mut LightcraftApp, &mut egui::Ui)) {+fn section(+ app: &mut LightcraftApp,+ ui: &mut egui::Ui,+ section: SidebarSection,+ body: impl FnOnce(&mut LightcraftApp, &mut egui::Ui),+) -> PlacedSection {ui.add_space(SECTION_GAP);let (header, _) = ui.allocate_exact_size(vec2(ui.available_width(), SECTION_HEADER), Sense::hover());if section_header(app, ui, section, header) {+ let rows_from = ui.cursor().top();body(app, ui);+ if ui.cursor().top() <= rows_from {+ empty_hint(ui, section);+ }+ }+ PlacedSection { section, top: header.top(), bottom: ui.cursor().top() }+}++/// What an open section with nothing to list says in place of its rows (widget+/// `sidebarEmpty:<id>`), so the section stays where it is instead of disappearing.+fn empty_hint(ui: &mut egui::Ui, section: SidebarSection) {+ let t = Tokens::get(ui.ctx());+ let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), 29.0), Sense::hover());+ register(ui.ctx(), format!("sidebarEmpty:{}", section.id()), r);+ let text = crate::i18n::tr(section.empty_hint());+ let galley = ui.painter().layout_no_wrap(text.to_string(), t.font(12.5), t.text_dim);+ note_width(ui, 42.0 + galley.size().x + 18.0);+ ui.painter().galley(pos2(r.left() + 42.0, r.center().y - galley.size().y / 2.0), galley, t.text_dim);+}++/// Where a section was laid out this frame (screen y): from its header's top to the end of its rows.+#[derive(Clone, Copy, Debug, PartialEq)]+pub(crate) struct PlacedSection {+ pub section: SidebarSection,+ pub top: f32,+ pub bottom: f32,+}++/// Where a section dragged to `y` would go among the sections drawn: above the first one whose+/// middle is below `y` (`Some`), or after them all (`None`).+pub(crate) fn section_drop_before(placed: &[PlacedSection], y: f32) -> Option<SidebarSection> {+ placed.iter().find(|p| y < (p.top + p.bottom) / 2.0).map(|p| p.section)+}++/// While a section is dragged by its header: a line shows where it would go, releasing over the+/// sidebar moves it there (`view.sidebarMoveSection`), releasing elsewhere or Esc leaves it.+fn section_drag(app: &mut LightcraftApp, ui: &mut egui::Ui, placed: &[PlacedSection]) {+ let Some(dragged) = app.ui.dragging_section else { return };+ let (released, pos, esc) = ui.input(|i| (i.pointer.primary_released(), i.pointer.latest_pos(), i.key_pressed(egui::Key::Escape)));+ if esc {+ app.ui.dragging_section = None;+ return;+ }+ let view = ui.clip_rect();+ let Some(pos) = pos.filter(|p| view.contains(*p)) else {+ if released {+ app.ui.dragging_section = None;+ }+ return;+ };+ let before = section_drop_before(placed, pos.y);+ if released {+ app.ui.dragging_section = None;+ let before = before.map_or(serde_json::Value::Null, |b| json!(b.id()));+ if let Err(e) = app.run("view.sidebarMoveSection", json!({"section": dragged.id(), "before": before})) {+ app.toast(ui.ctx(), e);+ }+ return;}+ // the line: in the gap above the section it would go before, or below the last one+ let y = match before {+ Some(b) => placed.iter().find(|p| p.section == b).map(|p| p.top - SECTION_GAP / 2.0),+ None => placed.last().map(|p| p.bottom + SECTION_GAP / 2.0),+ };+ if let Some(y) = y {+ let t = Tokens::get(ui.ctx());+ let visible_right: f32 = ui.data(|d| d.get_temp(egui::Id::new("left-visible-right"))).unwrap_or(view.right());+ let line = Rect::from_min_max(pos2(view.left() + 8.0, y - 1.0), pos2(visible_right.min(view.right()) - 8.0, y + 1.0));+ ui.painter().rect_filled(line, 1.0, t.accent);+ register(ui.ctx(), "sidebarSectionDrop", line);+ }+}++/// The dragged section's name follows the pointer; a drag that ended anywhere (also outside the+/// sidebar, or with the sidebar closed) is over.+pub fn section_drag_feedback(app: &mut LightcraftApp, ctx: &egui::Context) {+ let Some(section) = app.ui.dragging_section else { return };+ let (down, pos) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos()));+ if !down || !app.ui.left_panel {+ app.ui.dragging_section = None;+ return;+ }+ let Some(pos) = pos else { return };+ let t = Tokens::get(ctx);+ ctx.set_cursor_icon(egui::CursorIcon::Grabbing);+ egui::Area::new(egui::Id::new("drag-section")).order(egui::Order::Tooltip).interactable(false).fixed_pos(pos + vec2(14.0, 10.0)).show(+ ctx,+ |ui| {+ egui::Frame::NONE.fill(t.accent).corner_radius(10.0).inner_margin(egui::Margin::symmetric(9, 3)).show(ui, |ui| {+ ui.label(egui::RichText::new(crate::i18n::tr(section.title())).color(egui::Color32::WHITE).font(t.semibold(12.0)));+ });+ },+ );}/// A section's header in `r`: the bold title with a disclosure chevron after it; a click folds or@@ -204,11 +301,15 @@ fn section_header(app: &mut LightcraftApp, ui: &mut egui::Ui, section: SidebarSelet t = Tokens::get(ui.ctx());let id = section.id();let title = crate::i18n::tr(section.title());- let resp = ui.interact(r, ui.id().with(("sidebar-section", id)), Sense::click());+ let resp = ui.interact(r, ui.id().with(("sidebar-section", id)), Sense::click_and_drag());register(ui.ctx(), format!("sidebarSection:{id}"), r);if resp.clicked() {app.ui.sidebar.toggle_collapsed(section);}+ // dragged by its header, a section moves among the others (see `section_drag`)+ if resp.drag_started_by(egui::PointerButton::Primary) {+ app.ui.dragging_section = Some(section);+ }resp.context_menu(|ui| sections_menu(app, ui, Some(section)));let open = !app.ui.sidebar.is_collapsed(section);resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, true, open, title));@@ -234,6 +335,13 @@ fn sections_menu(app: &mut LightcraftApp, ui: &mut egui::Ui, on: Option<SidebarSif hide.clicked() {run = Some(("view.sidebarSection", json!({"section": section.id(), "show": false})));}+ for (up, label, widget) in [(true, "Move Up", "sidebarMenu:moveUp"), (false, "Move Down", "sidebarMenu:moveDown")] {+ let item = ui.add_enabled(app.ui.sidebar.can_move(section, up), egui::Button::new(crate::i18n::tr(label)));+ register(ui.ctx(), widget, item.rect);+ if item.clicked() {+ run = Some(("view.sidebarMoveSection", json!({"section": section.id(), "direction": if up { "up" } else { "down" }})));+ }+ }ui.separator();}for s in app.ui.sidebar.sections().iter().filter(|s| s.id.available()) {@@ -337,6 +445,9 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {{let _ = app.run("library.source", json!({"kind": "missing"}));}+ if row(app, ui, "recentlyDeleted", Icon::Trash, "Recently Deleted", Some(deleted), src == LibrarySource::RecentlyDeleted, 0.0).clicked() {+ let _ = app.run("library.source", json!({"kind": "recentlyDeleted"}));+ }// the album just made: the folders down to it open, once (also when the section is shut)let reveal = app.ui.reveal_album.take();if reveal.is_some() {@@ -346,8 +457,9 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {// Local keeps track of the folder being browsed whether or not it is drawnlet local = local_now(app, ui);let shown: Vec<SidebarSection> = app.ui.sidebar.shown().collect();+ let mut placed: Vec<PlacedSection> = Vec::with_capacity(shown.len());for s in shown {- match s {+ let at = match s {SidebarSection::Albums => section(app, ui, s, |app, ui| albums_rows(app, ui, reveal)),SidebarSection::Local => {let Some(local) = &local else { continue };@@ -356,9 +468,6 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {SidebarSection::ByDate => section(app, ui, s, date_rows),SidebarSection::Folders => {let tree = app.caches.folder_tree(&app.session.catalog);- if tree.is_empty() {- continue;- }section(app, ui, s, |app, ui| {reveal_chosen(app, ui, &tree);folder_rows(app, ui, &tree, 0.0);@@ -366,17 +475,14 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {}SidebarSection::Keywords => {let tree = app.caches.keyword_tree(&app.session.catalog);- if tree.is_empty() {- continue;- }section(app, ui, s, |app, ui| keyword_rows(app, ui, &tree, 0.0))}- }- }- ui.add_space(SECTION_GAP);- if row(app, ui, "recentlyDeleted", Icon::Trash, "Recently Deleted", Some(deleted), src == LibrarySource::RecentlyDeleted, 0.0).clicked() {- let _ = app.run("library.source", json!({"kind": "recentlyDeleted"}));+ };+ placed.push(at);}+ // room below the last section (a section dragged to the end is dropped here)+ ui.add_space(SECTION_GAP * 2.0);+ section_drag(app, ui, &placed);// what the rows asked for becomes next frame's widthlet next = ui.data(|d| d.get_temp::<f32>(egui::Id::new("left-content-width-next"))).unwrap_or(0.0);if (next - content_width(ui.ctx())).abs() > 0.5 {@@ -832,12 +938,15 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare}// what this frame draws; a click shows from the next onelet 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));+ toggled = tri.clicked();// the triangle sits on the row and takes its clicks: the menu opens from it toofolder_menu(app, &tri, a);}- if resp.clicked() {+ // one click, one toggle: the triangle's is not the row's as well+ if resp.clicked() && !toggled {set_tree_open(ui, open_id, !open);}folder_menu(app, &resp, a);@@ -912,7 +1021,7 @@ pub fn auto_scroll_speed(y: f32, top: f32, bottom: f32) -> f32 {/// pointer is near its top or bottom edge, so rows beyond the visible part can be reached. Call/// inside the scroll area.fn drag_auto_scroll(app: &LightcraftApp, ui: &egui::Ui) {- if app.ui.dragging_album.is_none() && app.ui.dragging_photos.is_none() {+ if app.ui.dragging_album.is_none() && app.ui.dragging_photos.is_none() && app.ui.dragging_section.is_none() {return;}let view = ui.clip_rect();@@ -1266,7 +1375,7 @@ fn is_within(app: &LightcraftApp, id: lightcraft_catalog::AlbumId, ancestor: ligfalse}-// "Folders": where on disk the library's photos were imported from, with photo counts (see+// "Folders" (drawn in `show`): where on disk the library's photos were imported from, with photo counts (see// `lightcraft_catalog::folders`). A click makes that folder the source, like an album or a Local// folder: its photos and those of the folders inside it fill the grid. The triangle opens a// level. Only folders holding imported photos are listed; every folder on disk is under Local.diff --git a/crates/ui-egui/src/sidebar.rs b/crates/ui-egui/src/sidebar.rsindex a5e80cdb9..4bc49fd61 100644--- a/crates/ui-egui/src/sidebar.rs+++ b/crates/ui-egui/src/sidebar.rs@@ -45,6 +45,17 @@ impl SidebarSection {}}+ /// What the section says while it has nothing to list, in English.+ pub const fn empty_hint(self) -> &'static str {+ match self {+ SidebarSection::Albums => "No albums yet",+ SidebarSection::Local => "No folders to browse",+ SidebarSection::ByDate => "No photos yet",+ SidebarSection::Folders => "No imported folders yet",+ SidebarSection::Keywords => "No keywords yet",+ }+ }+pub fn from_id(id: &str) -> Option<SidebarSection> {Self::ALL.into_iter().find(|s| s.id() == id)}@@ -109,6 +120,32 @@ impl From<serde_json::Value> for SidebarLayout {}impl SidebarLayout {+ /// The arrangement an agent or script asks for (`ui.set` `sidebar`), read strictly, unlike a+ /// settings file: a list whose entries are a section id or `{id, hidden?, collapsed?}`, each+ /// section at most once. Sections left out follow in the usual order, shown and open. What is+ /// wrong is said, so a typo doesn't quietly rearrange the sidebar.+ pub fn parse(asked: &serde_json::Value) -> Result<Self, String> {+ let entries = asked.as_array().ok_or_else(|| format!("`sidebar` must be a list of sections ({}), not {asked}", SidebarSection::ids()))?;+ let mut states: Vec<SectionState> = Vec::new();+ for entry in entries {+ let name = entry+ .as_str()+ .or_else(|| entry.get("id").and_then(serde_json::Value::as_str))+ .ok_or_else(|| format!("`sidebar`: {entry} names no section (an id, or {{id, hidden, collapsed}})"))?;+ let id = SidebarSection::from_id(name).ok_or_else(|| format!("`sidebar`: unknown section `{name}` ({})", SidebarSection::ids()))?;+ if states.iter().any(|s| s.id == id) {+ return Err(format!("`sidebar`: `{name}` is listed twice"));+ }+ let flag = |key: &str| match entry.get(key) {+ None | Some(serde_json::Value::Null) => Ok(false),+ Some(serde_json::Value::Bool(b)) => Ok(*b),+ Some(other) => Err(format!("`sidebar`: `{key}` of `{name}` must be true or false, not {other}")),+ };+ states.push(SectionState { id, hidden: flag("hidden")?, collapsed: flag("collapsed")? });+ }+ Ok(Self::from_states(states))+ }+/// The layout these states describe, made whole (see the type).fn from_states(states: impl IntoIterator<Item = SectionState>) -> Self {let mut all: Vec<SectionState> = Vec::with_capacity(SidebarSection::ALL.len());@@ -194,9 +231,11 @@ impl SidebarLayout {let Some(above) = at.checked_sub(1).and_then(|i| shown.get(i)) else { return false };self.move_before(section, Some(*above))} else {- let Some(below) = shown.get(at + 1) else { return false };+ if at + 1 >= shown.len() {+ return false;+ }// below the next one: above the one after it, or last- self.move_before(section, shown.get(at + 2).copied()) || self.move_before(*below, Some(section))+ self.move_before(section, shown.get(at + 2).copied())}}@@ -360,6 +399,29 @@ mod tests {assert!(layout.is_collapsed(ByDate) && layout.is_collapsed(Keywords) && !layout.is_collapsed(Albums));}+ /// Given an arrangement asked for by an agent, when it is right, then it is taken (sections it+ /// leaves out follow, shown and open); when anything in it is wrong, then it is refused with+ /// what is wrong, instead of being made whole as a settings file is.+ #[test]+ fn an_arrangement_that_is_asked_for_is_read_strictly() {+ let layout = SidebarLayout::parse(&json!(["keywords", {"id": "albums", "hidden": true, "collapsed": null}])).unwrap();+ assert_eq!(order(&layout), [Keywords, Albums, Local, ByDate, Folders]);+ assert!(layout.is_hidden(Albums) && !layout.is_collapsed(Albums));+ assert!(SidebarLayout::parse(&json!([])).unwrap().is_default());+ for (asked, says) in [+ (json!(null), "must be a list"),+ (json!({"albums": 1}), "must be a list"),+ (json!([{"id": "keywrods", "hidden": true}]), "unknown section `keywrods`"),+ (json!([7]), "names no section"),+ (json!(["albums", {"id": "albums"}]), "`albums` is listed twice"),+ (json!([{"id": "albums", "hidden": "yes"}]), "`hidden` of `albums` must be true or false"),+ (json!([{"id": "albums", "collapsed": 1}]), "`collapsed` of `albums` must be true or false"),+ ] {+ let e = SidebarLayout::parse(&asked).unwrap_err();+ assert!(e.contains(says), "{asked}: {e}");+ }+ }+#[test]fn sections_are_named_by_their_ids() {for s in SidebarSection::ALL {diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 966702356..01778290d 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -421,6 +421,9 @@ pub struct UiState {/// An album or folder row being dragged in the sidebar (dropped on a folder to move it there).#[serde(skip)]pub dragging_album: Option<u64>,+ /// A sidebar section being dragged by its header (dropped between sections to move it there).+ #[serde(skip)]+ pub dragging_section: Option<crate::sidebar::SidebarSection>,/// Selected curve channel in the Curve flyout.pub curve_channel: String,/// Selected mixer mode: "hue" | "saturation" | "luminance" | "all".@@ -846,6 +849,7 @@ impl Default for UiState {dragging_photos: None,reveal_album: None,dragging_album: None,+ dragging_section: None,curve_channel: "parametric".into(),mixer_mode: "hue".into(),grading_mode: "3way".into(),diff --git a/crates/ui-egui/src/tests_panels.rs b/crates/ui-egui/src/tests_panels.rsindex 4686412b9..a7cc59f00 100644--- a/crates/ui-egui/src/tests_panels.rs+++ b/crates/ui-egui/src/tests_panels.rs@@ -259,18 +259,21 @@ fn sections_drawn(h: &Headless) -> Vec<String> {#[test]fn the_sidebar_draws_its_sections_as_arranged() {let mut h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));- // (Local is not on every platform, and the demo library was imported from no folder)- let listed = |drawn: &[String]| drawn.iter().filter(|s| !matches!(s.as_str(), "local" | "folders")).cloned().collect::<Vec<_>>();+ // (Local is not on every platform)+ let listed = |drawn: &[String]| drawn.iter().filter(|s| s.as_str() != "local").cloned().collect::<Vec<_>>();let usual = sections_drawn(&h);- assert_eq!(listed(&usual), ["albums", "byDate", "keywords"], "{usual:?}");+ assert_eq!(listed(&usual), ["albums", "byDate", "folders", "keywords"], "{usual:?}");+ // the demo library was imported from no folder: Folders says so in place of rows+ assert!(has(&h, "sidebarEmpty:folders") && !has(&h, "sidebarEmpty:keywords"));let r = h.request("ui.set", json!({"sidebar": [{"id": "keywords"}, {"id": "byDate", "hidden": true}, {"id": "albums"}]}), T);assert_eq!(r["ok"], true, "{r}");h.settle(SETTLE);let drawn = sections_drawn(&h);- assert_eq!(listed(&drawn), ["keywords", "albums"], "{drawn:?}");+ assert_eq!(listed(&drawn), ["keywords", "albums", "folders"], "{drawn:?}");assert!(!h.app.widgets.iter().any(|(w, _)| w.starts_with("source:date:")), "a hidden section draws no rows");// every header sits the same gap below the last row above it- let mut rows: Vec<egui::Rect> = h.app.widgets.iter().filter(|(w, _)| w.starts_with("source:")).map(|(_, r)| *r).collect();+ let mut rows: Vec<egui::Rect> =+ h.app.widgets.iter().filter(|(w, _)| w.starts_with("source:") || w.starts_with("sidebarEmpty:")).map(|(_, r)| *r).collect();rows.sort_by(|a, b| a.top().total_cmp(&b.top()));for id in &drawn {let header = widget(&h, &format!("sidebarSection:{id}"));@@ -427,6 +430,242 @@ fn sidebar_commands_refuse_what_they_cannot_read() {assert!(h.app.ui.sidebar.is_default());}+/// Press on `from`, move to `to` over a few frames, and release there (after `before_release`).+fn drag_between(h: &mut Headless, from: egui::Pos2, to: egui::Pos2, before_release: Vec<egui::Event>) {+ let m = egui::Modifiers::NONE;+ h.app.synthetic.push(egui::Event::PointerMoved(from));+ h.app.synthetic.push(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: m });+ h.step();+ for i in 1..=8 {+ h.app.synthetic.push(egui::Event::PointerMoved(from + (to - from) * (i as f32 / 8.0)));+ h.step();+ }+ h.step();+ for e in before_release {+ h.app.synthetic.push(e);+ h.step();+ }+ h.app.synthetic.push(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: m });+ h.step();+ h.step();+ h.step();+}++fn header(h: &Headless, id: &str) -> egui::Rect {+ widget(h, &format!("sidebarSection:{id}"))+}++/// Given the sidebar, when a section's header is dragged above another section and released,+/// then the section is listed there, the others keeping their order; while it is dragged a line+/// shows where it would go; and the new order is part of the saved UI state.+#[test]+fn dragging_a_header_moves_its_section() {+ // folders too: photos imported from a folder+ let mut h = folders_app_sized(&["/pics/trip/a.jpg"], [1400.0, 1400.0]);+ let usual = sections_drawn(&h);+ let with_local = usual.contains(&"local".to_string());+ let listed = |ids: &[&str]| ids.iter().filter(|s| with_local || **s != "local").map(|s| s.to_string()).collect::<Vec<_>>();+ assert_eq!(usual, listed(&["albums", "local", "byDate", "folders", "keywords"]));+ assert!(has(&h, "sidebarEmpty:keywords"), "no keywords in this library: the section says so and stays");+ // Folders, dragged to just above Albums+ let (from, to) = (header(&h, "folders").center(), header(&h, "albums").center() - egui::vec2(0.0, 12.0));+ h.app.synthetic.push(egui::Event::PointerMoved(from));+ h.app.synthetic.push(egui::Event::PointerButton {+ pos: from,+ button: egui::PointerButton::Primary,+ pressed: true,+ modifiers: egui::Modifiers::NONE,+ });+ h.step();+ for i in 1..=8 {+ h.app.synthetic.push(egui::Event::PointerMoved(from + (to - from) * (i as f32 / 8.0)));+ h.step();+ }+ h.step();+ assert_eq!(h.app.ui.dragging_section, Some(crate::sidebar::SidebarSection::Folders));+ let line = widget(&h, "sidebarSectionDrop");+ assert!(+ line.center().y < header(&h, "albums").top() && line.center().y > header(&h, "albums").top() - 10.0,+ "the line is in the gap above Albums: {line:?}"+ );+ h.app.synthetic.push(egui::Event::PointerButton {+ pos: to,+ button: egui::PointerButton::Primary,+ pressed: false,+ modifiers: egui::Modifiers::NONE,+ });+ h.step();+ h.step();+ h.step();+ assert_eq!(h.app.ui.dragging_section, None);+ assert!(!has(&h, "sidebarSectionDrop"));+ assert_eq!(sections_drawn(&h), listed(&["folders", "albums", "local", "byDate", "keywords"]));+ // dragged below everything: last+ let end = egui::pos2(header(&h, "keywords").center().x, widget(&h, "panel:left_panel").bottom() - 20.0);+ let from = header(&h, "albums").center();+ drag_between(&mut h, from, end, Vec::new());+ assert_eq!(sections_drawn(&h), listed(&["folders", "local", "byDate", "keywords", "albums"]));+ // kept with the UI state+ let back = serde_json::from_value::<crate::UiState>(serde_json::to_value(&h.app.ui).unwrap()).unwrap().sanitized();+ assert_eq!(back.sidebar, h.app.ui.sidebar);+ // the header still folds its section with a click+ click(&mut h, "sidebarSection:folders");+ assert!(h.app.ui.sidebar_section_collapsed("folders"));+}++/// A drag that ends with Esc, or is released away from the sidebar, moves nothing.+#[test]+fn a_section_drag_that_is_given_up_moves_nothing() {+ let mut h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));+ let usual = sections_drawn(&h);+ let (from, to) = (header(&h, "keywords").center(), header(&h, "albums").center() - egui::vec2(0.0, 12.0));+ let esc = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };+ drag_between(&mut h, from, to, vec![esc]);+ assert_eq!((sections_drawn(&h), h.app.ui.dragging_section), (usual.clone(), None), "Esc");+ // released over the photos+ drag_between(&mut h, from, egui::pos2(800.0, to.y), Vec::new());+ assert_eq!((sections_drawn(&h), h.app.ui.dragging_section), (usual.clone(), None), "released outside");+ assert!(h.app.ui.sidebar.is_default());+}++/// An album dragged to the Albums header is not a section drag, and the other way round.+#[test]+fn dragging_a_section_is_not_dragging_an_album() {+ let mut h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));+ let (from, to) = (header(&h, "albums").center(), header(&h, "keywords").center() + egui::vec2(0.0, 4.0));+ let before = h.app.session.catalog.revision;+ h.app.synthetic.push(egui::Event::PointerMoved(from));+ h.app.synthetic.push(egui::Event::PointerButton {+ pos: from,+ button: egui::PointerButton::Primary,+ pressed: true,+ modifiers: egui::Modifiers::NONE,+ });+ h.step();+ h.app.synthetic.push(egui::Event::PointerMoved(from + (to - from) * 0.5));+ h.step();+ h.step();+ assert!(h.app.ui.dragging_section.is_some() && h.app.ui.dragging_album.is_none());+ h.app.synthetic.push(egui::Event::PointerButton {+ pos: to,+ button: egui::PointerButton::Primary,+ pressed: false,+ modifiers: egui::Modifiers::NONE,+ });+ h.step();+ h.step();+ assert_eq!(h.app.session.catalog.revision, before, "no album moved");+}++/// Given a section's header menu, Move Up and Move Down move it one shown section at a time+/// (stepping over hidden ones), and the command says when there is nowhere to go.+#[test]+fn a_section_moves_up_and_down_from_its_menu() {+ let mut h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));+ // (Local is not on every platform: taken out, so the same sections are there everywhere)+ exec(&mut h, "view.sidebarSection", json!({"section": "local", "show": false}));+ exec(&mut h, "view.sidebarSection", json!({"section": "folders", "show": false}));+ assert_eq!(sections_drawn(&h), ["albums", "byDate", "keywords"]);+ right_click(&mut h, "sidebarSection:keywords");+ click(&mut h, "sidebarMenu:moveUp");+ assert_eq!(sections_drawn(&h), ["albums", "keywords", "byDate"]);+ right_click(&mut h, "sidebarSection:albums");+ click(&mut h, "sidebarMenu:moveDown");+ assert_eq!(sections_drawn(&h), ["keywords", "albums", "byDate"], "one step, over the hidden sections");+ // the ends: nowhere to go+ let r = exec(&mut h, "view.sidebarMoveSection", json!({"section": "keywords", "direction": "up"}));+ assert_eq!(r["moved"], false, "{r}");+ let r = exec(&mut h, "view.sidebarMoveSection", json!({"section": "byDate", "direction": "down"}));+ assert_eq!(r["moved"], false, "{r}");+ // above a named section, or last+ let r = exec(&mut h, "view.sidebarMoveSection", json!({"section": "byDate", "before": "keywords"}));+ assert_eq!(r["moved"], true, "{r}");+ assert_eq!(sections_drawn(&h), ["byDate", "keywords", "albums"]);+ exec(&mut h, "view.sidebarMoveSection", json!({"section": "byDate", "before": null}));+ assert_eq!(sections_drawn(&h), ["keywords", "albums", "byDate"]);+ assert_eq!(h.app.ui.sidebar.sections().last().map(|s| s.id.id()), Some("byDate"));+ for (params, says) in [+ (json!({"section": "albums"}), "give either `direction`"),+ (json!({"section": "albums", "direction": "up", "before": null}), "give either `direction`"),+ (json!({"section": "albums", "direction": "left"}), "`direction` must be"),+ (json!({"section": "albums", "before": "map"}), "`before` must be a section"),+ (json!({"direction": "up"}), "`section` is needed"),+ ] {+ let r = h.request("engine.execute", json!({"command": "view.sidebarMoveSection", "params": params}), T);+ assert_eq!(r["ok"], false, "{params}: {r}");+ assert!(r.to_string().contains(says), "{params}: {r}");+ }+}++/// Recently Deleted is one of My Photos' rows: right below the others, above every section.+#[test]+fn recently_deleted_is_listed_with_my_photos() {+ let h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));+ let (picks, deleted) = (widget(&h, "source:picks"), widget(&h, "source:recentlyDeleted"));+ assert_eq!(deleted.top(), picks.bottom(), "no gap: the same group");+ let first = sections_drawn(&h).remove(0);+ assert_eq!(header(&h, &first).top() - deleted.bottom(), 10.0, "the sections start below it");+}++/// An arrangement set through the control channel is checked: a wrong one is refused and leaves+/// the sidebar as it was; the older `collapsedSidebar` list still folds and unfolds sections.+#[test]+fn an_arrangement_set_by_an_agent_is_checked() {+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid", "leftPanel": true}));+ exec(&mut h, "view.sidebarSection", json!({"section": "keywords", "show": false}));+ let arranged = h.app.ui.sidebar.clone();+ for bad in [json!(null), json!({"albums": 1}), json!([{"id": "keywrods", "hidden": true}]), json!(["albums", "albums"])] {+ let r = h.request("ui.set", json!({"sidebar": bad}), T);+ assert_eq!(r["ok"], false, "{bad}: {r}");+ assert_eq!(h.app.ui.sidebar, arranged, "{bad}");+ }+ let r = h.request("ui.set", json!({"collapsedSidebar": ["byDate"]}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(h.app.ui.sidebar_section_collapsed("byDate") && !h.app.ui.sidebar_section_collapsed("albums"));+ assert!(h.app.ui.sidebar.is_hidden(crate::sidebar::SidebarSection::Keywords), "the rest of the arrangement stays");+ let r = h.request("ui.set", json!({"collapsedSidebar": []}), T);+ assert_eq!(r["ok"], true, "{r}");+ assert!(!h.app.ui.sidebar_section_collapsed("byDate"));+}++/// Where a dragged section goes: above the first section whose middle is below the pointer.+#[test]+fn a_dragged_section_goes_above_the_section_it_is_over_the_top_half_of() {+ use crate::panels::left::{PlacedSection, section_drop_before};+ use crate::sidebar::SidebarSection::{Albums, ByDate, Keywords};+ let placed = [+ PlacedSection { section: Albums, top: 100.0, bottom: 300.0 },+ PlacedSection { section: ByDate, top: 310.0, bottom: 344.0 },+ PlacedSection { section: Keywords, top: 354.0, bottom: 500.0 },+ ];+ for (y, before) in [+ (0.0, Some(Albums)),+ (199.0, Some(Albums)),+ (201.0, Some(ByDate)),+ (326.0, Some(ByDate)),+ (328.0, Some(Keywords)),+ (430.0, None),+ (9e9, None),+ ] {+ assert_eq!(section_drop_before(&placed, y), before, "{y}");+ }+ assert_eq!(section_drop_before(&[], 10.0), None);+ assert_eq!(section_drop_before(&placed, f32::NAN), None);+}++/// By Date opens a year into its months with the triangle, and closes it again.+#[test]+fn a_year_opens_into_its_months() {+ let mut h = demo([1400.0, 1400.0], json!({"view": "photoGrid", "leftPanel": true}));+ let rows = |h: &Headless| h.app.widgets.iter().filter(|(w, _)| w.starts_with("source:date:")).count();+ let years = rows(&h);+ let toggle = h.app.widgets.iter().find(|(w, _)| w.starts_with("dateToggle:")).map(|(w, _)| w.clone()).expect("a year has a triangle");+ click(&mut h, &toggle);+ assert!(rows(&h) > years, "months are listed");+ click(&mut h, &toggle);+ assert_eq!(rows(&h), years, "closed again");+}+/// Albums nest in folders like the other sidebar trees: a folder row has a disclosure triangle/// (`albumToggle:<id>`), plain albums have none, and folding a folder hides what is inside it.#[test]@@ -1171,7 +1410,8 @@ fn removing_a_disk_from_the_library_asks_first() {#[test]fn a_deep_chain_keeps_its_nesting_and_the_sidebar_scrolls_sideways() {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")]);+ // (tall enough for the whole chain: Recently Deleted is above it now)+ let mut h = folders_app_sized(&[&format!("{deep}/x/1.jpg"), &format!("{deep}/y/2.jpg")], [1400.0, 1000.0]);let mut xs: Vec<f32> = Vec::new();let mut path = String::new();for name in deep.split('/').filter(|n| !n.is_empty()) {@@ -1266,7 +1506,8 @@ fn a_long_name_alone_does_not_make_the_sidebar_scroll() {#[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")]);+ // (tall enough for the whole chain: Recently Deleted is above it now)+ let mut h = folders_app_sized(&[&format!("{deep}/x/1.jpg"), &format!("{deep}/y/2.jpg")], [1400.0, 1000.0]);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");diff --git a/docs/parity.md b/docs/parity.mdindex 8bfbc7d7e..9394a27c7 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -44,13 +44,13 @@ and prints the summary; `cargo xtask parity --write` refreshes the summary table| U. Map & location (MAP) | 0 | 1 | 1 | 0 | β | 0/1 (0%) || V. Preferences (PREF) | 6 | 2 | 2 | 2 | 1/1 (100%) | 4/5 (80%) || W. Cloud & AI infrastructure (CLOUD / AI) | 1 | 0 | 1 | 2 | β | β |-| X. Cross-cutting behaviours (BEHAV) | 20 | 6 | 1 | 1 | 8/8 (100%) | 6/9 (67%) |+| X. Cross-cutting behaviours (BEHAV) | 21 | 6 | 1 | 1 | 8/8 (100%) | 6/9 (67%) || Y. Menus | 83 | 0 | 4 | 8 | 47/47 (100%) | 23/23 (100%) || Z. Keyboard shortcuts (desktop) | 75 | 3 | 3 | 1 | 49/52 (94%) | 23/24 (96%) || Lightroom Classic extras | 33 | 15 | 35 | 9 | β | 23/25 (92%) |-| **Total** | 400 | 49 | 73 | 36 | 192/200 (96%) | 143/155 (92%) |+| **Total** | 401 | 49 | 73 | 36 | 192/200 (96%) | 143/155 (92%) |-Weighted completion (β = 1, π‘ = Β½, π« left out): **81.3%** of 522 in-scope rows β P0 98.0% of 200 Β· P1 95.2% of 155 Β· P2 48.2% of 166.+Weighted completion (β = 1, π‘ = Β½, π« left out): **81.4%** of 523 in-scope rows β P0 98.0% of 200 Β· P1 95.2% of 155 Β· P2 48.5% of 167.<!-- /parity:summary -->## Top gaps@@ -526,8 +526,9 @@ under the UI command that wraps it (a no-op error); the UI command now wins.| LR-BEHAV-DRAGDROP | Drag and drop | P1 | β | `crates/ui-egui/src/lib.rs`, `crates/ui-egui/src/panels/grid.rs` (`drag_feedback`), `crates/ui-egui/src/panels/left.rs` (`drop_target`, `album_drag_over`, `top_level_drop_target`, `drag_auto_scroll`) | files β app (import); grid photos β an album row (adds the selection, with a count badge while dragging); sidebar album / folder rows β a folder (moves it; its name follows the pointer); a drag of albums or grid photos near the top or bottom edge of the sidebar scrolls it (faster nearer the edge, only while the pointer is over the sidebar) || LR-BEHAV-TOAST | Toast notifications | P1 | β | `crates/ui-egui/src/panels/mod.rs` | || LR-BEHAV-SIDEBAR-COLLAPSE | Collapsible left-sidebar sections | P2 | β | `crates/ui-egui/src/panels/left.rs` (`section`, `section_header`), `crates/ui-egui/src/sidebar.rs` (`SidebarLayout`), `crates/ui-egui/src/tests_panels.rs` | click the Albums, Local, By Date, Folders or Keywords header (or drive `ui.clickWidget` `sidebarSection:<albums\|local\|byDate\|folders\|keywords>`) to fold or unfold the section; a chevron after the title shows the state; the choice is kept across restarts (`sidebar` in the UI state; the `collapsedSidebar` list of older settings files is still read). UI-only (no command), like the By Date / Keywords disclosure triangles; photos dropped on a folded Albums section have no target |-| LR-BEHAV-SIDEBAR-SECTIONS | Left-sidebar sections share one frame and one arrangement | P2 | β | `crates/ui-egui/src/sidebar.rs` (`SidebarSection`, `SidebarLayout`), `crates/ui-egui/src/panels/left.rs` (`section`, `section_header`, `tree_toggle`), `crates/ui-egui/src/tests_panels.rs` | Albums, Local, By Date, Folders and Keywords are drawn by one `section` frame (the same gap above, header, fold and accessibility name) from one arrangement, `sidebar` in the UI state: a list of `{id, hidden, collapsed}` top to bottom, also settable with `ui.set`. Whatever is read, every section is in it exactly once (unknown and repeated entries are dropped, the rest follow in the usual order), so a damaged or newer settings file never loses the other settings. Rows that open (album folders, Local folders, dates, library folders, keywords) share `tree_toggle`: the same triangle, the same remembered open state, announced as Expand / Collapse. My Photos (All Photos, Recently Added, Picks, Missing Photos) is not a section: it stays on top |+| LR-BEHAV-SIDEBAR-SECTIONS | Left-sidebar sections share one frame and one arrangement | P2 | β | `crates/ui-egui/src/sidebar.rs` (`SidebarSection`, `SidebarLayout`), `crates/ui-egui/src/panels/left.rs` (`section`, `section_header`, `tree_toggle`), `crates/ui-egui/src/tests_panels.rs` | Albums, Local, By Date, Folders and Keywords are drawn by one `section` frame (the same gap above, header, fold and accessibility name) from one arrangement, `sidebar` in the UI state: a list of `{id, hidden, collapsed}` top to bottom, also settable with `ui.set`. Whatever is read, every section is in it exactly once (unknown and repeated entries are dropped, the rest follow in the usual order), so a damaged or newer settings file never loses the other settings. Rows that open (album folders, Local folders, dates, library folders, keywords) share `tree_toggle`: the same triangle, the same remembered open state, announced as Expand / Collapse. A section with nothing to list (Folders before anything is imported, Keywords before any is added) stays, open, with a one-line note in place of rows (`sidebarEmpty:<id>`) instead of disappearing. `ui.set` reads `sidebar` strictly (`SidebarLayout::parse`): an unknown or repeated section, or a flag that is not true / false, is refused and changes nothing; sections left out follow in the usual order, shown and open; the older `collapsedSidebar` list still folds and unfolds. My Photos (All Photos, Recently Added, Picks, Missing Photos, Recently Deleted) is not a section: it stays on top || LR-BEHAV-SIDEBAR-HIDE | Show and hide left-sidebar sections | P2 | β | `cmd:view.sidebarSection`, `cmd:view.sidebarReset`, `crates/ui-egui/src/sidebar.rs`, `crates/ui-egui/src/panels/left.rs` (`sections_menu`), `crates/ui-egui/src/menubar.rs`, `crates/ui-egui/src/tests_panels.rs` | View βΈ Sidebar Sections lists Albums, Local, By Date, Folders and Keywords in the sidebar's order, each checked while shown; unchecking one takes its header and rows off the sidebar, checking it puts it back where and how it was (still folded if it was). The same list opens with a right-click on any section header (with Hide This Section first; widgets `sidebarMenu:hide`, `sidebarMenu:section:<id>`, `sidebarMenu:reset`) and on the My Photos title (`sidebarTitle`), which is always there, so hidden sections can always come back. Reset Sidebar Sections (enabled once something changed) shows and opens every section in the usual order. `view.sidebarSection` `{section, show?, collapsed?}` flips shown / hidden when neither flag is given and refuses an unknown section or a flag that is not true / false. Hiding the section of what the grid shows (an album, a keyword filter) leaves the grid as it is; an album made while Albums is hidden or folded brings Albums back, open. Kept with the UI state (`sidebar`). My Photos itself can't be hidden |+| LR-BEHAV-SIDEBAR-REORDER | Reorder left-sidebar sections | P2 | β | `cmd:view.sidebarMoveSection`, `crates/ui-egui/src/sidebar.rs` (`move_before`, `move_by`), `crates/ui-egui/src/panels/left.rs` (`section_drag`, `section_drop_before`, `section_drag_feedback`), `crates/ui-egui/src/tests_panels.rs` | drag a section by its header: its name follows the pointer, a line (`sidebarSectionDrop`) shows the gap it would go to (above the section whose upper half the pointer is over, or below the last), releasing over the sidebar moves it there, Esc or releasing elsewhere leaves it; the sidebar scrolls when the drag nears its top or bottom edge. A click on the header still folds the section, and an album dragged onto the Albums header is still an album drag. The header's menu has Move Up / Move Down (`sidebarMenu:moveUp` / `moveDown`), one shown section at a time, stepping over hidden ones, disabled at the ends. `view.sidebarMoveSection` `{section, direction: up\|down}` or `{section, before: <section>\|null}` (null: last) answers `{moved, order}`. The order is kept with the UI state (`sidebar`). Recently Deleted is listed with My Photos (below Picks / Missing Photos), not after the sections. Not here: dragging My Photos, or rows from one section into another || LR-BEHAV-PANEL-RESIZE | Resizable side panels | P1 | β | `crates/ui-egui/src/panels/mod.rs` (`resizable_side`), `crates/ui-egui/src/state.rs` (`LEFT_WIDTH`, `RIGHT_WIDTH`), `crates/ui-egui/src/tests_panels.rs` | drag the left sidebar's right edge (200β480 pt) or the right panel's left edge (250β520 pt); the photo area keeps β₯ 360 pt; widths are kept across panels, views and restarts (`leftWidth` / `rightWidth` in the UI state); the Presets column stays fixed || LR-BEHAV-EMPTY-STATES | Empty states | P1 | β | `crates/ui-egui/src/panels/mod.rs` (`empty_message`) | || LR-BEHAV-TOOLTIPS | Tooltips with shortcuts | P0 | β | `crates/ui-egui/src/panels/bottombar.rs` | |