From 0ae61db3badf894ac97ea06897a2fe68abb70336 Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Mon, 12 Oct 2026 10:25:17 -0400 Subject: [PATCH 01/37] LR-PREF-GENERAL: the Settings window is one size on every tab, and nothing in it runs off the side General was 970 pt wide and the other tabs about 600, because a row of controls never wrapped and the widest row set the window's width; the window was also as tall as each tab's content, so it moved up and down between tabs and the tabs moved under the pointer. In a 900 pt wide app window the row labels and the Close button of General were off screen at the left, and a long library path made the window wider than the screen. - settings::window draws the tab bar, which stays put, above the page of the open tab, which scrolls: 560 pt wide and up to 640 pt tall whatever the page holds, less when the app window is smaller. Each page keeps a scroll position of its own, and one that goes on below shows its scroll handle without the pointer on it. It is still drawn in the scroll area every dialog has, which has nothing to scroll; in a window with under 120 pt for the page (far below the desktop minimum) that area scrolls tabs and page together, as before. - A row's controls wrap in the room beside the label, further lines starting under the first control, and a label longer than its column wraps in it (Forget unchanged photos pushed its choices 8 pt out of line). - Paths are one line, shortened from the front after either kind of separator, with all of the path in a tooltip only when it was cut: Library > Location, the folder Auto Import watches (it wrapped over several lines), the smart previews folder (it lost its end, and had two tooltips) and a monitor profile's file. row(), choices() and TABS keep their signatures, the match on the tab is where it was and the shared dialog code changes by one call, so the open pull requests that add tabs and rows still merge. Below 640 pt of app window a row holding a 240 pt field can still be wider than the page. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/panels/dialogs.rs | 4 +- crates/ui-egui/src/panels/settings.rs | 176 +++++++++-- crates/ui-egui/src/tests_dialog_settings.rs | 314 ++++++++++++++++++++ docs/whats-new.md | 11 + 5 files changed, 486 insertions(+), 21 deletions(-) create mode 100644 crates/ui-egui/src/tests_dialog_settings.rs diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 37fb86df31e..2280a14de3a 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -63,6 +63,8 @@ mod tests_date_picker; #[cfg(test)] mod tests_dialog_fit; #[cfg(test)] +mod tests_dialog_settings; +#[cfg(test)] mod tests_dialogs; #[cfg(test)] mod tests_error_kinds; diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index a79261fdc7f..913f0990bad 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -987,7 +987,9 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) { } Dialog::Merge { opts } => crate::merge::body(app, ui, opts), Dialog::Import { opts } => crate::import::body(app, ui, opts), - Dialog::Settings { tab } => crate::panels::settings::body(app, ui, tab), + // (Settings is never taller than `body_max`, so the scroll area round it never + // scrolls: its tab bar stays put and its pages scroll by themselves) + Dialog::Settings { tab } => crate::panels::settings::window(app, ui, tab, body_max), Dialog::SamModel { error, .. } => sam_model_body(app, ui, error.as_deref()), Dialog::KeywordTag { editing, diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs index a0717ccfd6a..754efaa5374 100644 --- a/crates/ui-egui/src/panels/settings.rs +++ b/crates/ui-egui/src/panels/settings.rs @@ -33,12 +33,41 @@ const CACHE_SIZES: [u32; 5] = [512, 1024, 2048, 4096, 8192]; const LABEL_W: f32 = 150.0; -/// The dialog body for `tab` (the tab bar switches `tab`). -pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String) { +/// The page of `tab` (the tab bar in [`window`] switches `tab`). +pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &str) { let t = Tokens::get(ui.ctx()); - ui.set_width((ui.ctx().content_rect().width() - 64.0).clamp(240.0, 560.0)); + match tab { + "import" => import_tab(app, ui, &t), + "performance" => performance_tab(app, ui, &t), + "display" => display_tab(app, ui, &t), + "interface" => interface_tab(app, ui, &t), + "faces" => super::faces::settings_tab(app, ui, &t), + "denoise" => super::denoise::settings_tab(app, ui, &t), + _ => general_tab(app, ui, &t), + } +} + +/// The widest the Settings window's content gets, and the tallest its pages get: the window is +/// one size on every tab, so it stays where it is as the tabs are gone through. +const PAGE_SIZE: egui::Vec2 = egui::vec2(560.0, 640.0); + +/// The least room in which a page scrolls by itself. In a window with less (far below the +/// desktop minimum), the tabs and the page scroll together in the dialog's own scroll area. +const PAGE_MIN_HEIGHT: f32 = 120.0; + +/// The Settings window's content: the tab bar, which stays put, above the page of `tab` +/// ([`body`]), which scrolls when it is taller than the room for it, with a scroll handle that +/// shows without the pointer on it. `max_height` is the room the app window leaves for both: the +/// two together never take more, so the scroll area every dialog is drawn in has nothing to +/// scroll (but for a window with less than [`PAGE_MIN_HEIGHT`] for the page, where that area +/// scrolls the two together). Every page gets the same room whatever it holds, and each keeps a +/// scroll position of its own. Nothing here is wider than the window from 640 pt of app window +/// up: a row's controls wrap ([`row`]) and paths are shortened ([`path_label`]). +pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_height: f32) { + ui.set_width((ui.ctx().content_rect().width() - 64.0).clamp(240.0, PAGE_SIZE.x)); + let top = ui.cursor().top(); ui.horizontal_wrapped(|ui| { - ui.spacing_mut().item_spacing.x = 4.0; + ui.spacing_mut().item_spacing = egui::vec2(4.0, 4.0); for (id, label) in TABS { if crate::widgets::text_button(ui, &format!("settingsTab-{id}"), label, tab == id).clicked() { *tab = id.to_string(); @@ -46,15 +75,64 @@ pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String) { } }); ui.separator(); - ui.add_space(2.0); - match tab.as_str() { - "import" => import_tab(app, ui, &t), - "performance" => performance_tab(app, ui, &t), - "display" => display_tab(app, ui, &t), - "interface" => interface_tab(app, ui, &t), - "faces" => super::faces::settings_tab(app, ui, &t), - "denoise" => super::denoise::settings_tab(app, ui, &t), - _ => general_tab(app, ui, &t), + // (a point less than the room left, so rounding never makes the dialog's own scroll area scroll) + let room = max_height - (ui.cursor().top() - top) - 1.0; + if room < PAGE_MIN_HEIGHT { + body(app, ui, tab.as_str()); + register(ui.ctx(), "settings:page", ui.min_rect()); + return; + } + let height = room.min(PAGE_SIZE.y); + // A page that goes on below shows its scroll handle all the time: without it, a page a line + // or two too long looks cut off, not scrollable. + ui.spacing_mut().scroll.dormant_handle_opacity = 0.6; + let page = egui::ScrollArea::vertical() + .id_salt(("settings-page", tab.as_str())) + .max_height(height) + .min_scrolled_height(height) + .auto_shrink([false, false]) + .show(ui, |ui| { + ui.add_space(2.0); + body(app, ui, tab.as_str()); + // (what the page took: wider than the room for it would mean a control is cut off) + register(ui.ctx(), "settings:page", ui.min_rect()); + }); + register(ui.ctx(), "settings:pageRoom", page.inner_rect); +} + +/// `path` shortened to fit `max` (as `width` measures it) by dropping leading folders, after +/// either kind of separator, so that its end stays (`…/Pictures/Library`, +/// `…\Pictures\Library`): the end says which folder it is. A last folder too long by itself +/// loses its end ([`crate::widgets::elide_head`]). +fn elide_path(path: &str, max: f32, width: impl Fn(&str) -> f32) -> String { + if width(path) <= max { + return path.to_string(); + } + // (a separator at the very end is not where a name starts: `…/` alone would say nothing) + let end = path.trim_end_matches(['/', '\\']).len(); + let mut rest = path; + while let Some(i) = rest.find(['/', '\\']).filter(|i| path.len() - rest.len() + i + 1 < end) { + let separator = if rest.get(i..).is_some_and(|r| r.starts_with('\\')) { '\\' } else { '/' }; + rest = rest.get(i + 1..).unwrap_or(""); + let shorter = format!("…{separator}{rest}"); + if width(&shorter) <= max { + return shorter; + } + } + let name = rest.trim_end_matches(['/', '\\']); + // (nothing but separators: never an empty label) + if name.is_empty() { "…".to_string() } else { crate::widgets::elide_head(name, max, width) } +} + +/// A folder or file path on one line in the room left in its row (`text:{id}`): shortened from +/// the front when it is too long ([`elide_path`]), with all of it in a tooltip then. +fn path_label(ui: &mut egui::Ui, id: &str, path: &str, font: egui::FontId, color: egui::Color32) { + let shown = elide_path(path, ui.available_width(), |s| ui.painter().layout_no_wrap(s.to_string(), font.clone(), color).size().x); + // (`truncate` is the last resort, for a room narrower than "…") + let r = ui.add(egui::Label::new(RichText::new(&shown).font(font).color(color)).truncate().show_tooltip_when_elided(false)); + register(ui.ctx(), format!("text:{id}"), r.rect); + if shown != path { + r.on_hover_text(path); } } @@ -67,9 +145,17 @@ fn row(ui: &mut egui::Ui, t: &Tokens, label: &str, add: impl FnOnce(&mut egui ui.horizontal(|ui| { ui.allocate_ui_with_layout(egui::vec2(LABEL_W, 24.0), egui::Layout::left_to_right(egui::Align::Center), |ui| { ui.set_min_width(LABEL_W); - ui.label(RichText::new(crate::i18n::tr(label)).color(t.text_label)); + // (a label longer than its column wraps in it; it does not push the controls along) + ui.add(egui::Label::new(RichText::new(crate::i18n::tr(label)).color(t.text_label)).wrap()); }); - add(ui) + // The controls wrap in the room beside the label, each further line starting under the + // first control, so a row with many choices grows down and never widens the window. + let wrapped = egui::Layout::left_to_right(egui::Align::Center).with_main_wrap(true); + ui.allocate_ui_with_layout(egui::vec2(ui.available_width(), 24.0), wrapped, |ui| { + ui.spacing_mut().item_spacing.y = 4.0; + add(ui) + }) + .inner }) .inner } @@ -112,7 +198,7 @@ fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { None => crate::i18n::tr("In memory — nothing is saved").to_string(), }; row(ui, t, crate::i18n::tr("Location"), |ui| { - ui.label(RichText::new(location).color(t.text)); + path_label(ui, "settingsLocation", &location, egui::TextStyle::Body.resolve(ui.style()), t.text); }); row(ui, t, "", |ui| { let can = app.services.pick_folder.is_some(); @@ -361,7 +447,10 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("Auto Import")); hint(ui, t, crate::i18n::tr("Photos that arrive in this folder (tethering, a scanner, a sync app) are added as soon as they're complete.")); row(ui, t, crate::i18n::tr("Watched folder"), |ui| { - ui.label(RichText::new(d.auto_folder.clone().unwrap_or_else(|| crate::i18n::tr("Off").into())).color(t.text)); + match &d.auto_folder { + Some(folder) => path_label(ui, "settingsAutoFolder", folder, egui::TextStyle::Body.resolve(ui.style()), t.text), + None => drop(ui.label(RichText::new(crate::i18n::tr("Off")).color(t.text))), + } let can = app.services.pick_folder.is_some(); let r = ui.add_enabled(can, egui::Button::new(crate::i18n::tr("Choose…"))); register(ui.ctx(), "button:settingsAutoFolder", r.rect); @@ -491,8 +580,10 @@ fn smart_previews(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { let available = loc["available"].as_bool().unwrap_or(true); let custom = loc["custom"].as_bool().unwrap_or(false); row(ui, t, crate::i18n::tr("Folder"), |ui| { - let text = format!("{path}{}", if custom { "" } else { " (library default)" }); - ui.add(egui::Label::new(RichText::new(text.clone()).color(if available { t.text } else { t.reject })).truncate()).on_hover_text(text); + path_label(ui, "settingsSmartFolder", &path, egui::TextStyle::Body.resolve(ui.style()), if available { t.text } else { t.reject }); + if !custom { + ui.label(RichText::new("(library default)").color(t.text)); + } }); let (count, bytes) = (loc["count"].as_u64().unwrap_or(0), loc["bytes"].as_u64().unwrap_or(0)); if available { @@ -608,7 +699,7 @@ fn display_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { let info = d.describe(); if !screen { row(ui, t, crate::i18n::tr("File"), |ui| { - ui.label(RichText::new(&d.path).size(11.0).color(t.text_dim)); + path_label(ui, "settingsDisplayFile", &d.path, egui::FontId::proportional(11.0), t.text_dim); }); } row(ui, t, crate::i18n::tr("Type"), |ui| { @@ -1182,3 +1273,48 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } } + +#[cfg(test)] +mod path_tests { + use super::elide_path; + + /// Width = characters, so a limit of 20 is "20 characters". + fn fit(path: &str, max: usize) -> String { + elide_path(path, max as f32, |s| s.chars().count() as f32) + } + + #[test] + fn a_path_that_fits_is_left_alone() { + assert_eq!(fit("/Users/me/Pictures", 18), "/Users/me/Pictures"); + assert_eq!(fit("", 5), ""); + } + + #[test] + fn leading_folders_go_first_and_the_end_stays() { + assert_eq!(fit("/Users/me/Pictures/Library", 20), "…/Pictures/Library"); + assert_eq!(fit("/Users/me/Pictures/Library", 10), "…/Library"); + } + + /// Windows paths: `Path::display` gives backslashes there. + #[test] + fn a_path_with_backslashes_keeps_its_end_too() { + assert_eq!(fit(r"C:\Users\me\Pictures\Library", 20), r"…\Pictures\Library"); + assert_eq!(fit(r"C:\Users\me/Pictures\Library", 10), r"…\Library"); + } + + #[test] + fn a_last_folder_too_long_by_itself_loses_its_end() { + assert_eq!(fit("/Users/me/a-very-long-folder-name", 8), "a-very-…"); + assert_eq!(fit("no-separator-at-all", 8), "no-sepa…"); + assert_eq!(fit("/Users/Фотографии-из-отпуска", 8), "Фотогра…"); + } + + #[test] + fn a_separator_at_the_end_is_not_where_the_name_starts() { + assert_eq!(fit("/Users/me/Pictures/Library/", 11), "…/Library/"); + assert_eq!(fit("/Users/me/a-very-long-folder-name/", 8), "a-very-…"); + assert_eq!(fit(r"C:\Users\me\Library\", 11), r"…\Library\"); + assert_eq!(fit("///", 2), "…"); + assert_eq!(fit(r"\\server\share\folder", 15), r"…\share\folder"); + } +} diff --git a/crates/ui-egui/src/tests_dialog_settings.rs b/crates/ui-egui/src/tests_dialog_settings.rs new file mode 100644 index 00000000000..b30770c1b17 --- /dev/null +++ b/crates/ui-egui/src/tests_dialog_settings.rs @@ -0,0 +1,314 @@ +//! The Settings window is one size in one place whatever tab is open, and lies inside the app +//! window: a row with more choices than fit wraps, a label longer than its column wraps, a long +//! folder path is cut short (its tooltip has all of it), and the tabs stay put while a page scrolls. +//! +//! Before, a wide row widened the whole window: General was 970 points wide and the other tabs +//! about 600, the window moved up and down between tabs, and in a 900 point wide app window the +//! row labels and the Close button of General were cut off at the left. + +use std::time::Duration; + +use serde_json::json; + +use crate::headless::Headless; +use crate::panels::settings::TABS; +use crate::{LightcraftApp, Services}; + +const T: Duration = Duration::from_secs(20); + +/// The app window sizes tried: roomy, the desktop minimum, and smaller than that. +const SIZES: [[f32; 2]; 3] = [[1600.0, 1000.0], [900.0, 560.0], [640.0, 480.0]]; + +fn headless(session: lightcraft_engine::Session, size: [f32; 2]) -> Headless { + let mut h = Headless::new(LightcraftApp::new(session, Services::default()), size, 1.0); + // let the first renders finish (a render still running at exit can crash in GPU teardown) + h.settle(T); + h +} + +fn demo(size: [f32; 2]) -> Headless { + headless(lightcraft_engine::Session::with_demo(), size) +} + +/// Given Settings open on `tab`, drawn until its layout has settled. +fn show(h: &mut Headless, tab: &str) { + let r = h.request("engine.execute", json!({"command": "app.settings", "params": {"tab": tab}}), T); + assert_eq!(r["ok"], true, "app.settings {tab}: {r}"); + h.settle(T); + for _ in 0..4 { + h.step(); + } +} + +/// A folder under the system's temporary one, removed again when the test ends, passed or not. +struct TempFolder(std::path::PathBuf); + +impl TempFolder { + fn new(tag: &str) -> Self { + let dir = std::env::temp_dir().join(format!("lc-ui-{tag}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + Self(dir) + } +} + +impl Drop for TempFolder { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } +} + +fn rect(h: &Headless, id: &str) -> egui::Rect { + h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r).unwrap_or_else(|| panic!("no widget {id}")) +} + +/// The controls the Settings window registers on the tab that is open (and its tab buttons). +fn controls(h: &Headless) -> Vec<(String, egui::Rect)> { + let named = |id: &str| id.split_once(':').is_some_and(|(_, name)| name.starts_with("settings") || name.starts_with("theme")); + h.app.widgets.iter().filter(|(id, _)| named(id)).cloned().collect() +} + +fn same(a: egui::Rect, b: egui::Rect) -> bool { + (a.min - b.min).abs().max_elem() < 0.5 && (a.max - b.max).abs().max_elem() < 0.5 +} + +#[test] +fn the_window_keeps_its_size_and_place_from_tab_to_tab() { + for size in SIZES { + let mut h = demo(size); + // Given the first tab, when every other tab is opened in turn + show(&mut h, "general"); + let first = rect(&h, "dialog:window"); + for (tab, _) in TABS { + show(&mut h, tab); + // Then the window has not moved or changed size + let now = rect(&h, "dialog:window"); + assert!(same(first, now), "{size:?}: Settings is {now:?} on {tab}, and was {first:?} on general"); + } + // And going back to the first tab finds it as it was + show(&mut h, "general"); + assert!(same(first, rect(&h, "dialog:window")), "{size:?}: general again"); + } +} + +#[test] +fn every_tab_keeps_its_controls_inside_the_window() { + for size in SIZES { + let mut h = demo(size); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, h.size); + for (tab, _) in TABS { + // When a tab is opened + show(&mut h, tab); + // Then the Settings window lies inside the app window + let window = rect(&h, "dialog:window"); + assert!(screen.contains_rect(window), "{size:?} {tab}: Settings {window:?} runs off the {screen:?} window"); + // And no control reaches past its left or right edge + // (the page is everything the tab drew, whether or not it has a name of its own; a + // control past the room for it would be clipped there, inside the window's margin) + let (page, room) = (rect(&h, "settings:page"), rect(&h, "settings:pageRoom")); + assert!( + page.left() >= room.left() - 0.5 && page.right() <= room.right() + 0.5, + "{size:?} {tab}: the page {page:?} is wider than the room for it {room:?}" + ); + assert!(window.contains_rect(room), "{size:?} {tab}: the page's room {room:?} is inside Settings {window:?}"); + for (id, r) in controls(&h) { + let within = if id.contains("settingsTab-") { window } else { room }; + assert!(r.left() >= within.left() - 0.5 && r.right() <= within.right() + 0.5, "{size:?} {tab}: {id} {r:?} is outside {within:?}"); + } + } + } +} + +#[test] +fn a_row_of_many_choices_wraps_under_itself() { + // Given an app window too narrow for the languages in one line + let mut h = demo([900.0, 560.0]); + show(&mut h, "general"); + let languages: Vec = (0..crate::i18n::Locale::ALL.len()).map(|i| rect(&h, &format!("button:settingsLanguage-{i}"))).collect(); + // Then they take more than one line + let first = languages[0]; + assert!(languages.iter().any(|r| r.top() > first.bottom()), "the languages wrap: {languages:?}"); + // And each further line starts under the first choice, not under the row's label + for r in languages.iter().filter(|r| r.top() > first.bottom()) { + assert!(r.left() >= first.left() - 0.5, "{r:?} starts left of the first language {first:?}"); + } + assert!( + languages.iter().filter(|r| r.top() > first.bottom()).any(|r| (r.left() - first.left()).abs() < 0.5), + "a wrapped line starts at the first choice" + ); +} + +#[test] +fn a_label_longer_than_its_column_leaves_the_controls_in_line() { + // Given Performance, whose "Forget unchanged photos" label is wider than the label column + let mut h = demo([1600.0, 1000.0]); + show(&mut h, "performance"); + // Then its choices start where the choices of a short label do + let (short, long) = (rect(&h, "button:settingsPreview-0"), rect(&h, "button:settingsForgetLocal-0")); + assert!((short.left() - long.left()).abs() < 0.5, "Preview size starts at {} and Forget unchanged photos at {}", short.left(), long.left()); +} + +#[test] +fn a_long_library_folder_is_cut_short_and_its_tooltip_has_all_of_it() { + // Given a library in a folder with a very long path + let base = TempFolder::new("settings-window"); + let dir = + base.0.join("photographs-from-2019-to-2026-kept-on-the-second-external-drive-that-nobody-wants-to-type-twice").join("the-master-library"); + std::fs::create_dir_all(&dir).unwrap(); + let mut session = lightcraft_engine::Session::new().with_fs(); + session.open_library(&dir, true).unwrap(); + let path = dir.display().to_string(); + + let mut h = headless(session, [1600.0, 1000.0]); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, h.size); + // When Settings opens on General, which shows where the library is + show(&mut h, "general"); + let general = rect(&h, "dialog:window"); + show(&mut h, "display"); + // Then the window is as wide as on a tab without a path + assert!(same(general, rect(&h, "dialog:window")), "General is {general:?} with a long path, Display is {:?}", rect(&h, "dialog:window")); + show(&mut h, "general"); + assert!(screen.contains_rect(general), "Settings {general:?} runs off the {screen:?} window"); + // And the path is cut short, inside the window + let location = rect(&h, "text:settingsLocation"); + let room = rect(&h, "settings:pageRoom"); + assert!(location.right() <= room.right() + 0.5, "the path {location:?} stays inside the room for the page {room:?}"); + let texts = h.painted_text(); + assert!(!texts.iter().any(|text| text.contains(&path)), "the whole path is not drawn in the row"); + // And what is left of it is its end, which says which library this is + let name = "the-master-library"; + assert!(path.ends_with(name)); + assert!( + texts.iter().any(|text| text.starts_with('…') && text.ends_with(name)), + "the row keeps the end of the path: {:?}", + texts.iter().filter(|t| t.contains("library")).collect::>() + ); + // And resting the pointer on it shows the whole path + assert_eq!(h.request("ui.hoverWidget", json!({"id": "text:settingsLocation"}), T)["ok"], true); + assert!(h.step_until(T, |h| h.painted_text().iter().any(|text| text.contains(&path))), "the tooltip has the whole path"); + + // And the same holds for the folder Auto Import watches, which stays on one line + let watched = h.app.run("library.autoImport", json!({"folder": path})); + assert!(watched.is_ok(), "{watched:?}"); + show(&mut h, "import"); + let (folder, room) = (rect(&h, "text:settingsAutoFolder"), rect(&h, "settings:pageRoom")); + assert!(folder.height() < 24.0 && folder.right() <= room.right(), "the watched folder {folder:?} is one line inside {room:?}"); + assert!(h.painted_text().iter().any(|text| text.starts_with('…') && text.ends_with(name)), "and keeps its end"); + drop(h); +} + +#[test] +fn a_short_path_is_shown_whole_and_has_no_tooltip() { + // Given the in-memory library, whose Location is a short sentence + let mut h = demo([1600.0, 1000.0]); + show(&mut h, "general"); + assert!(h.painted_text().iter().any(|text| text == "In memory — nothing is saved"), "it is all there"); + let before = h.painted_text().len(); + // When the pointer rests on it + assert_eq!(h.request("ui.hoverWidget", json!({"id": "text:settingsLocation"}), T)["ok"], true); + let _ = h.step_until(Duration::from_secs(2), |h| h.painted_text().len() > before); + // Then nothing more is drawn: there is nothing a tooltip could add + assert_eq!(h.painted_text().len(), before, "no tooltip for a path that is all there"); +} + +/// How many pixels of `rect` are not `colour` (one pixel per point here). +fn other_than(image: &egui::ColorImage, rect: egui::Rect, colour: egui::Color32) -> usize { + let [w, h] = image.size; + let (x0, x1) = (rect.left().round().max(0.0) as usize, (rect.right().round().max(0.0) as usize).min(w)); + let (y0, y1) = (rect.top().round().max(0.0) as usize, (rect.bottom().round().max(0.0) as usize).min(h)); + (y0..y1).flat_map(|y| (x0..x1).map(move |x| (x, y))).filter(|(x, y)| image.pixels[y * w + x] != colour).count() +} + +#[test] +fn a_page_that_goes_on_below_shows_a_scroll_handle_without_the_pointer_on_it() { + let mut h = demo([900.0, 560.0]); + let chrome = crate::theme::Tokens::get(&h.view.ctx).chrome; + // (the pointer is nowhere near the window) + h.request("ui.move", json!({"x": 5.0, "y": 5.0}), T); + let handle = |h: &Headless| { + let room = rect(h, "settings:pageRoom"); + other_than(&h.paint(), egui::Rect::from_min_max(egui::pos2(room.right() - 6.0, room.top()), room.max), chrome) + }; + // Given Import, which is taller than the room a 560 pt tall app window has for it + show(&mut h, "import"); + assert!(rect(&h, "settings:page").height() > rect(&h, "settings:pageRoom").height()); + // Then a handle is drawn at the page's right edge + assert!(handle(&h) > 40, "Import shows a scroll handle ({} px)", handle(&h)); + // And Display, which fits, has none + show(&mut h, "display"); + assert!(rect(&h, "settings:page").height() <= rect(&h, "settings:pageRoom").height()); + assert_eq!(handle(&h), 0, "Display has nothing to scroll"); +} + +#[test] +fn a_window_too_short_for_a_page_of_its_own_scrolls_tabs_and_page_together() { + // Given an app window far below the desktop minimum + let mut h = demo([900.0, 220.0]); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, h.size); + show(&mut h, "import"); + let window = rect(&h, "dialog:window"); + assert!(screen.contains_rect(window), "Settings {window:?} is inside the {screen:?} window"); + let (tab, page) = (rect(&h, "button:settingsTab-import"), rect(&h, "check:settings.perCamera")); + // When it is scrolled + h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); + for _ in 0..3 { + h.request("ui.scroll", json!({"dy": -120.0}), T); + h.step(); + } + h.settle(T); + // Then the tabs and the page move as one, so every setting can still be reached + let (tab_now, page_now) = (rect(&h, "button:settingsTab-import"), rect(&h, "check:settings.perCamera")); + assert!(page_now.top() < page.top() - 50.0, "the page scrolled: {page:?} -> {page_now:?}"); + assert!(((tab.top() - tab_now.top()) - (page.top() - page_now.top())).abs() < 0.5, "tabs and page moved together"); + assert!(same(window, rect(&h, "dialog:window")), "the window did not move"); +} + +#[test] +fn the_tabs_stay_put_while_a_page_scrolls() { + // Given a page taller than the window has room for + let mut h = demo([900.0, 560.0]); + show(&mut h, "import"); + let window = rect(&h, "dialog:window"); + let tabs: Vec = TABS.iter().map(|(id, _)| rect(&h, &format!("button:settingsTab-{id}"))).collect(); + let page_before = rect(&h, "check:settings.perCamera"); + // When the page is scrolled + h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); + for _ in 0..3 { + h.request("ui.scroll", json!({"dy": -120.0}), T); + h.step(); + } + h.settle(T); + // Then the page moved + let page_after = rect(&h, "check:settings.perCamera"); + assert!(page_after.top() < page_before.top() - 50.0, "the page scrolled: {page_before:?} -> {page_after:?}"); + // And the tabs and the window did not + for ((id, _), before) in TABS.iter().zip(tabs) { + assert!(same(before, rect(&h, &format!("button:settingsTab-{id}"))), "tab {id} moved"); + } + assert!(same(window, rect(&h, "dialog:window")), "the window moved"); +} + +#[test] +fn each_tab_remembers_how_far_it_was_scrolled() { + let mut h = demo([900.0, 560.0]); + show(&mut h, "interface"); + let fresh = rect(&h, "button:settingsAppearance-0"); + // Given Import scrolled down + show(&mut h, "import"); + let window = rect(&h, "dialog:window"); + let top = rect(&h, "check:settings.perCamera").top(); + h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); + for _ in 0..3 { + h.request("ui.scroll", json!({"dy": -120.0}), T); + h.step(); + } + h.settle(T); + let scrolled = rect(&h, "check:settings.perCamera").top(); + assert!(scrolled < top - 50.0); + // When another tab is opened, it starts at its top + show(&mut h, "interface"); + let mode = rect(&h, "button:settingsAppearance-0"); + assert!(same(fresh, mode), "Interface is at its top, as when first opened: {fresh:?} -> {mode:?}"); + // And Import is where it was left + show(&mut h, "import"); + assert!((rect(&h, "check:settings.perCamera").top() - scrolled).abs() < 0.5, "Import is where it was left"); +} diff --git a/docs/whats-new.md b/docs/whats-new.md index 1bf44c3f4ef..8c3c6ba43ea 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -238,6 +238,17 @@ scene) now develop from their sensor data with every editing tool, like the camera's other raws. Photos imported earlier switch over with Photo ▸ Reload from Disk. +### Settings window +- Settings is one size on every tab and stays where it is as you go through them; before, each tab made its own + size and the tabs moved under the pointer. The tabs stay in place while a long page scrolls, a page that goes on + below shows a scroll handle without the pointer on it, and each page remembers where it was scrolled to. +- Nothing in Settings runs off the side any more. A row with more choices than fit (the languages on General) wraps + onto further lines and a long label wraps in its column, where both used to widen the window: in a small + LightCraft window the labels and the Close button of General ended up off screen. +- A long folder (General ▸ Library ▸ Location, the folder Auto Import watches, the smart previews folder, a monitor + profile's file) is shortened to its last folders ("…/Pictures/Library") on one line; rest the pointer on it for + the whole path. + ### Switching libraries - File ▸ New Library… asks for a name, then where to put it, and opens the new library (issue #902). - File ▸ Open Recent Library lists the last 8 libraries; ones that are gone (moved, drive disconnected) are greyed From 12e4e1470e981f852f29f8d24f399fb1daae3c13 Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Mon, 12 Oct 2026 12:16:15 -0400 Subject: [PATCH 02/37] LR-PREF-GENERAL: the long-path test scrolls to the watched folder before reading it The row is at the foot of Import. With more sections above it (another pull request adds one) it is below the fold of the 640 pt page, and a row that is not drawn has no text to read: the test failed for the page's length, not for the path. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tests_dialog_settings.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/ui-egui/src/tests_dialog_settings.rs b/crates/ui-egui/src/tests_dialog_settings.rs index b30770c1b17..ed1ee4e93fa 100644 --- a/crates/ui-egui/src/tests_dialog_settings.rs +++ b/crates/ui-egui/src/tests_dialog_settings.rs @@ -190,7 +190,16 @@ fn a_long_library_folder_is_cut_short_and_its_tooltip_has_all_of_it() { let watched = h.app.run("library.autoImport", json!({"folder": path})); assert!(watched.is_ok(), "{watched:?}"); show(&mut h, "import"); + // (the row is at the foot of the page: scrolled to, so that it is drawn however long the page is) + let window = rect(&h, "dialog:window"); + h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); + for _ in 0..6 { + h.request("ui.scroll", json!({"dy": -400.0}), T); + h.step(); + } + h.settle(T); let (folder, room) = (rect(&h, "text:settingsAutoFolder"), rect(&h, "settings:pageRoom")); + assert!(room.intersects(folder), "the watched folder {folder:?} is in view in {room:?}"); assert!(folder.height() < 24.0 && folder.right() <= room.right(), "the watched folder {folder:?} is one line inside {room:?}"); assert!(h.painted_text().iter().any(|text| text.starts_with('…') && text.ends_with(name)), "and keeps its end"); drop(h); From b1d39a769d443f9e6feb7d6803ff1ab827a96742 Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Mon, 12 Oct 2026 10:40:14 -0400 Subject: [PATCH 03/37] LR-PREF-GENERAL: the Settings tabs look like tabs, and what is chosen or has the focus shows One widget drew the tab bar and every row of choices: on General the languages read as a second tab bar. What was chosen differed from what was not by its fill alone, 1.35 to 1.56:1 in the four themes, and a tab or choice reached with Tab showed nothing (the frame with and without the focus was the same, pixel for pixel). - widgets::tab_button: a tab is its name on the window, a size up from the headings inside a page, the open one in the text colour over a 2 pt line of that colour; no border, no fill. Each line of tabs stands on a 1 pt line the width of the window, so the open tab's line never hangs over the names below when the tabs take two lines (a narrow window, or Russian at full width). - widgets::choice_button, used by settings::choices: the chosen option keeps its fill and is outlined in the label colour (5.5:1 or more against its fill, a button and the window in every theme), and is a radio button to a screen reader. The Export dialog's own rows of choices are as they were. - Both, and text_button wherever it is used, show a ring while they have the keyboard focus: 2 pt in the text colour with a 1 pt line of the surface's colour inside it, within their rect. A double line, where a chosen option has a single thin one, so the two are told apart by shape. Tab, the arrow keys, Space and Return already worked. Widget ids are as they were (button:settingsTab-{id}, button:{id}-{index}). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/panels/settings.rs | 22 +- .../ui-egui/src/tests_dialog_settings_tabs.rs | 291 ++++++++++++++++++ crates/ui-egui/src/widgets.rs | 65 +++- docs/whats-new.md | 6 + 5 files changed, 380 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tests_dialog_settings_tabs.rs diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 2280a14de3a..80efdab03b8 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -65,6 +65,8 @@ mod tests_dialog_fit; #[cfg(test)] mod tests_dialog_settings; #[cfg(test)] +mod tests_dialog_settings_tabs; +#[cfg(test)] mod tests_dialogs; #[cfg(test)] mod tests_error_kinds; diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs index 754efaa5374..94bd8bbcf8a 100644 --- a/crates/ui-egui/src/panels/settings.rs +++ b/crates/ui-egui/src/panels/settings.rs @@ -66,15 +66,29 @@ const PAGE_MIN_HEIGHT: f32 = 120.0; pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_height: f32) { ui.set_width((ui.ctx().content_rect().width() - 64.0).clamp(240.0, PAGE_SIZE.x)); let top = ui.cursor().top(); + // Each line of tabs stands on a line of its own the width of the window, so the open tab's + // line always has the bar's under it: in a narrow window, or a language with long names, the + // tabs take two lines or more. + let mut lines: Vec = Vec::new(); ui.horizontal_wrapped(|ui| { - ui.spacing_mut().item_spacing = egui::vec2(4.0, 4.0); + ui.spacing_mut().item_spacing = egui::vec2(4.0, 5.0); for (id, label) in TABS { - if crate::widgets::text_button(ui, &format!("settingsTab-{id}"), label, tab == id).clicked() { + let r = crate::widgets::tab_button(ui, &format!("settingsTab-{id}"), label, tab == id); + let bottom = egui::emath::GuiRounding::round_to_pixels(r.rect.bottom(), ui.pixels_per_point()); + if !lines.iter().any(|line| (line - bottom).abs() < 0.5) { + lines.push(bottom); + } + if r.clicked() { *tab = id.to_string(); } } }); - ui.separator(); + let divider = Tokens::get(ui.ctx()).divider; + for bottom in lines { + let line = egui::Rect::from_min_max(egui::pos2(ui.min_rect().left(), bottom), egui::pos2(ui.min_rect().right(), bottom + 1.0)); + ui.painter().rect_filled(line, egui::CornerRadius::ZERO, divider); + } + ui.add_space(1.0); // (a point less than the room left, so rounding never makes the dialog's own scroll area scroll) let room = max_height - (ui.cursor().top() - top) - 1.0; if room < PAGE_MIN_HEIGHT { @@ -176,7 +190,7 @@ pub(super) fn choices(ui: &mut egui::Ui, id: &str, options: let mut changed = false; ui.spacing_mut().item_spacing.x = 4.0; for (i, (v, l)) in options.iter().enumerate() { - if crate::widgets::text_button(ui, &format!("{id}-{i}"), l, *value == *v).clicked() && *value != *v { + if crate::widgets::choice_button(ui, &format!("{id}-{i}"), l, *value == *v).clicked() && *value != *v { *value = *v; changed = true; } diff --git a/crates/ui-egui/src/tests_dialog_settings_tabs.rs b/crates/ui-egui/src/tests_dialog_settings_tabs.rs new file mode 100644 index 00000000000..e64c1964dc8 --- /dev/null +++ b/crates/ui-egui/src/tests_dialog_settings_tabs.rs @@ -0,0 +1,291 @@ +//! The Settings tabs look like tabs and not like the choices under them, the open tab and a chosen +//! option are marked by more than a slightly different fill, and a tab or choice reached with the +//! keyboard shows that it has the focus. +//! +//! Before, one widget drew both: on General the languages read as a second tab bar, what was +//! chosen stood 1.35 to 1.56:1 against what was not, and Tab moved a focus nobody could see (the +//! picture with and without it was the same, pixel for pixel). + +use std::time::Duration; + +use egui::Color32; +use serde_json::json; + +use crate::headless::Headless; +use crate::panels::settings::TABS; +use crate::theme::{ThemeKind, Tokens}; +use crate::{LightcraftApp, Services}; + +const T: Duration = Duration::from_secs(20); + +fn demo() -> Headless { + let mut h = Headless::new(LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services::default()), [1200.0, 900.0], 1.0); + // let the first renders finish (a render still running at exit can crash in GPU teardown) + h.settle(T); + h +} + +fn run(h: &mut Headless, command: &str, params: serde_json::Value) { + let r = h.request("engine.execute", json!({"command": command, "params": params}), T); + assert_eq!(r["ok"], true, "{command}: {r}"); + h.settle(T); + for _ in 0..4 { + h.step(); + } +} + +fn show(h: &mut Headless, tab: &str) { + run(h, "app.settings", json!({"tab": tab})); +} + +fn key(h: &mut Headless, key: &str) { + assert_eq!(h.request("ui.key", json!({"key": key}), T)["ok"], true, "{key}"); + for _ in 0..3 { + h.step(); + } +} + +fn rect(h: &Headless, id: &str) -> egui::Rect { + h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r).unwrap_or_else(|| panic!("no widget {id}")) +} + +fn tab(h: &Headless, id: &str) -> egui::Rect { + rect(h, &format!("button:settingsTab-{id}")) +} + +/// How many pixels of `rect` are `colour` (one pixel per point here). +fn count(image: &egui::ColorImage, rect: egui::Rect, colour: Color32) -> usize { + let [w, h] = image.size; + let (x0, x1) = (rect.left().round().max(0.0) as usize, (rect.right().round().max(0.0) as usize).min(w)); + let (y0, y1) = (rect.top().round().max(0.0) as usize, (rect.bottom().round().max(0.0) as usize).min(h)); + (y0..y1).flat_map(|y| (x0..x1).map(move |x| (x, y))).filter(|(x, y)| image.pixels[y * w + x] == colour).count() +} + +/// How many pixels of the focus ring's colour run round `rect`: along its top and its two sides +/// (not its bottom, where the open tab has its line in the same colour). +fn ring(image: &egui::ColorImage, rect: egui::Rect, colour: Color32) -> usize { + let [top, _, left, right] = edges(rect, 2.0); + [top, left, right].iter().map(|e| count(image, *e, colour)).sum() +} + +/// The outermost ring of `rect`, `width` points thick, as its four edges. +fn edges(rect: egui::Rect, width: f32) -> [egui::Rect; 4] { + [ + egui::Rect::from_min_max(rect.min, egui::pos2(rect.right(), rect.top() + width)), + egui::Rect::from_min_max(egui::pos2(rect.left(), rect.bottom() - width), rect.max), + egui::Rect::from_min_max(rect.min, egui::pos2(rect.left() + width, rect.bottom())), + egui::Rect::from_min_max(egui::pos2(rect.right() - width, rect.top()), rect.max), + ] +} + +/// WCAG contrast of two opaque colours. +fn contrast(a: Color32, b: Color32) -> f32 { + let lum = |c: Color32| { + let lin = |v: u8| { + let v = f32::from(v) / 255.0; + if v <= 0.04045 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) } + }; + 0.2126 * lin(c.r()) + 0.7152 * lin(c.g()) + 0.0722 * lin(c.b()) + }; + let (a, b) = (lum(a), lum(b)); + (a.max(b) + 0.05) / (a.min(b) + 0.05) +} + +#[test] +fn the_open_tab_is_underlined_and_the_others_are_not() { + for kind in ThemeKind::ALL { + let mut h = demo(); + run(&mut h, "view.theme", json!({"theme": kind.id()})); + let t = Tokens::for_kind(kind); + // Given Settings on Performance + show(&mut h, "performance"); + let image = h.paint(); + for (id, _) in TABS { + let r = tab(&h, id); + // Then a line in the text colour runs under the open tab's whole name, and under no other tab + let line = count(&image, egui::Rect::from_min_max(egui::pos2(r.left(), r.bottom() - 2.0), r.max), t.text); + if *id == "performance" { + assert!(line as f32 >= 2.0 * (r.width() - 2.0), "{kind:?}: the open tab {id} is underlined ({line} px of {r:?})"); + } else { + assert_eq!(line, 0, "{kind:?}: {id} is not open and has no line"); + } + } + // And that line stands out from the window whatever the theme (3:1 for a mark that is not text) + assert!(contrast(t.text, t.chrome) >= 3.0, "{kind:?}: {}", contrast(t.text, t.chrome)); + } +} + +#[test] +fn tabs_are_not_drawn_as_the_choices_under_them_are() { + let mut h = demo(); + let t = Tokens::get(&h.view.ctx); + // Given General, where a row of language choices sits right under the tabs + show(&mut h, "general"); + let image = h.paint(); + // Then a choice is a bordered button + let choice = rect(&h, "button:settingsLanguage-4"); + let border: usize = edges(choice, 1.0).iter().map(|e| count(&image, *e, t.button_border)).sum(); + assert!(border as f32 > choice.width(), "a choice has a border ({border} px)"); + // And a tab that is not open is its name alone on the window: no border, no fill of its own + let import = tab(&h, "import"); + let border: usize = edges(import, 1.0).iter().map(|e| count(&image, *e, t.button_border)).sum(); + assert_eq!(border, 0, "a tab has no border"); + assert_eq!(count(&image, import, t.button), 0, "a tab has no button fill"); + assert!(count(&image, import, t.chrome) as f32 > 0.6 * import.area(), "a tab is drawn on the window itself"); +} + +#[test] +fn a_tab_reached_with_the_keyboard_shows_the_focus() { + for kind in ThemeKind::ALL { + let mut h = demo(); + run(&mut h, "view.theme", json!({"theme": kind.id()})); + let t = Tokens::for_kind(kind); + show(&mut h, "general"); + let import = tab(&h, "import"); + let ring = |h: &Headless| ring(&h.paint(), import, t.text); + // Given no tab has the focus, there is no ring round Import + assert!(ring(&h) < 8, "{kind:?}: no ring before ({})", ring(&h)); + // When Tab is pressed twice (General, then Import) + key(&mut h, "Tab"); + key(&mut h, "Tab"); + // Then a ring in the text colour runs round Import + let length = import.width() + 2.0 * import.height(); + assert!(ring(&h) as f32 > 1.5 * length, "{kind:?}: Import shows the focus ({} px of ring along {length} pt)", ring(&h)); + // And it is still General that is open: the focus is not the choice + assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "general".into() })); + } +} + +#[test] +fn the_arrow_keys_move_along_the_tabs_and_space_opens_one() { + let mut h = demo(); + let t = Tokens::get(&h.view.ctx); + show(&mut h, "general"); + let ring = |h: &Headless, id: &str| ring(&h.paint(), tab(h, id), t.text); + // Given the focus on the first tab + key(&mut h, "Tab"); + assert!(ring(&h, "general") > 60, "General has the focus"); + // When → is pressed twice + key(&mut h, "ArrowRight"); + key(&mut h, "ArrowRight"); + // Then the focus is on the third tab, and nothing has opened yet + assert!(ring(&h, "performance") > 60, "Performance has the focus"); + assert!(ring(&h, "general") < 60 && ring(&h, "import") < 60, "and no other tab has"); + assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "general".into() })); + // And ← goes back one + key(&mut h, "ArrowLeft"); + assert!(ring(&h, "import") > 60, "Import has the focus"); + // When Space is pressed, that tab opens and keeps the focus + key(&mut h, "Space"); + assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "import".into() })); + assert!(ring(&h, "import") > 60, "Import still has the focus"); +} + +#[test] +fn a_chosen_option_has_an_outline_and_the_others_do_not() { + for kind in ThemeKind::ALL { + let mut h = demo(); + run(&mut h, "view.theme", json!({"theme": kind.id()})); + let t = Tokens::for_kind(kind); + // Given Performance, where Preview size is Automatic (the first choice) + show(&mut h, "performance"); + assert_eq!(h.app.ui.settings.preview_limit, 0); + let image = h.paint(); + let outline = |id: &str| edges(rect(&h, id), 1.0).iter().map(|e| count(&image, *e, t.text_label)).sum::(); + // Then the chosen one is outlined in the label colour, and one that is not chosen is not + let chosen = rect(&h, "button:settingsPreview-0"); + assert!( + outline("button:settingsPreview-0") as f32 > chosen.width() + chosen.height(), + "{kind:?}: the chosen size is outlined ({})", + outline("button:settingsPreview-0") + ); + assert!(outline("button:settingsPreview-1") < 8, "{kind:?}: another size is not ({})", outline("button:settingsPreview-1")); + // And an outline is not the focus ring: nothing in the ring's colour runs round the chosen one + assert!(ring(&image, chosen, t.text) < 8, "{kind:?}: chosen is not focused ({})", ring(&image, chosen, t.text)); + // And the outline stands out from the button it is on, from one that is not chosen and from the window + for (what, other) in [("its fill", t.pressed), ("a button", t.button), ("the window", t.chrome)] { + assert!(contrast(t.text_label, other) >= 3.0, "{kind:?}: the outline against {what} is {}", contrast(t.text_label, other)); + } + } +} + +#[test] +fn a_choice_reached_with_the_keyboard_shows_the_focus() { + let mut h = demo(); + let t = Tokens::get(&h.view.ctx); + show(&mut h, "performance"); + let ring = |h: &Headless, id: &str| ring(&h.paint(), rect(h, id), t.text); + assert!(ring(&h, "button:settingsPreview-1") < 8); + // When Tab is pressed until the second preview size has the focus (the tabs and the GPU checkbox come first) + let reached = (0..40).any(|_| { + key(&mut h, "Tab"); + ring(&h, "button:settingsPreview-1") > 60 + }); + // Then it shows a ring, and is not chosen by that + assert!(reached, "a choice shows the focus"); + assert_eq!(h.app.ui.settings.preview_limit, 0); + // And Space chooses it + key(&mut h, "Space"); + assert_eq!(h.app.ui.settings.preview_limit, crate::state::PREVIEW_LIMITS[1]); +} + +/// What a screen reader is told: a choice is a radio button that says whether it is the one +/// chosen, a tab a button that says whether it is the one open. +#[test] +fn choices_and_tabs_say_what_they_are_and_which_one_holds() { + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + ctx.enable_accesskit(); + let mut found = Vec::new(); + for _ in 0..3 { + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + let _ = crate::widgets::choice_button(ui, "size-0", "Automatic", true); + let _ = crate::widgets::choice_button(ui, "size-1", "1600 px", false); + let _ = crate::widgets::tab_button(ui, "tab-general", "General", true); + let _ = crate::widgets::tab_button(ui, "tab-import", "Import", false); + }); + out.textures_delta.clear(); + if let Some(update) = out.platform_output.accesskit_update.take() { + found = update + .nodes + .iter() + .map(|(_, n)| (format!("{:?}", n.role()), n.label().unwrap_or_default().to_string(), format!("{:?}", n.toggled()))) + .collect(); + } + } + let has = + |role: &str, label: &str, on: bool| found.iter().any(|(r, l, t)| r == role && l == label && t.contains(if on { "True" } else { "False" })); + assert!(has("RadioButton", "Automatic", true), "{found:?}"); + assert!(has("RadioButton", "1600 px", false), "{found:?}"); + assert!(has("Button", "General", true), "{found:?}"); + assert!(has("Button", "Import", false), "{found:?}"); +} + +#[test] +fn tabs_on_two_lines_each_stand_on_a_line_of_their_own() { + // Given an app window too narrow for the tabs in one line + let mut h = Headless::new(LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services::default()), [480.0, 640.0], 1.0); + h.settle(T); + let t = Tokens::get(&h.view.ctx); + show(&mut h, "general"); + let tabs: Vec = TABS.iter().map(|(id, _)| tab(&h, id)).collect(); + let first = tabs[0]; + let lower: Vec<&egui::Rect> = tabs.iter().filter(|r| r.top() >= first.bottom()).collect(); + assert!(!lower.is_empty(), "the tabs take more than one line: {tabs:?}"); + let image = h.paint(); + let window = rect(&h, "dialog:window"); + // Then a line the width of the window runs right under each line of tabs, the first too, + // where the open tab is: its own line does not hang in the air over the names below + for bottom in [first.bottom().round(), lower[0].bottom().round()] { + let strip = egui::Rect::from_min_max(egui::pos2(window.left(), bottom), egui::pos2(window.right(), bottom + 1.0)); + assert!( + count(&image, strip, t.divider) as f32 > 0.8 * (window.width() - 32.0), + "a line runs under the tabs at y = {bottom} ({} px)", + count(&image, strip, t.divider) + ); + } + // And the lower line of tabs starts clear of it + assert!(lower[0].top() >= first.bottom() + 4.0, "the second line of tabs {:?} is clear of the first {first:?}", lower[0]); + // And the page starts under the last of them + assert!(rect(&h, "settings:pageRoom").top() > lower[0].bottom(), "the page is under the tabs"); +} diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index a6af3dc7a87..509a2c2f4be 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -500,13 +500,26 @@ pub fn flyout_row(ui: &mut Ui, id: &str, title: &str, icon: Icon, open: bool) -> /// A small bordered text button (Auto, B&W, HDR…). pub fn text_button(ui: &mut Ui, id: &str, label: &str, active: bool) -> Response { + chip(ui, id, label, active, false) +} + +/// One of a row of choices of which exactly one holds (`button:{id}`), drawn as [`text_button`] +/// is, except that the one chosen is also outlined in the label colour: its fill alone stands +/// about 1.4:1 against the others, the outline 3:1 or more in every theme. A screen reader is +/// told it is a radio button. +pub fn choice_button(ui: &mut Ui, id: &str, label: &str, chosen: bool) -> Response { + chip(ui, id, label, chosen, true) +} + +fn chip(ui: &mut Ui, id: &str, label: &str, active: bool, choice: bool) -> Response { let label = if id.starts_with("labelSet-") { label } else { crate::i18n::tr(label) }; let t = Tokens::get(ui.ctx()); let font = t.semibold(11.5); let galley = ui.painter().layout_no_wrap(label.to_string(), font, t.text); let size = vec2((galley.size().x + 18.0).max(37.0), 24.0); let (r, resp) = ui.allocate_exact_size(size, Sense::click()); - resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, active, label)); + let kind = if choice { egui::WidgetType::RadioButton } else { egui::WidgetType::Button }; + resp.widget_info(|| egui::WidgetInfo::selected(kind, true, active, label)); register(ui.ctx(), format!("button:{id}"), r); let fill = if active { t.pressed @@ -515,9 +528,57 @@ pub fn text_button(ui: &mut Ui, id: &str, label: &str, active: bool) -> Response } else { t.button }; + let border = if active && choice { t.text_label } else { t.button_border }; let p = ui.painter(); - p.rect(r, CornerRadius::same(4), fill, Stroke::new(1.0, t.button_border), StrokeKind::Inside); + p.rect(r, CornerRadius::same(4), fill, Stroke::new(1.0, border), StrokeKind::Inside); p.galley(r.center() - galley.size() / 2.0, galley, t.text); + focus_ring(ui, &t, &resp, r); + resp +} + +/// The ring a button drawn here shows while it has the keyboard focus (Tab, the arrow keys): 2 pt +/// in the text colour with a 1 pt line of the surface's colour inside it, both within its rect so +/// that a neighbour or the edge of a scrolled list never cuts them. The inner line sets the ring +/// off from the button's fill, and makes it a double line: a chosen [`choice_button`] has a +/// single thin one, so "has the focus" and "is chosen" are told apart by shape, not thickness. +fn focus_ring(ui: &Ui, t: &Tokens, resp: &Response, r: Rect) { + if resp.has_focus() { + let p = ui.painter(); + p.rect_stroke(r, CornerRadius::same(4), Stroke::new(2.0, t.text), StrokeKind::Inside); + p.rect_stroke(r.shrink(2.0), CornerRadius::same(2), Stroke::new(1.0, t.chrome), StrokeKind::Inside); + } +} + +/// How tall a [`tab_button`] is. +const TAB_HEIGHT: f32 = 28.0; + +/// A tab of a tab bar (`button:{id}`): its name on the surface it is on, with no border and no +/// fill, so that it does not read as one of the buttons a page holds. The open tab's name is in +/// the text colour over a 2 pt line of that colour along its bottom edge (the bar's own line, when +/// the caller draws one there); the others are in the label colour. The names are a size up from +/// the headings inside a page, which are in the same face. To a screen reader a tab is a button +/// that says whether it is the one chosen (egui has no tab role to give it). +pub fn tab_button(ui: &mut Ui, id: &str, label: &str, open: bool) -> Response { + let label = crate::i18n::tr(label); + let t = Tokens::get(ui.ctx()); + let color = if open { t.text } else { t.text_label }; + let galley = ui.painter().layout_no_wrap(label.to_string(), t.semibold(13.5), color); + let size = vec2((galley.size().x + 20.0).max(37.0), TAB_HEIGHT); + let (r, resp) = ui.allocate_exact_size(size, Sense::click()); + resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, open, label)); + register(ui.ctx(), format!("button:{id}"), r); + let p = ui.painter(); + // (on whole pixels, so the line under the open tab is crisp at a whole-number scale) + let r = egui::emath::GuiRounding::round_to_pixels(r, p.pixels_per_point()); + if resp.hovered() && !open { + p.rect_filled(r.shrink2(vec2(0.0, 3.0)), CornerRadius::same(4), t.hover); + } + let color = if resp.hovered() { t.text } else { color }; + p.galley_with_override_text_color(r.center() - galley.size() / 2.0, galley, color); + if open { + p.rect_filled(Rect::from_min_max(pos2(r.left(), r.bottom() - 2.0), r.max), CornerRadius::ZERO, t.text); + } + focus_ring(ui, &t, &resp, r); resp } diff --git a/docs/whats-new.md b/docs/whats-new.md index 8c3c6ba43ea..c9a68ef2132 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -245,6 +245,12 @@ - Nothing in Settings runs off the side any more. A row with more choices than fit (the languages on General) wraps onto further lines and a long label wraps in its column, where both used to widen the window: in a small LightCraft window the labels and the Close button of General ended up off screen. +- The tabs of Settings look like tabs: names on the window with a line under the open one, no longer the same + buttons as the choices under them (on General the languages read as a second row of tabs). In Settings a chosen + option is outlined as well as filled, so it stands out in every theme. +- A tab or a choice reached with the keyboard shows a ring. Tab moves through them, ← and → along a row, and Space + or Return opens or chooses, as before: the focus was there all along but could not be seen. Text buttons + elsewhere in LightCraft show the same ring. Screen readers are told a choice in Settings is a radio button. - A long folder (General ▸ Library ▸ Location, the folder Auto Import watches, the smart previews folder, a monitor profile's file) is shortened to its last folders ("…/Pictures/Library") on one line; rest the pointer on it for the whole path. From 506451a183668b8a1492f5bb5b0426122af97308 Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Mon, 12 Oct 2026 11:40:35 -0400 Subject: [PATCH 04/37] LR-PREF-GENERAL: Settings asks before what cannot be taken back, and Esc in its text boxes gives the text back - Clear Cache and a model's Remove (Faces, AI Denoise) open a small panel under the button that says what the action costs, with the action and Keep (settings::ask_first; {id}:confirm, {id}:keep). Keep has the focus, so Return alone changes nothing; Esc or a click elsewhere answers no. They acted on one click: a cache that takes hours to make again in a large library, a model that is a 261 MB download. - Smart previews: "Delete them" was a choice made beforehand that a later press of Choose Folder or Use Library Folder carried out without a word. The change now waits, says how many smart previews would go and what they are for, and is made on Delete and Change Folder or dropped on Cancel. The choice and a waiting change are kept from one frame of the section to the next only, for the library and folder they were made in (SmartAsk): closing Settings, another tab, another library, or the folder changed some other way leaves nothing chosen or asked, and the choice goes back to "Move them" after any change. - The text boxes of Settings go through settings::field: Esc gives the text back and is used up by that, so Settings stays open. Copyright, Creator and the Auto Import album become the project's TextField; Esc there used to save what was typed (the box lost the focus) and close the window. - A tab clicked opens on the next frame, so the page being left is drawn once more and Copyright or Creator saves what was typed; it was dropped. - The album box keeps its text per library (one library's album name could be written into another's). - Automatically write changes into XMP sidecars has a line saying what is written where. The lines that run the commands (let _ = app.run(..)) and the ones next to them are as they were: #1153's sweep of those lines still applies. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/panels/denoise.rs | 7 + crates/ui-egui/src/panels/faces.rs | 7 + crates/ui-egui/src/panels/settings.rs | 198 +++++++- .../src/tests_dialog_settings_trust.rs | 455 ++++++++++++++++++ docs/whats-new.md | 12 + 6 files changed, 657 insertions(+), 24 deletions(-) create mode 100644 crates/ui-egui/src/tests_dialog_settings_trust.rs diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 80efdab03b8..214b0eae56a 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -67,6 +67,8 @@ mod tests_dialog_settings; #[cfg(test)] mod tests_dialog_settings_tabs; #[cfg(test)] +mod tests_dialog_settings_trust; +#[cfg(test)] mod tests_dialogs; #[cfg(test)] mod tests_error_kinds; diff --git a/crates/ui-egui/src/panels/denoise.rs b/crates/ui-egui/src/panels/denoise.rs index 75488f76b04..0121fc078bf 100644 --- a/crates/ui-egui/src/panels/denoise.rs +++ b/crates/ui-egui/src/panels/denoise.rs @@ -461,6 +461,13 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value, if installed { let r = ui.button(tr("Remove")); register(ui.ctx(), format!("denoise:remove:{id}"), r.rect); + let r = super::settings::ask_first( + t, + &format!("denoise:remove:{id}"), + r, + "The model's file is deleted. To use it again you download or add it again.", + "Remove", + ); if r.clicked() { let _ = app.run("denoise.models.remove", json!({"id": id})); app.caches.denoise.epoch += 1; diff --git a/crates/ui-egui/src/panels/faces.rs b/crates/ui-egui/src/panels/faces.rs index 2b3fe0329af..bde7131d9c2 100644 --- a/crates/ui-egui/src/panels/faces.rs +++ b/crates/ui-egui/src/panels/faces.rs @@ -342,6 +342,13 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value, if installed { let r = ui.button("Remove"); register(ui.ctx(), format!("faces:remove:{id}"), r.rect); + let r = super::settings::ask_first( + t, + &format!("faces:remove:{id}"), + r, + "The model's file is deleted. To use it again you download or add it again.", + "Remove", + ); if r.clicked() { let _ = app.run("faces.models.remove", json!({"id": id})); app.caches.faces_epoch += 1; diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs index 94bd8bbcf8a..8e171888edb 100644 --- a/crates/ui-egui/src/panels/settings.rs +++ b/crates/ui-egui/src/panels/settings.rs @@ -65,6 +65,10 @@ const PAGE_MIN_HEIGHT: f32 = 120.0; /// up: a row's controls wrap ([`row`]) and paths are shortened ([`path_label`]). pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_height: f32) { ui.set_width((ui.ctx().content_rect().width() - 64.0).clamp(240.0, PAGE_SIZE.x)); + // The page drawn is the one that was open when the frame began: a tab clicked now opens on + // the next frame, so a text box on the page being left is drawn once more and saves what was + // typed in it (the click took the focus from it). + let shown = tab.clone(); let top = ui.cursor().top(); // Each line of tabs stands on a line of its own the width of the window, so the open tab's // line always has the bar's under it: in a narrow window, or a language with long names, the @@ -73,13 +77,14 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_ ui.horizontal_wrapped(|ui| { ui.spacing_mut().item_spacing = egui::vec2(4.0, 5.0); for (id, label) in TABS { - let r = crate::widgets::tab_button(ui, &format!("settingsTab-{id}"), label, tab == id); + let r = crate::widgets::tab_button(ui, &format!("settingsTab-{id}"), label, shown == *id); let bottom = egui::emath::GuiRounding::round_to_pixels(r.rect.bottom(), ui.pixels_per_point()); if !lines.iter().any(|line| (line - bottom).abs() < 0.5) { lines.push(bottom); } if r.clicked() { *tab = id.to_string(); + ui.ctx().request_repaint(); } } }); @@ -92,7 +97,7 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_ // (a point less than the room left, so rounding never makes the dialog's own scroll area scroll) let room = max_height - (ui.cursor().top() - top) - 1.0; if room < PAGE_MIN_HEIGHT { - body(app, ui, tab.as_str()); + body(app, ui, shown.as_str()); register(ui.ctx(), "settings:page", ui.min_rect()); return; } @@ -101,13 +106,13 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_ // or two too long looks cut off, not scrollable. ui.spacing_mut().scroll.dormant_handle_opacity = 0.6; let page = egui::ScrollArea::vertical() - .id_salt(("settings-page", tab.as_str())) + .id_salt(("settings-page", shown.as_str())) .max_height(height) .min_scrolled_height(height) .auto_shrink([false, false]) .show(ui, |ui| { ui.add_space(2.0); - body(app, ui, tab.as_str()); + body(app, ui, shown.as_str()); // (what the page took: wider than the room for it would mean a control is cut off) register(ui.ctx(), "settings:page", ui.min_rect()); }); @@ -150,6 +155,76 @@ fn path_label(ui: &mut egui::Ui, id: &str, path: &str, font: egui::FontId, color } } +/// What the Smart previews section ([`smart_previews`]) keeps between frames: what is chosen for the previews already +/// built (0 move, 1 leave, 2 delete) and a change of folder that waits for a yes because it would +/// delete them, with the frame, library and folder they were chosen and asked in. +#[cfg(not(target_arch = "wasm32"))] +#[derive(Clone, Default)] +struct SmartAsk { + pass: u64, + library: String, + folder: String, + mode: u8, + waiting: Option, +} + +/// A text box of the Settings window, shown: Esc in it gives its text back and is used up by +/// that, so Settings stays open (a second Esc, with nothing being edited, closes it). +fn field(ui: &mut egui::Ui, field: crate::text_field::TextField<'_>) -> egui::Response { + let shown = field.show(ui); + if shown.cancelled() { + crate::widgets::take_escape(ui.ctx()); + } + shown.response +} + +/// What [`ask_first`] makes of a button: [`Asked::clicked`] once the person has said yes. +pub(super) struct Asked { + yes: bool, +} + +impl Asked { + /// The person pressed the button and then said yes to its question. + pub(super) fn clicked(&self) -> bool { + self.yes + } +} + +/// A button whose action cannot be taken back, or takes long to make good again, asks before it +/// acts. Pressing `button` (registered by the caller as `id`) opens a small panel under it with +/// `question`, which says what the action costs, and two buttons: `yes` (`{id}:confirm`) and +/// Keep (`{id}:keep`), which has the focus when the panel opens. A click elsewhere or Esc answers no. What comes back stands in for the +/// button: its `clicked` is true on the frame the answer was yes. +pub(super) fn ask_first(t: &Tokens, id: &str, button: egui::Response, question: &str, yes: &str) -> Asked { + let mut answer = false; + let opened = button.clicked(); + egui::Popup::from_toggle_button_response(&button).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + ui.set_max_width(280.0); + ui.add(egui::Label::new(RichText::new(crate::i18n::tr(question)).color(t.text_label)).wrap()); + ui.horizontal(|ui| { + let r = ui.button(crate::i18n::tr(yes)); + register(ui.ctx(), format!("{id}:confirm"), r.rect); + if r.clicked() { + answer = true; + ui.close(); + button.request_focus(); + } + let r = ui.button(crate::i18n::tr("Keep")); + register(ui.ctx(), format!("{id}:keep"), r.rect); + // (the question opens with the focus on Keep, so Return or Space alone changes nothing) + if opened { + r.request_focus(); + } + // (answered from the keyboard, the focus goes back to the button the question was about) + if r.clicked() { + ui.close(); + button.request_focus(); + } + }); + }); + Asked { yes: answer } +} + pub(super) fn heading(ui: &mut egui::Ui, t: &Tokens, text: &str) { ui.add_space(4.0); ui.label(RichText::new(crate::i18n::tr(text)).font(t.semibold(12.5)).color(t.text)); @@ -244,10 +319,12 @@ fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { check(ui, "settings.confirmDelete", &mut app.ui.settings.confirm_delete, "Confirm before moving photos to Recently Deleted"); heading(ui, t, crate::i18n::tr("External Editing")); row(ui, t, crate::i18n::tr("PhotoCraft"), |ui| { - crate::text_field::TextField::singleline("field:photocraftPath", &mut app.ui.settings.photocraft_path) - .hint(crate::i18n::tr("Found automatically")) - .width(220.0) - .show(ui); + field( + ui, + crate::text_field::TextField::singleline("field:photocraftPath", &mut app.ui.settings.photocraft_path) + .hint(crate::i18n::tr("Found automatically")) + .width(220.0), + ); }); edit_file_rows(ui, t, "photocraftFile", &mut app.ui.settings.photocraft_file); hint( @@ -258,10 +335,12 @@ fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { ), ); row(ui, t, crate::i18n::tr("Other editor"), |ui| { - crate::text_field::TextField::singleline("field:externalEditor", &mut app.ui.settings.external_editor) - .hint(crate::i18n::tr("System default")) - .width(220.0) - .show(ui); + field( + ui, + crate::text_field::TextField::singleline("field:externalEditor", &mut app.ui.settings.external_editor) + .hint(crate::i18n::tr("System default")) + .width(220.0), + ); }); edit_file_rows(ui, t, "externalFile", &mut app.ui.settings.external_file); hint(ui, t, crate::i18n::tr("Edit in Other Editor (⌥⌘E) opens the copy in this application (an app name on macOS, a program path elsewhere).")); @@ -409,7 +488,10 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { row(ui, t, label, |ui| { let id = egui::Id::new(("settingsMeta", key)); let mut text: String = ui.data(|m| m.get_temp(id)).unwrap_or(value.clone()); - let r = ui.add(egui::TextEdit::singleline(&mut text).hint_text(hint_text).desired_width(240.0)); + // (the project's text field: Esc gives the text back and stays in Settings, and with + // the text back the line below has nothing to save) + let widget = format!("field:settings.{key}"); + let r = field(ui, crate::text_field::TextField::singleline(&widget, &mut text).hint(hint_text).width(240.0)); register(ui.ctx(), format!("field:settings.{key}"), r.rect); if r.lost_focus() && text.trim() != value { let _ = app.run("library.preferences", json!({"import": {key: text.trim()}})); @@ -449,6 +531,11 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { if check(ui, "settings.autoWriteXmp", &mut xmp.auto_write, "Automatically write changes into XMP sidecars") { let _ = app.run("library.xmpPreferences", json!({"autoWrite": xmp.auto_write})); } + hint( + ui, + t, + "On, every change to a photo's edits or metadata is written to an XMP file beside the photo, for other apps to read. Off, that happens when you choose Save Metadata to File in the Photo menu.", + ); row(ui, t, crate::i18n::tr("Sidecar names"), |ui| { use lightcraft_engine::sidecar::SidecarNaming as N; let mut n = xmp.naming; @@ -486,9 +573,13 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { } }); row(ui, t, crate::i18n::tr("Album"), |ui| { - let id = egui::Id::new("auto-album"); + // (per library: a name left here by one library is not another's) + let id = egui::Id::new(("auto-album", app.session.library.as_ref().map(|l| l.dir.clone()))); let mut name = ui.data(|m| m.get_temp::(id)).unwrap_or_else(|| d.auto_album.clone().unwrap_or_default()); - let r = ui.add(egui::TextEdit::singleline(&mut name).hint_text(crate::i18n::tr("None")).desired_width(180.0)); + let r = field( + ui, + crate::text_field::TextField::singleline("field:settingsAutoAlbum", &mut name).hint(crate::i18n::tr("None")).width(180.0), + ); if r.lost_focus() { let _ = app.run("library.autoImport", json!({"album": name.trim()})); } @@ -548,6 +639,13 @@ fn performance_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { ui.label(RichText::new(used.map(|b| format!("{:.1} MB", b as f64 / 1048576.0)).unwrap_or_else(|| "memory only".into())).color(t.text)); let r = ui.button(crate::i18n::tr("Clear Cache")); register(ui.ctx(), "button:settingsClearCache", r.rect); + let r = ask_first( + t, + "button:settingsClearCache", + r, + "Thumbnails and previews are made again as you browse, which takes a while in a large library. Your photos and edits are not touched.", + "Clear Cache", + ); if r.clicked() { let _ = app.run("library.clearPreviews", json!({})); } @@ -621,17 +719,26 @@ fn smart_previews(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { ); } // what happens to the previews already built when the folder changes - let mode_id = egui::Id::new("smart-existing"); - let mut mode: u8 = ui.data(|d| d.get_temp(mode_id)).unwrap_or(0); + // That choice, and a change waiting for an answer, are kept from one frame of this section to + // the next only, and only for this library and this folder: with Settings closed, another + // tab or library opened, or the folder changed some other way, nothing is left chosen or asked. + let ask_id = egui::Id::new("smart-ask"); + let pass = ui.ctx().cumulative_pass_nr(); + let library = app.session.library.as_ref().map(|l| l.dir.display().to_string()).unwrap_or_default(); + let kept: Option = ui.data(|d| d.get_temp(ask_id)); + let mut ask = kept.filter(|k| k.pass.checked_add(1) == Some(pass) && k.library == library && k.folder == path).unwrap_or_default(); + let mut mode = ask.mode; if count > 0 { row(ui, t, crate::i18n::tr("Existing previews"), |ui| { - if choices(ui, "settingsSmartExisting", &[(0u8, "Move them"), (1, "Leave them"), (2, "Delete them")], &mut mode) { - ui.data_mut(|d| d.insert_temp(mode_id, mode)); - } + choices(ui, "settingsSmartExisting", &[(0u8, "Move them"), (1, "Leave them"), (2, "Delete them")], &mut mode); }); } - let existing = ["move", "leave", "discard"][mode.min(2) as usize]; - let mut result = None; + let mut existing = ["move", "leave", "discard"][mode.min(2) as usize]; + // Deleting the previews already built is asked about once more, when the folder they would + // be deleted for is known: until then the change (the command's parameters) waits here. + // (asked for "Delete them" only: choosing otherwise withdraws the question) + let mut waiting: Option = ask.waiting.take().filter(|_| existing == "discard"); + let mut change = None; ui.horizontal(|ui| { ui.add_space(LABEL_W); if app.services.pick_folder.is_some() { @@ -640,15 +747,58 @@ fn smart_previews(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { if r.clicked() && let Some(dir) = app.services.pick_folder.as_mut().and_then(|f| f()) { - result = Some(app.run("library.smartPreviewsLocation", json!({"path": dir, "existing": existing}))); + change = Some(json!({"path": dir, "existing": existing})); } } let r = ui.add_enabled(custom, egui::Button::new(crate::i18n::tr("Use Library Folder"))); register(ui.ctx(), "button:settingsSmartReset", r.rect); if r.clicked() { - result = Some(app.run("library.smartPreviewsLocation", json!({"reset": true, "existing": existing}))); + change = Some(json!({"reset": true, "existing": existing})); } }); + if existing == "discard" && count > 0 && change.is_some() { + waiting = change.take(); + } + let mut answered = false; + if let Some(params) = &waiting { + // (said with the count line above and two plain sentences, so no new format string is needed) + let how_many = + crate::i18n::tr_format!("{count} smart preview{} · {:.1} MB", if count == 1 { "" } else { "s" }, bytes as f64 / 1048576.0, count = count); + let question = format!( + "{} {how_many}. {}", + crate::i18n::tr("Delete the smart previews in the folder used until now?"), + crate::i18n::tr( + "Photos whose originals are not connected are shown and edited from their smart previews; new ones can only be made from originals that are connected." + ), + ); + ui.add(egui::Label::new(RichText::new(question).color(t.caution)).wrap()); + ui.horizontal(|ui| { + let r = ui.button(crate::i18n::tr("Delete and Change Folder")); + register(ui.ctx(), "button:settingsSmartDelete", r.rect); + if r.clicked() { + // (what the section shows is up to two seconds old: the folder is asked for + // again, and a question about a folder that is no longer the one is dropped) + let still = app.run("library.smartPreviewsLocation", json!({})).is_ok_and(|now| now["path"].as_str() == Some(path.as_str())); + if still { + change = Some(params.clone()); + existing = "discard"; + } else { + ui.data_mut(|d| d.remove::<(f64, Value)>(cache)); + } + answered = true; + } + let r = ui.button(crate::i18n::tr("Cancel")); + register(ui.ctx(), "button:settingsSmartCancel", r.rect); + answered |= r.clicked(); + }); + } + if answered || change.is_some() { + // (the choice goes back to "Move them": deleting is never left set for the next time) + waiting = None; + mode = 0; + } + ui.data_mut(|d| d.insert_temp(ask_id, SmartAsk { pass, library, folder: path.clone(), mode, waiting })); + let result = change.map(|params| app.run("library.smartPreviewsLocation", params)); if let Some(r) = result { ui.data_mut(|d| d.remove::<(f64, Value)>(cache)); match r { diff --git a/crates/ui-egui/src/tests_dialog_settings_trust.rs b/crates/ui-egui/src/tests_dialog_settings_trust.rs new file mode 100644 index 00000000000..98880b21f6b --- /dev/null +++ b/crates/ui-egui/src/tests_dialog_settings_trust.rs @@ -0,0 +1,455 @@ +//! Settings does not do what cannot be taken back, or takes long to make again, on one click, and +//! Esc in one of its text boxes gives the text back. +//! +//! Before: Esc in Copyright or Creator saved what had been typed and closed the window; Clear +//! Cache and a model's Remove acted at once; and deleting the smart previews already built was a +//! choice made beforehand, which a later press of Choose Folder then carried out without a word. + +use std::time::Duration; + +use serde_json::{Value, json}; + +use crate::headless::Headless; +use crate::state::Dialog; +use crate::{LightcraftApp, Services}; + +const T: Duration = Duration::from_secs(20); + +/// A folder under the system's temporary one, removed again when the test ends, passed or not. +struct TempFolder(std::path::PathBuf); + +impl TempFolder { + fn new(tag: &str) -> Self { + let dir = std::env::temp_dir().join(format!("lc-ui-{tag}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + Self(dir) + } + + fn path(&self, rest: &str) -> String { + self.0.join(rest).to_string_lossy().into_owned() + } +} + +impl Drop for TempFolder { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } +} + +fn headless(session: lightcraft_engine::Session, services: Services) -> Headless { + let mut h = Headless::new(LightcraftApp::new(session, services), [1200.0, 900.0], 1.0); + // let the first renders finish (a render still running at exit can crash in GPU teardown) + h.settle(T); + h +} + +fn demo() -> Headless { + headless(lightcraft_engine::Session::with_demo(), Services::default()) +} + +fn show(h: &mut Headless, tab: &str) { + let r = h.request("engine.execute", json!({"command": "app.settings", "params": {"tab": tab}}), T); + assert_eq!(r["ok"], true, "app.settings {tab}: {r}"); + h.settle(T); + for _ in 0..4 { + h.step(); + } +} + +fn steps(h: &mut Headless) { + for _ in 0..4 { + h.step(); + } +} + +fn click(h: &mut Headless, id: &str) { + let r = h.request("ui.clickWidget", json!({"id": id}), T); + assert_eq!(r["ok"], true, "click {id}: {r}"); + steps(h); +} + +fn key(h: &mut Headless, key: &str) { + assert_eq!(h.request("ui.key", json!({"key": key}), T)["ok"], true, "{key}"); + steps(h); +} + +fn has(h: &Headless, id: &str) -> bool { + h.app.widgets.iter().any(|(w, _)| w == id) +} + +fn says(h: &Headless, part: &str) -> bool { + h.painted_text().iter().any(|text| text.contains(part)) +} + +fn settings_open(h: &Headless, tab: &str) -> bool { + h.app.ui.dialog == Some(Dialog::Settings { tab: tab.into() }) +} + +fn copyright(h: &mut Headless) -> Value { + h.app.run("library.preferences", json!({})).unwrap()["import"]["copyright"].clone() +} + +#[test] +fn esc_in_copyright_gives_the_text_back_and_leaves_settings_open() { + let mut h = demo(); + show(&mut h, "import"); + let before = copyright(&mut h); + // Given a name typed into Copyright + click(&mut h, "field:settings.copyright"); + h.request("ui.text", json!({"text": "Example Name"}), T); + steps(&mut h); + assert!(says(&h, "Example Name"), "the typing shows"); + // When Esc is pressed + key(&mut h, "Escape"); + // Then the name is gone again, nothing was saved, and Settings is still open + assert!(!says(&h, "Example Name"), "Esc gives the text back"); + assert_eq!(copyright(&mut h), before, "nothing was saved"); + assert!(settings_open(&h, "import"), "Settings stays open: {:?}", h.app.ui.dialog); + // And a second Esc, with no edit under way, closes Settings as it always did + key(&mut h, "Escape"); + assert!(h.app.ui.dialog.is_none()); +} + +#[test] +fn return_in_copyright_saves_the_text() { + let mut h = demo(); + show(&mut h, "import"); + click(&mut h, "field:settings.copyright"); + h.request("ui.text", json!({"text": "Example Name"}), T); + steps(&mut h); + key(&mut h, "Enter"); + assert_eq!(copyright(&mut h), json!("Example Name")); + assert!(settings_open(&h, "import")); +} + +#[test] +fn clear_cache_asks_first() { + let mut h = demo(); + show(&mut h, "performance"); + let used = |h: &Headless| h.app.session.media.rendered.mem_usage().0; + let before = used(&h); + assert!(before > 0, "the demo's thumbnails are cached"); + // When Clear Cache is pressed + click(&mut h, "button:settingsClearCache"); + // Then it says what clearing costs and waits for an answer; nothing is cleared yet + assert!(says(&h, "made again"), "it says what clearing costs: {:?}", h.painted_text().iter().filter(|t| t.contains("again")).collect::>()); + assert!(has(&h, "button:settingsClearCache:confirm") && has(&h, "button:settingsClearCache:keep")); + assert_eq!(used(&h), before, "nothing is cleared before the answer"); + // When the answer is to keep it + click(&mut h, "button:settingsClearCache:keep"); + // Then the question goes and the cache is as it was + assert!(!has(&h, "button:settingsClearCache:confirm")); + assert_eq!(used(&h), before); + // When it is pressed again and confirmed, the cache is cleared + click(&mut h, "button:settingsClearCache"); + let r = h.request("ui.clickWidget", json!({"id": "button:settingsClearCache:confirm"}), T); + assert_eq!(r["ok"], true, "{r}"); + h.step(); + h.step(); + assert!(used(&h) < before, "the cache was cleared: {} of {before}", used(&h)); + steps(&mut h); + assert!(!has(&h, "button:settingsClearCache:confirm"), "and the question is gone"); +} + +#[test] +fn esc_takes_the_question_away_and_leaves_settings_open() { + let mut h = demo(); + show(&mut h, "performance"); + let before = h.app.session.media.rendered.mem_usage().0; + click(&mut h, "button:settingsClearCache"); + assert!(has(&h, "button:settingsClearCache:confirm")); + key(&mut h, "Escape"); + assert!(!has(&h, "button:settingsClearCache:confirm"), "Esc answers no"); + assert!(settings_open(&h, "performance"), "and Settings stays open"); + assert_eq!(h.app.session.media.rendered.mem_usage().0, before); +} + +#[test] +fn removing_a_face_model_asks_first() { + let dir = TempFolder::new("settings-trust-faces"); + let mut h = demo(); + h.app.session.face_models_dir = Some(dir.0.join("models")); + if h.app.session.execute("faces.models.list", &json!({})).unwrap()["runtime"] != true { + return; // this build cannot run recognition models: there is nothing to install or remove + } + // Given a recognition model installed + let model = dir.0.join("Mine.onnx"); + std::fs::write(&model, lightcraft_faces::synthetic::tiny_embedder_model(512)).unwrap(); + let installed = h.app.run("faces.models.install", json!({"path": model.to_string_lossy(), "acknowledged": true, "activate": false})).unwrap(); + let id = installed["installed"]["id"].as_str().unwrap().to_string(); + h.app.caches.faces_epoch += 1; + let is_installed = |h: &mut Headless| h.app.run("faces.models.list", json!({})).unwrap().to_string().contains(&id); + show(&mut h, "faces"); + let remove = format!("faces:remove:{id}"); + // When Remove is pressed + click(&mut h, &remove); + // Then it asks, and the model is still there + assert!(has(&h, &format!("{remove}:confirm")), "Remove asks first"); + assert!(is_installed(&mut h), "the model is still installed"); + // When the answer is yes, it is removed + click(&mut h, &format!("{remove}:confirm")); + assert!(!is_installed(&mut h), "the model is removed"); + assert!(!has(&h, &remove), "and its Remove button is gone with it"); +} + +fn write_png(path: &str, seed: u8) { + let (w, h) = (24usize, 16usize); + let data: Vec<[u8; 4]> = (0..w * h).map(|i| [(i % w * 9) as u8, (i / w * 13) as u8, seed, 255]).collect(); + let img = lightcraft_raster::Rgba8 { width: w, height: h, data }; + let bytes = lightcraft_codecs::encode_png(&lightcraft_codecs::EncodeImage::rgba8(&img), &lightcraft_codecs::EncodeMeta::default()).unwrap(); + std::fs::create_dir_all(std::path::Path::new(path).parent().unwrap()).unwrap(); + std::fs::write(path, bytes).unwrap(); +} + +/// A library on disk with one photo and its smart preview built, whose folder picker answers `to`. +fn with_smart_preview(dir: &TempFolder, to: &str) -> Headless { + write_png(&dir.path("trip/a.png"), 3); + let mut session = lightcraft_engine::Session::new().with_fs(); + session.open_library(dir.0.join("library"), false).unwrap(); + session.execute("library.import", &json!({"paths": [dir.path("trip/a.png")]})).unwrap(); + session.execute("library.smartPreviews", &json!({})).unwrap(); + std::fs::create_dir_all(to).unwrap(); + let to = to.to_string(); + headless(session, Services { pick_folder: Some(Box::new(move || Some(to.clone()))), ..Default::default() }) +} + +fn smart(h: &mut Headless) -> Value { + h.app.run("library.smartPreviewsLocation", json!({})).unwrap() +} + +#[test] +fn deleting_the_smart_previews_is_asked_about_when_the_folder_is_chosen() { + let dir = TempFolder::new("settings-trust-smart"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + assert_eq!(smart(&mut h)["count"], 1); + show(&mut h, "performance"); + // Given "Delete them" chosen for the previews already built + click(&mut h, "button:settingsSmartExisting-2"); + // When a new folder is chosen + click(&mut h, "button:settingsSmartChoose"); + // Then nothing has happened yet: it asks, saying how many previews would go + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(false)), "nothing is deleted or moved before the answer: {now}"); + assert!(has(&h, "button:settingsSmartDelete") && has(&h, "button:settingsSmartCancel"), "it asks"); + let question: Vec = h.painted_text().into_iter().filter(|text| text.contains("Delete the smart previews")).collect(); + assert!(question.iter().any(|text| text.contains("1 smart preview")), "it asks, saying how many would go: {question:?}"); + // When the answer is no + click(&mut h, "button:settingsSmartCancel"); + // Then the folder and its previews are as they were, and the question is gone + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(false))); + assert!(!has(&h, "button:settingsSmartDelete")); + // And the choice is back at "Move them": deleting is not left armed for next time + click(&mut h, "button:settingsSmartChoose"); + let moved = smart(&mut h); + assert_eq!((moved["count"].clone(), moved["custom"].clone()), (json!(1), json!(true)), "the previews moved with the folder: {moved}"); +} + +#[test] +fn saying_yes_deletes_the_smart_previews_and_changes_the_folder() { + let dir = TempFolder::new("settings-trust-smart-yes"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + click(&mut h, "button:settingsSmartExisting-2"); + click(&mut h, "button:settingsSmartChoose"); + assert_eq!(smart(&mut h)["count"], 1); + click(&mut h, "button:settingsSmartDelete"); + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(0), json!(true)), "{now}"); + assert_eq!(now["path"], json!(to)); + assert!(!has(&h, "button:settingsSmartDelete")); +} + +#[test] +fn moving_the_smart_previews_needs_no_question() { + let dir = TempFolder::new("settings-trust-smart-move"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + click(&mut h, "button:settingsSmartChoose"); + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(true)), "{now}"); + assert!(!has(&h, "button:settingsSmartDelete")); +} + +#[test] +fn writing_xmp_by_itself_says_what_is_written_where() { + let mut h = demo(); + show(&mut h, "import"); + assert!(says(&h, "beside the photo"), "{:?}", h.painted_text().iter().filter(|t| t.contains("XMP")).collect::>()); +} + +/// A second library on disk with a smart preview of its own, in a folder chosen for it. +fn another_library(dir: &TempFolder) -> (String, String) { + write_png(&dir.path("other/b.png"), 9); + let (library, folder) = (dir.path("library-b"), dir.path("previews-b")); + std::fs::create_dir_all(&folder).unwrap(); + let mut session = lightcraft_engine::Session::new().with_fs(); + session.open_library(&library, false).unwrap(); + session.execute("library.import", &json!({"paths": [dir.path("other/b.png")]})).unwrap(); + session.execute("library.smartPreviewsLocation", &json!({"path": folder, "existing": "leave"})).unwrap(); + session.execute("library.smartPreviews", &json!({})).unwrap(); + session.close_library().unwrap(); + (library, folder) +} + +#[test] +fn a_question_left_unanswered_is_gone_when_settings_is_opened_again() { + let dir = TempFolder::new("settings-trust-smart-left"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + // Given the question about deleting, left unanswered + click(&mut h, "button:settingsSmartExisting-2"); + click(&mut h, "button:settingsSmartChoose"); + assert!(has(&h, "button:settingsSmartDelete")); + // When Settings is closed and opened again + key(&mut h, "Escape"); + assert!(h.app.ui.dialog.is_none()); + show(&mut h, "performance"); + // Then nothing waits: no question, and the choice is back at "Move them" + assert!(!has(&h, "button:settingsSmartDelete"), "the question does not outlive Settings"); + click(&mut h, "button:settingsSmartChoose"); + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(true)), "the previews moved: {now}"); +} + +#[test] +fn a_question_asked_in_one_library_is_not_there_in_another() { + let dir = TempFolder::new("settings-trust-smart-other"); + let (library_b, folder_b) = another_library(&dir); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + // Given the question about deleting asked in one library, and left + click(&mut h, "button:settingsSmartExisting-2"); + click(&mut h, "button:settingsSmartChoose"); + assert!(has(&h, "button:settingsSmartDelete")); + key(&mut h, "Escape"); + // When another library is opened and its Settings looked at + h.app.run("app.openLibrary", json!({"path": library_b})).unwrap(); + h.settle(T); + show(&mut h, "performance"); + // Then that library is not asked anything, and its smart previews are where they were + assert!(!has(&h, "button:settingsSmartDelete"), "the question belongs to the library it was asked in"); + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["path"].clone()), (json!(1), json!(folder_b)), "{now}"); +} + +#[test] +fn a_change_made_another_way_takes_the_question_away() { + let dir = TempFolder::new("settings-trust-smart-other-way"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + click(&mut h, "button:settingsSmartExisting-2"); + click(&mut h, "button:settingsSmartChoose"); + assert!(has(&h, "button:settingsSmartDelete")); + // When "Move them" is chosen instead and the folder chosen again + click(&mut h, "button:settingsSmartExisting-0"); + assert!(!has(&h, "button:settingsSmartDelete"), "choosing not to delete takes the question away"); + click(&mut h, "button:settingsSmartChoose"); + // Then the previews moved, and no question about deleting them is left standing + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(true)), "{now}"); + assert!(!has(&h, "button:settingsSmartDelete")); +} + +#[test] +fn use_library_folder_asks_before_deleting_too() { + let dir = TempFolder::new("settings-trust-smart-reset"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + // Given the previews moved to a chosen folder, then "Delete them" chosen + click(&mut h, "button:settingsSmartChoose"); + assert_eq!(smart(&mut h)["custom"], true); + h.settle(T); + steps(&mut h); + click(&mut h, "button:settingsSmartExisting-2"); + // When Use Library Folder is pressed, it asks first + click(&mut h, "button:settingsSmartReset"); + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(true)), "{now}"); + assert!(has(&h, "button:settingsSmartDelete")); +} + +#[test] +fn text_typed_in_copyright_is_saved_when_another_tab_is_opened() { + let mut h = demo(); + show(&mut h, "import"); + click(&mut h, "field:settings.copyright"); + h.request("ui.text", json!({"text": "Example Name"}), T); + steps(&mut h); + // When another tab is clicked with the text still being typed + click(&mut h, "button:settingsTab-general"); + // Then that tab opens and the text was saved, as leaving the box any other way saves it + assert!(settings_open(&h, "general")); + assert_eq!(copyright(&mut h), json!("Example Name")); +} + +#[test] +fn esc_in_an_external_editing_box_leaves_settings_open_too() { + let mut h = demo(); + show(&mut h, "general"); + let before = h.app.ui.settings.external_editor.clone(); + click(&mut h, "field:externalEditor"); + h.request("ui.text", json!({"text": "Example Editor"}), T); + steps(&mut h); + key(&mut h, "Escape"); + assert_eq!(h.app.ui.settings.external_editor, before, "Esc gives the text back"); + assert!(settings_open(&h, "general"), "and Settings stays open: {:?}", h.app.ui.dialog); +} + +#[test] +fn the_question_opens_with_the_focus_on_keep() { + let mut h = demo(); + show(&mut h, "performance"); + let before = h.app.session.media.rendered.mem_usage().0; + click(&mut h, "button:settingsClearCache"); + assert!(has(&h, "button:settingsClearCache:confirm")); + // When Return is pressed straight away + key(&mut h, "Enter"); + // Then the answer was Keep: the question is gone and nothing was cleared + assert!(!has(&h, "button:settingsClearCache:confirm")); + assert_eq!(h.app.session.media.rendered.mem_usage().0, before); + assert!(settings_open(&h, "performance")); +} + +#[test] +fn a_question_about_a_folder_that_has_changed_since_deletes_nothing() { + let dir = TempFolder::new("settings-trust-smart-outside"); + let to = dir.path("elsewhere"); + let mut h = with_smart_preview(&dir, &to); + show(&mut h, "performance"); + click(&mut h, "button:settingsSmartExisting-2"); + click(&mut h, "button:settingsSmartChoose"); + assert!(has(&h, "button:settingsSmartDelete")); + // Given the folder changed from outside Settings (an agent, say) while the question stands + let other = dir.path("another"); + std::fs::create_dir_all(&other).unwrap(); + h.app.run("library.smartPreviewsLocation", json!({"path": other, "existing": "move"})).unwrap(); + // When Delete and Change Folder is pressed all the same + let r = h.request("ui.clickWidget", json!({"id": "button:settingsSmartDelete"}), T); + assert_eq!(r["ok"], true, "{r}"); + steps(&mut h); + // Then nothing is deleted and the folder is the one set from outside: the question was about another + let now = smart(&mut h); + assert_eq!((now["count"].clone(), now["path"].clone()), (json!(1), json!(other)), "{now}"); + assert!(!has(&h, "button:settingsSmartDelete")); +} + +#[test] +fn after_keep_the_focus_is_back_on_the_button() { + let mut h = demo(); + show(&mut h, "performance"); + click(&mut h, "button:settingsClearCache"); + key(&mut h, "Enter"); // Keep, which has the focus + assert!(!has(&h, "button:settingsClearCache:confirm")); + // When Space is pressed again, the question opens again: the focus was on Clear Cache + key(&mut h, "Space"); + assert!(has(&h, "button:settingsClearCache:confirm"), "the focus went back to Clear Cache"); +} diff --git a/docs/whats-new.md b/docs/whats-new.md index c9a68ef2132..76cae6bb200 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -251,6 +251,18 @@ - A tab or a choice reached with the keyboard shows a ring. Tab moves through them, ← and → along a row, and Space or Return opens or chooses, as before: the focus was there all along but could not be seen. Text buttons elsewhere in LightCraft show the same ring. Screen readers are told a choice in Settings is a radio button. +- Settings asks before it does what is slow or impossible to take back. Clear Cache says that thumbnails and + previews are made again as you browse, and a model's Remove that its file is deleted, each with the action and + Keep under the button. Keep has the focus, so Return alone changes nothing; Esc or a click elsewhere answers no. +- Changing the smart previews folder with "Delete them" chosen no longer deletes at the press of Choose Folder: with + the new folder chosen, it says how many smart previews would go and what they are for, and waits for Delete and + Change Folder or Cancel. The choice goes back to "Move them" afterwards, and neither it nor the question is + left standing when Settings is closed or another library is opened. +- Esc in a text box of Settings (Copyright, Creator, the Auto Import album, the two External Editing boxes) gives + the text back and stays in Settings; in the first three it used to save what was typed, and in all of them it + closed the window. Those three now have the Cut / Copy / Paste menu too, and what is typed in Copyright or + Creator is saved when another tab is clicked, where it used to be dropped. +- Automatically write changes into XMP sidecars says what is written where. - A long folder (General ▸ Library ▸ Location, the folder Auto Import watches, the smart previews folder, a monitor profile's file) is shortened to its last folders ("…/Pictures/Library") on one line; rest the pointer on it for the whole path. From 8b1cfc814d86bb30290e689d98f8d67ac7b5aa8b Mon Sep 17 00:00:00 2001 From: Nathaniel Ledford Date: Mon, 12 Oct 2026 12:35:32 -0400 Subject: [PATCH 05/37] LR-PREF-GENERAL: the Settings tabs are grouped by what a person comes to do General held the library's location beside the language and the external editors; XMP sidecar writing, which governs every later edit, sat under Import; forgetting unchanged photos and the smart previews folder, which are the library's own, under Performance. "Display" was the monitor's colour profile and "Interface" how LightCraft looks. - Library (new, `library`): where the library is, opening or making another, where its smart previews are kept, and Local folders. - Files (new, `files`): XMP sidecars and External Editing. - General keeps Language, Startup and Culling; Import keeps what happens to photos as they come in; Performance keeps Rendering and Thumbnail cache. - Display is labelled Monitor and Interface is labelled Appearance (settings::tab_label). Their ids, and every other tab id, are as they were: `app.settings {tab}` from agents, scripts and the rest of the app opens what it opened. - What is saved with the library says, in a library that is in memory, that it will not last, on each tab that holds such settings. - A section's heading is registered as `heading:{its English name}` whatever the language (i18n::source_of). - Files and Monitor are in the nine catalogs. No section's code moved. The tab functions are split where their sections begin by inserting the end of one function and the start of the next, and the tabs call the sections: the lines other open pull requests change are where they were. Controls keep their widget ids. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/prefs.rs | 2 +- crates/ui-egui/locales/de.json | 2 + crates/ui-egui/locales/es.json | 2 + crates/ui-egui/locales/fr.json | 2 + crates/ui-egui/locales/ja.json | 2 + crates/ui-egui/locales/pt-br.json | 2 + crates/ui-egui/locales/ru.json | 2 + crates/ui-egui/locales/uk.json | 2 + crates/ui-egui/locales/zh-hans.json | 2 + crates/ui-egui/locales/zh-hant.json | 2 + crates/ui-egui/src/i18n.rs | 29 +++- crates/ui-egui/src/lib.rs | 4 +- crates/ui-egui/src/panels/settings.rs | 80 ++++++++- crates/ui-egui/src/tests_dialog_settings.rs | 56 +++--- .../src/tests_dialog_settings_groups.rs | 164 ++++++++++++++++++ .../ui-egui/src/tests_dialog_settings_tabs.rs | 20 +-- .../src/tests_dialog_settings_trust.rs | 26 +-- docs/display-profiles.md | 2 +- docs/parity-checklist.md | 2 +- docs/whats-new.md | 10 ++ 20 files changed, 353 insertions(+), 60 deletions(-) create mode 100644 crates/ui-egui/src/tests_dialog_settings_groups.rs diff --git a/crates/engine/src/cmd/prefs.rs b/crates/engine/src/cmd/prefs.rs index 78de9d8500c..7003ee5bc10 100644 --- a/crates/engine/src/cmd/prefs.rs +++ b/crates/engine/src/cmd/prefs.rs @@ -1,4 +1,4 @@ -//! Library preferences (Settings → Import / Performance): develop defaults applied on import and +//! Library preferences (Settings → Library / Import / Performance): develop defaults applied on import and //! the thumbnail cache budget. Saved in the library's `prefs.json` (see [`crate::library`]). use serde_json::{Value, json}; diff --git a/crates/ui-egui/locales/de.json b/crates/ui-egui/locales/de.json index 25c411ce0e0..65b14ebcf99 100644 --- a/crates/ui-egui/locales/de.json +++ b/crates/ui-egui/locales/de.json @@ -2036,6 +2036,8 @@ "Not saved": "Nicht gespeichert", "A folder is being synchronized": "Ein Ordner wird gerade synchronisiert", "Wait for the import to finish": "Warten Sie, bis der Import abgeschlossen ist", + "Files": "Dateien", + "Monitor": "Monitor", "Appearance": "Erscheinungsbild", "Appearance Mode": "Erscheinungsmodus", "Sync with System": "Mit System synchronisieren", diff --git a/crates/ui-egui/locales/es.json b/crates/ui-egui/locales/es.json index ba3e1e33165..a38344700d5 100644 --- a/crates/ui-egui/locales/es.json +++ b/crates/ui-egui/locales/es.json @@ -1916,6 +1916,8 @@ "Not saved": "Sin guardar", "A folder is being synchronized": "Se está sincronizando una carpeta", "Wait for the import to finish": "Esperar a que termine la importación", + "Files": "Archivos", + "Monitor": "Monitor", "Appearance": "Apariencia", "Appearance Mode": "Modo de apariencia", "Sync with System": "Sincronizar con el sistema", diff --git a/crates/ui-egui/locales/fr.json b/crates/ui-egui/locales/fr.json index b0becb154e4..77526d46ae6 100644 --- a/crates/ui-egui/locales/fr.json +++ b/crates/ui-egui/locales/fr.json @@ -1937,6 +1937,8 @@ "Appearance Settings…": "Réglages d’apparence…", "Add to favorites": "Ajouter aux favoris", "Remove from favorites": "Retirer des favoris", + "Files": "Fichiers", + "Monitor": "Moniteur", "Appearance": "Apparence", "Appearance Mode": "Mode d’apparence", "Sync with System": "Synchroniser avec le système", diff --git a/crates/ui-egui/locales/ja.json b/crates/ui-egui/locales/ja.json index 7a282e676e4..32338af7b9e 100644 --- a/crates/ui-egui/locales/ja.json +++ b/crates/ui-egui/locales/ja.json @@ -1882,6 +1882,8 @@ "Not saved": "保存されていません", "A folder is being synchronized": "フォルダを同期中です", "Wait for the import to finish": "読み込みが終わるまでお待ちください", + "Files": "ファイル", + "Monitor": "モニター", "Appearance": "外観", "Appearance Mode": "外観モード", "Sync with System": "システムと同期", diff --git a/crates/ui-egui/locales/pt-br.json b/crates/ui-egui/locales/pt-br.json index f8e4753e5ce..700a332178d 100644 --- a/crates/ui-egui/locales/pt-br.json +++ b/crates/ui-egui/locales/pt-br.json @@ -1880,6 +1880,8 @@ "Not saved": "Não salvo", "A folder is being synchronized": "Uma pasta está sendo sincronizada", "Wait for the import to finish": "Aguarde a importação terminar", + "Files": "Arquivos", + "Monitor": "Monitor", "Appearance": "Aparência", "Appearance Mode": "Modo de aparência", "Sync with System": "Sincronizar com o sistema", diff --git a/crates/ui-egui/locales/ru.json b/crates/ui-egui/locales/ru.json index c840218a039..7e005b09b3a 100644 --- a/crates/ui-egui/locales/ru.json +++ b/crates/ui-egui/locales/ru.json @@ -1593,6 +1593,8 @@ "Not saved": "Не сохранено", "A folder is being synchronized": "Папка синхронизируется", "Wait for the import to finish": "Дождитесь завершения импорта", + "Files": "Файлы", + "Monitor": "Монитор", "Appearance": "Оформление", "Appearance Mode": "Режим оформления", "Sync with System": "Как в системе", diff --git a/crates/ui-egui/locales/uk.json b/crates/ui-egui/locales/uk.json index 85a83809806..4772ebe7164 100644 --- a/crates/ui-egui/locales/uk.json +++ b/crates/ui-egui/locales/uk.json @@ -2131,6 +2131,8 @@ "Appearance Settings…": "Налаштування вигляду…", "Add to favorites": "Додати до вибраного", "Remove from favorites": "Видалити з вибраного", + "Files": "Файли", + "Monitor": "Монітор", "Appearance": "Вигляд", "Appearance Mode": "Режим вигляду", "Sync with System": "Як у системі", diff --git a/crates/ui-egui/locales/zh-hans.json b/crates/ui-egui/locales/zh-hans.json index ad379f1ef3c..4f905883fbb 100644 --- a/crates/ui-egui/locales/zh-hans.json +++ b/crates/ui-egui/locales/zh-hans.json @@ -1880,6 +1880,8 @@ "Not saved": "未保存", "A folder is being synchronized": "正在同步文件夹", "Wait for the import to finish": "请等待导入完成", + "Files": "文件", + "Monitor": "显示器", "Appearance": "外观", "Appearance Mode": "外观模式", "Sync with System": "与系统同步", diff --git a/crates/ui-egui/locales/zh-hant.json b/crates/ui-egui/locales/zh-hant.json index 647d153d0a7..047514be5d0 100644 --- a/crates/ui-egui/locales/zh-hant.json +++ b/crates/ui-egui/locales/zh-hant.json @@ -1880,6 +1880,8 @@ "Not saved": "未儲存", "A folder is being synchronized": "正在同步資料夾", "Wait for the import to finish": "請等待匯入完成", + "Files": "檔案", + "Monitor": "顯示器", "Appearance": "外觀", "Appearance Mode": "外觀模式", "Sync with System": "與系統同步", diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 109accfa9ea..473ac1d9d51 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -166,6 +166,22 @@ pub fn tr(source: &str) -> &str { tr_in(language(), source) } +/// The source (English) text a piece of interface text stands for in the current language, or +/// the text itself when it stands for none (it is English already, or was never a message). For +/// names that scripts and tests look things up by, which must not change with the language. +/// When two messages read alike in a language, the first in the catalog's order is given. +pub fn source_of(text: &str) -> &str { + source_of_in(language(), text) +} + +fn source_of_in(language: Locale, text: &str) -> &str { + language + .catalog() + .iter() + .find(|(source, translation)| translation.as_str() == text && !source.contains('|')) + .map_or(text, |(source, _)| source.as_str()) +} + /// [`tr`] for a message whose translation depends on where it appears: a catalog entry keyed /// `"|"` wins, else the plain message. A language adds the contextual entry only /// where its shared translation reads wrongly there (Japanese はい / いいえ as a rule's value). @@ -430,6 +446,17 @@ pub fn rules_label(rules: &lightcraft_catalog::RuleSet, catalog: &lightcraft_cat #[cfg(test)] mod tests { + /// A section's name for scripts is its English one whatever the language shows. + #[test] + fn interface_text_is_traced_back_to_its_source() { + let german = super::Locale::De.tr("Library").to_string(); + assert_ne!(german, "Library", "German has a word of its own for it"); + assert_eq!(super::source_of_in(super::Locale::De, &german), "Library"); + assert_eq!(super::source_of_in(super::Locale::De, "Library"), "Library", "English text is itself"); + assert_eq!(super::source_of_in(super::Locale::En, "Library"), "Library"); + assert_eq!(super::source_of_in(super::Locale::De, "no such message"), "no such message"); + } + use super::*; #[test] @@ -834,7 +861,7 @@ mod tests { let mut labels: Vec<&str> = lightcraft_engine::command_specs().iter().map(|spec| spec.label).collect(); labels.extend(crate::menus::ui_commands().map(|command| command.1).filter(|label| !Locale::ALL.iter().any(|locale| locale.name() == *label))); labels.extend(lightcraft_develop::CONTROLS.iter().map(|control| control.label)); - labels.extend(crate::panels::settings::TABS.iter().map(|(_, label)| *label)); + labels.extend(crate::panels::settings::TABS.iter().map(|(id, label)| crate::panels::settings::tab_label(id, label))); for (_, label, kind) in lightcraft_catalog::rules::FIELDS { labels.push(label); labels.extend(lightcraft_catalog::rules::ops_for(*kind).iter().map(|(_, label)| *label)); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 214b0eae56a..44dd82b3891 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -65,6 +65,8 @@ mod tests_dialog_fit; #[cfg(test)] mod tests_dialog_settings; #[cfg(test)] +mod tests_dialog_settings_groups; +#[cfg(test)] mod tests_dialog_settings_tabs; #[cfg(test)] mod tests_dialog_settings_trust; @@ -227,7 +229,7 @@ pub struct Services { /// The host's current log file (`/logs/lightcraft.log`), which Help ▸ Open Log /// Folder reveals (#260). None where no log is kept: the web, `--memory`, `LIGHTCRAFT_NO_PREFS`. pub log_file: Option, - /// Choose a folder (Settings → General → Open Library…; desktop only). + /// Choose a folder (Settings → Library → Open Library…; desktop only). pub pick_folder: Option, /// Open a Lightroom Classic `.lrcat` catalog for read-only import. pub pick_lightroom_catalog: Option, diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs index 8e171888edb..6e49b0884fe 100644 --- a/crates/ui-egui/src/panels/settings.rs +++ b/crates/ui-egui/src/panels/settings.rs @@ -20,7 +20,9 @@ use crate::widgets::register; /// (id, label) of the tabs, in order. pub const TABS: &[(&str, &str)] = &[ ("general", "General"), + ("library", "Library"), ("import", "Import"), + ("files", "Files"), ("performance", "Performance"), ("display", "Display"), ("interface", "Interface"), @@ -28,6 +30,18 @@ pub const TABS: &[(&str, &str)] = &[ ("denoise", "AI Denoise"), ]; +/// What a tab is called on the tab bar. Two tabs go by another name than [`TABS`] gives them, +/// so that the monitor's colour profile and how LightCraft looks are not taken for each other: +/// `display` is Monitor and `interface` is Appearance. (Said here and not in `TABS`, whose lines +/// after these two are where other work adds its tabs; ids stay as they are.) +pub fn tab_label(id: &str, label: &'static str) -> &'static str { + match id { + "display" => "Monitor", + "interface" => "Appearance", + _ => label, + } +} + /// Thumbnail cache sizes offered (MB). const CACHE_SIZES: [u32; 5] = [512, 1024, 2048, 4096, 8192]; @@ -37,6 +51,8 @@ const LABEL_W: f32 = 150.0; pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &str) { let t = Tokens::get(ui.ctx()); match tab { + "library" => library_tab(app, ui, &t), + "files" => files_tab(app, ui, &t), "import" => import_tab(app, ui, &t), "performance" => performance_tab(app, ui, &t), "display" => display_tab(app, ui, &t), @@ -77,7 +93,7 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_ ui.horizontal_wrapped(|ui| { ui.spacing_mut().item_spacing = egui::vec2(4.0, 5.0); for (id, label) in TABS { - let r = crate::widgets::tab_button(ui, &format!("settingsTab-{id}"), label, shown == *id); + let r = crate::widgets::tab_button(ui, &format!("settingsTab-{id}"), tab_label(id, label), shown == *id); let bottom = egui::emath::GuiRounding::round_to_pixels(r.rect.bottom(), ui.pixels_per_point()); if !lines.iter().any(|line| (line - bottom).abs() < 0.5) { lines.push(bottom); @@ -227,7 +243,10 @@ pub(super) fn ask_first(t: &Tokens, id: &str, button: egui::Response, question: pub(super) fn heading(ui: &mut egui::Ui, t: &Tokens, text: &str) { ui.add_space(4.0); - ui.label(RichText::new(crate::i18n::tr(text)).font(t.semibold(12.5)).color(t.text)); + // (`heading:{its English name}`, whatever the language: where a section starts, for scripts + // and tests that look for one. Callers pass the name translated or not.) + let r = ui.label(RichText::new(crate::i18n::tr(text)).font(t.semibold(12.5)).color(t.text)); + register(ui.ctx(), format!("heading:{}", crate::i18n::source_of(text)), r.rect); } fn row(ui: &mut egui::Ui, t: &Tokens, label: &str, add: impl FnOnce(&mut egui::Ui) -> R) -> R { @@ -275,12 +294,44 @@ pub(super) fn choices(ui: &mut egui::Ui, id: &str, options: // ------------------------------------------------------------------------------------- General +/// Library: the library itself. Where it is and opening another ([`library_section`]), where +/// its smart previews are kept ([`smart_previews`], for a library on disk), and what leaves its +/// catalog by itself ([`local_folders`]). +fn library_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { + library_section(app, ui, t); + #[cfg(not(target_arch = "wasm32"))] + smart_previews(app, ui, t); + local_folders(app, ui, t); + in_memory_note(app, ui, t); +} + +/// Files: what LightCraft writes beside the photo files ([`xmp_sidecars`]) and what it opens +/// them in ([`external_editing`]). +fn files_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { + xmp_sidecars(app, ui, t); + in_memory_note(app, ui, t); + external_editing(app, ui, t); +} + +/// What is saved with the library lasts only as long as a library that is not on disk does: +/// said under such settings wherever they are (Import says it at its foot itself). +fn in_memory_note(app: &LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { + if app.session.library.is_none() { + hint(ui, t, "In-memory session: these settings last until LightCraft quits."); + } +} + fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { row(ui, t, crate::i18n::tr("Language"), |ui| { let languages: Vec<_> = crate::i18n::Locale::ALL.iter().map(|language| (*language, language.name())).collect(); choices(ui, "settingsLanguage", &languages, &mut app.ui.language); crate::i18n::set_language(app.ui.language); }); + startup_and_culling(app, ui, t); +} + +/// Library: where the open library is, and opening or making another. +fn library_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("Library")); let location = match &app.session.library { Some(l) => l.dir.display().to_string(), @@ -305,6 +356,10 @@ fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { hint(ui, t, crate::i18n::tr("not available here")); } }); +} + +/// Startup and Culling: what LightCraft opens in, and how rating and deleting behave. +fn startup_and_culling(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("Startup")); row(ui, t, crate::i18n::tr("Open in"), |ui| { choices( @@ -317,6 +372,10 @@ fn general_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("Culling")); check(ui, "settings.autoAdvance", &mut app.ui.auto_advance, "Auto Advance: move to the next photo after rating or flagging"); check(ui, "settings.confirmDelete", &mut app.ui.settings.confirm_delete, "Confirm before moving photos to Recently Deleted"); +} + +/// External Editing: the editors a photo is opened in, and the copy they are given. +fn external_editing(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("External Editing")); row(ui, t, crate::i18n::tr("PhotoCraft"), |ui| { field( @@ -526,6 +585,12 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { } }); } + auto_import(app, ui, t); +} + +/// XMP sidecars: whether changes are written beside the photos by themselves, and how the files +/// are named. +fn xmp_sidecars(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("XMP sidecars")); let mut xmp = app.session.xmp; if check(ui, "settings.autoWriteXmp", &mut xmp.auto_write, "Automatically write changes into XMP sidecars") { @@ -544,6 +609,11 @@ fn import_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { let _ = app.run("library.xmpPreferences", json!({"naming": naming})); } }); +} + +/// Auto Import: the folder watched for new photos, and what is done with what arrives there. +fn auto_import(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { + let d = app.session.import_defaults.clone(); if !cfg!(target_arch = "wasm32") { heading(ui, t, crate::i18n::tr("Auto Import")); hint(ui, t, crate::i18n::tr("Photos that arrive in this folder (tethering, a scanner, a sync app) are added as soon as they're complete.")); @@ -650,6 +720,10 @@ fn performance_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { let _ = app.run("library.clearPreviews", json!({})); } }); +} + +/// Local folders: when photos only seen in Local, never added or changed, leave the catalog. +fn local_folders(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { heading(ui, t, crate::i18n::tr("Local folders")); row(ui, t, crate::i18n::tr("Forget unchanged photos"), |ui| { let opts = [(0u32, "Never"), (7, "After 7 days"), (30, "After 30 days"), (90, "After 90 days"), (365, "After a year")]; @@ -665,8 +739,6 @@ fn performance_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) { "Photos seen in Local but never added or changed leave the catalog when their folder hasn't been browsed for this long (checked when the library opens). Files stay on disk; browsing the folder shows them again.", ), ); - #[cfg(not(target_arch = "wasm32"))] - smart_previews(app, ui, t); } /// Where this library keeps its smart previews (the offline-editing proxies, which can be large): diff --git a/crates/ui-egui/src/tests_dialog_settings.rs b/crates/ui-egui/src/tests_dialog_settings.rs index ed1ee4e93fa..819ce16db62 100644 --- a/crates/ui-egui/src/tests_dialog_settings.rs +++ b/crates/ui-egui/src/tests_dialog_settings.rs @@ -139,12 +139,12 @@ fn a_row_of_many_choices_wraps_under_itself() { #[test] fn a_label_longer_than_its_column_leaves_the_controls_in_line() { - // Given Performance, whose "Forget unchanged photos" label is wider than the label column + // Given Library, whose "Forget unchanged photos" label is wider than the label column let mut h = demo([1600.0, 1000.0]); - show(&mut h, "performance"); - // Then its choices start where the choices of a short label do - let (short, long) = (rect(&h, "button:settingsPreview-0"), rect(&h, "button:settingsForgetLocal-0")); - assert!((short.left() - long.left()).abs() < 0.5, "Preview size starts at {} and Forget unchanged photos at {}", short.left(), long.left()); + show(&mut h, "library"); + // Then its choices start where the control of a short label does + let (short, long) = (rect(&h, "text:settingsLocation"), rect(&h, "button:settingsForgetLocal-0")); + assert!((short.left() - long.left()).abs() < 0.5, "Location starts at {} and Forget unchanged photos at {}", short.left(), long.left()); } #[test] @@ -160,14 +160,14 @@ fn a_long_library_folder_is_cut_short_and_its_tooltip_has_all_of_it() { let mut h = headless(session, [1600.0, 1000.0]); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, h.size); - // When Settings opens on General, which shows where the library is - show(&mut h, "general"); - let general = rect(&h, "dialog:window"); + // When Settings opens on Library, which shows where the library is + show(&mut h, "library"); + let library = rect(&h, "dialog:window"); show(&mut h, "display"); // Then the window is as wide as on a tab without a path - assert!(same(general, rect(&h, "dialog:window")), "General is {general:?} with a long path, Display is {:?}", rect(&h, "dialog:window")); - show(&mut h, "general"); - assert!(screen.contains_rect(general), "Settings {general:?} runs off the {screen:?} window"); + assert!(same(library, rect(&h, "dialog:window")), "Library is {library:?} with a long path, Display is {:?}", rect(&h, "dialog:window")); + show(&mut h, "library"); + assert!(screen.contains_rect(library), "Settings {library:?} runs off the {screen:?} window"); // And the path is cut short, inside the window let location = rect(&h, "text:settingsLocation"); let room = rect(&h, "settings:pageRoom"); @@ -209,7 +209,7 @@ fn a_long_library_folder_is_cut_short_and_its_tooltip_has_all_of_it() { fn a_short_path_is_shown_whole_and_has_no_tooltip() { // Given the in-memory library, whose Location is a short sentence let mut h = demo([1600.0, 1000.0]); - show(&mut h, "general"); + show(&mut h, "library"); assert!(h.painted_text().iter().any(|text| text == "In memory — nothing is saved"), "it is all there"); let before = h.painted_text().len(); // When the pointer rests on it @@ -237,11 +237,11 @@ fn a_page_that_goes_on_below_shows_a_scroll_handle_without_the_pointer_on_it() { let room = rect(h, "settings:pageRoom"); other_than(&h.paint(), egui::Rect::from_min_max(egui::pos2(room.right() - 6.0, room.top()), room.max), chrome) }; - // Given Import, which is taller than the room a 560 pt tall app window has for it - show(&mut h, "import"); + // Given Appearance, which is taller than the room a 560 pt tall app window has for it + show(&mut h, "interface"); assert!(rect(&h, "settings:page").height() > rect(&h, "settings:pageRoom").height()); // Then a handle is drawn at the page's right edge - assert!(handle(&h) > 40, "Import shows a scroll handle ({} px)", handle(&h)); + assert!(handle(&h) > 40, "Appearance shows a scroll handle ({} px)", handle(&h)); // And Display, which fits, has none show(&mut h, "display"); assert!(rect(&h, "settings:page").height() <= rect(&h, "settings:pageRoom").height()); @@ -275,10 +275,10 @@ fn a_window_too_short_for_a_page_of_its_own_scrolls_tabs_and_page_together() { fn the_tabs_stay_put_while_a_page_scrolls() { // Given a page taller than the window has room for let mut h = demo([900.0, 560.0]); - show(&mut h, "import"); + show(&mut h, "interface"); let window = rect(&h, "dialog:window"); let tabs: Vec = TABS.iter().map(|(id, _)| rect(&h, &format!("button:settingsTab-{id}"))).collect(); - let page_before = rect(&h, "check:settings.perCamera"); + let page_before = rect(&h, "button:settingsAppearance-0"); // When the page is scrolled h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); for _ in 0..3 { @@ -287,7 +287,7 @@ fn the_tabs_stay_put_while_a_page_scrolls() { } h.settle(T); // Then the page moved - let page_after = rect(&h, "check:settings.perCamera"); + let page_after = rect(&h, "button:settingsAppearance-0"); assert!(page_after.top() < page_before.top() - 50.0, "the page scrolled: {page_before:?} -> {page_after:?}"); // And the tabs and the window did not for ((id, _), before) in TABS.iter().zip(tabs) { @@ -299,25 +299,25 @@ fn the_tabs_stay_put_while_a_page_scrolls() { #[test] fn each_tab_remembers_how_far_it_was_scrolled() { let mut h = demo([900.0, 560.0]); - show(&mut h, "interface"); - let fresh = rect(&h, "button:settingsAppearance-0"); - // Given Import scrolled down show(&mut h, "import"); + let fresh = rect(&h, "check:settings.perCamera"); + // Given Appearance scrolled down + show(&mut h, "interface"); let window = rect(&h, "dialog:window"); - let top = rect(&h, "check:settings.perCamera").top(); + let top = rect(&h, "button:settingsAppearance-0").top(); h.request("ui.move", json!({"x": window.center().x, "y": window.center().y}), T); for _ in 0..3 { h.request("ui.scroll", json!({"dy": -120.0}), T); h.step(); } h.settle(T); - let scrolled = rect(&h, "check:settings.perCamera").top(); + let scrolled = rect(&h, "button:settingsAppearance-0").top(); assert!(scrolled < top - 50.0); // When another tab is opened, it starts at its top - show(&mut h, "interface"); - let mode = rect(&h, "button:settingsAppearance-0"); - assert!(same(fresh, mode), "Interface is at its top, as when first opened: {fresh:?} -> {mode:?}"); - // And Import is where it was left show(&mut h, "import"); - assert!((rect(&h, "check:settings.perCamera").top() - scrolled).abs() < 0.5, "Import is where it was left"); + let mode = rect(&h, "check:settings.perCamera"); + assert!(same(fresh, mode), "Import is at its top, as when first opened: {fresh:?} -> {mode:?}"); + // And Appearance is where it was left + show(&mut h, "interface"); + assert!((rect(&h, "button:settingsAppearance-0").top() - scrolled).abs() < 0.5, "Appearance is where it was left"); } diff --git a/crates/ui-egui/src/tests_dialog_settings_groups.rs b/crates/ui-egui/src/tests_dialog_settings_groups.rs new file mode 100644 index 00000000000..99d29ac3683 --- /dev/null +++ b/crates/ui-egui/src/tests_dialog_settings_groups.rs @@ -0,0 +1,164 @@ +//! The Settings tabs are grouped by what a person comes to do: the library itself (where it is, +//! what leaves it by itself) under Library; what is written beside and opened from the photo +//! files under Files; and the tabs for the monitor and for how LightCraft looks named for that. +//! +//! Before, General held the library's location beside the language and the external editors, +//! XMP sidecar writing (which governs every later edit) sat under Import, and forgetting unchanged +//! photos (catalog housekeeping) under Performance. "Display" was the monitor's colour profile and +//! "Interface" was how the app looks. + +use std::time::Duration; + +use serde_json::json; + +use crate::headless::Headless; +use crate::panels::settings::TABS; +use crate::state::Dialog; +use crate::{LightcraftApp, Services}; + +const T: Duration = Duration::from_secs(20); + +fn demo() -> Headless { + let mut h = Headless::new(LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services::default()), [1200.0, 1000.0], 1.0); + // let the first renders finish (a render still running at exit can crash in GPU teardown) + h.settle(T); + h +} + +fn show(h: &mut Headless, tab: &str) { + let r = h.request("engine.execute", json!({"command": "app.settings", "params": {"tab": tab}}), T); + assert_eq!(r["ok"], true, "app.settings {tab}: {r}"); + h.settle(T); + for _ in 0..4 { + h.step(); + } +} + +/// Every section heading of the open page, top to bottom (`heading:{its English name}`). +fn headings(h: &Headless) -> Vec { + let mut found: Vec<(f32, String)> = + h.app.widgets.iter().filter_map(|(id, r)| Some((r.top(), id.strip_prefix("heading:")?.to_string()))).collect(); + found.sort_by(|a, b| a.0.total_cmp(&b.0)); + found.into_iter().map(|(_, text)| text).collect() +} + +#[test] +fn the_tabs_are_named_and_ordered_for_what_they_hold() { + let names: Vec<(&str, &str)> = TABS.iter().take(9).map(|(id, label)| (*id, crate::panels::settings::tab_label(id, label))).collect(); + assert_eq!( + names, + [ + ("general", "General"), + ("library", "Library"), + ("import", "Import"), + ("files", "Files"), + ("performance", "Performance"), + ("display", "Monitor"), + ("interface", "Appearance"), + ("faces", "Faces"), + ("denoise", "AI Denoise"), + ] + ); +} + +#[test] +fn each_section_is_under_the_tab_a_person_would_look_in() { + let mut h = demo(); + // (every heading a page has, so a section that turns up on a tab it does not belong to is seen) + let mut under = |tab: &str| { + show(&mut h, tab); + headings(&h) + }; + // General is about the app as a whole + assert_eq!(under("general"), ["Startup", "Culling"]); + // Library is the library itself: where it is, and what leaves it by itself + assert_eq!(under("library"), ["Library", "Local folders"]); + // Import is what happens to photos as they come in + assert_eq!(under("import"), ["Raw defaults", "Other images (JPEG, PNG, TIFF, HEIC…)", "Metadata", "Auto Import"]); + // Files is what is written beside the photo files and what they are opened in + assert_eq!(under("files"), ["XMP sidecars", "External Editing"]); + // Performance is speed and the cache that buys it + assert_eq!(under("performance"), ["Rendering", "Thumbnail cache"]); + assert_eq!(under("display"), ["Monitor profile"]); + assert_eq!(under("interface"), ["Appearance", "Filmstrip", "Grid", "Detail"]); + // Faces and AI Denoise are as they were (here without a way to download models) + assert_eq!(under("faces"), ["Face recognition"]); + assert_eq!(under("denoise"), ["AI Denoise"]); + // And every tab there is was looked at + assert_eq!(TABS.len(), 9, "a new tab needs its sections listed here"); +} + +#[test] +fn what_is_saved_with_a_library_in_memory_says_it_will_not_last() { + let mut h = demo(); + let note = "In-memory session: these settings last until LightCraft quits."; + for tab in ["library", "import", "files"] { + show(&mut h, tab); + assert!(h.painted_text().iter().any(|text| text == note), "{tab} says so"); + } + show(&mut h, "general"); + assert!(!h.painted_text().iter().any(|text| text == note), "General is saved on this computer"); +} + +#[test] +fn every_tab_id_from_before_still_opens_its_tab() { + let mut h = demo(); + // Given the ids agents, the docs and the rest of the app have used so far, and the two new ones + for id in ["general", "import", "performance", "display", "interface", "faces", "denoise", "library", "files"] { + show(&mut h, id); + assert_eq!(h.app.ui.dialog, Some(Dialog::Settings { tab: id.into() }), "{id}"); + } + // And an id that names no tab is refused, saying which there are + let r = h.request("engine.execute", json!({"command": "app.settings", "params": {"tab": "nowhere"}}), T); + assert_eq!(r["ok"], false, "{r}"); + assert!(r.to_string().contains("library") && r.to_string().contains("files"), "the refusal lists the tabs: {r}"); +} + +#[test] +fn controls_keep_their_names_where_they_moved_to() { + let mut h = demo(); + let has = |h: &Headless, id: &str| h.app.widgets.iter().any(|(w, _)| w == id); + // (what scripts and agents click is found by the same name on its new tab) + show(&mut h, "library"); + assert!(has(&h, "button:settingsOpenLibrary") && has(&h, "text:settingsLocation") && has(&h, "button:settingsForgetLocal-0")); + show(&mut h, "files"); + assert!(has(&h, "check:settings.autoWriteXmp") && has(&h, "field:externalEditor") && has(&h, "field:photocraftPath")); + show(&mut h, "general"); + assert!(has(&h, "button:settingsLanguage-0") && has(&h, "check:settings.autoAdvance")); + assert!(!has(&h, "button:settingsOpenLibrary") && !has(&h, "field:externalEditor"), "and no longer on General"); + show(&mut h, "import"); + assert!(has(&h, "field:settings.copyright") && !has(&h, "check:settings.autoWriteXmp")); + show(&mut h, "performance"); + assert!(has(&h, "button:settingsClearCache") && !has(&h, "button:settingsForgetLocal-0")); +} + +#[test] +fn a_library_on_disk_has_its_smart_previews_folder_under_library() { + let dir = std::env::temp_dir().join(format!("lc-ui-settings-groups-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let mut session = lightcraft_engine::Session::new().with_fs(); + session.open_library(&dir, true).unwrap(); + let mut h = Headless::new(LightcraftApp::new(session, Services::default()), [1200.0, 1000.0], 1.0); + h.settle(T); + show(&mut h, "performance"); + let on_performance = headings(&h); + show(&mut h, "library"); + let on_library = headings(&h); + drop(h); + let _ = std::fs::remove_dir_all(&dir); + // (where a library keeps its files is the library's; Performance keeps rendering and the cache) + assert_eq!(on_library, ["Library", "Smart previews", "Local folders"]); + assert_eq!(on_performance, ["Rendering", "Thumbnail cache"]); +} + +#[test] +fn the_tab_bar_shows_the_names_people_read() { + let mut h = demo(); + show(&mut h, "general"); + let texts = h.painted_text(); + for name in ["General", "Library", "Import", "Files", "Performance", "Monitor", "Appearance", "Faces", "AI Denoise"] { + assert!(texts.iter().any(|text| text == name), "the tab bar has {name}"); + } + assert!(!texts.iter().any(|text| text == "Display" || text == "Interface"), "and not the names from before"); +} diff --git a/crates/ui-egui/src/tests_dialog_settings_tabs.rs b/crates/ui-egui/src/tests_dialog_settings_tabs.rs index e64c1964dc8..e7b00fcdd80 100644 --- a/crates/ui-egui/src/tests_dialog_settings_tabs.rs +++ b/crates/ui-egui/src/tests_dialog_settings_tabs.rs @@ -141,16 +141,16 @@ fn a_tab_reached_with_the_keyboard_shows_the_focus() { run(&mut h, "view.theme", json!({"theme": kind.id()})); let t = Tokens::for_kind(kind); show(&mut h, "general"); - let import = tab(&h, "import"); + let import = tab(&h, "library"); let ring = |h: &Headless| ring(&h.paint(), import, t.text); - // Given no tab has the focus, there is no ring round Import + // Given no tab has the focus, there is no ring round Library assert!(ring(&h) < 8, "{kind:?}: no ring before ({})", ring(&h)); - // When Tab is pressed twice (General, then Import) + // When Tab is pressed twice (General, then Library) key(&mut h, "Tab"); key(&mut h, "Tab"); - // Then a ring in the text colour runs round Import + // Then a ring in the text colour runs round Library let length = import.width() + 2.0 * import.height(); - assert!(ring(&h) as f32 > 1.5 * length, "{kind:?}: Import shows the focus ({} px of ring along {length} pt)", ring(&h)); + assert!(ring(&h) as f32 > 1.5 * length, "{kind:?}: Library shows the focus ({} px of ring along {length} pt)", ring(&h)); // And it is still General that is open: the focus is not the choice assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "general".into() })); } @@ -169,16 +169,16 @@ fn the_arrow_keys_move_along_the_tabs_and_space_opens_one() { key(&mut h, "ArrowRight"); key(&mut h, "ArrowRight"); // Then the focus is on the third tab, and nothing has opened yet - assert!(ring(&h, "performance") > 60, "Performance has the focus"); - assert!(ring(&h, "general") < 60 && ring(&h, "import") < 60, "and no other tab has"); + assert!(ring(&h, "import") > 60, "Import has the focus"); + assert!(ring(&h, "general") < 60 && ring(&h, "library") < 60, "and no other tab has"); assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "general".into() })); // And ← goes back one key(&mut h, "ArrowLeft"); - assert!(ring(&h, "import") > 60, "Import has the focus"); + assert!(ring(&h, "library") > 60, "Library has the focus"); // When Space is pressed, that tab opens and keeps the focus key(&mut h, "Space"); - assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "import".into() })); - assert!(ring(&h, "import") > 60, "Import still has the focus"); + assert_eq!(h.app.ui.dialog, Some(crate::state::Dialog::Settings { tab: "library".into() })); + assert!(ring(&h, "library") > 60, "Library still has the focus"); } #[test] diff --git a/crates/ui-egui/src/tests_dialog_settings_trust.rs b/crates/ui-egui/src/tests_dialog_settings_trust.rs index 98880b21f6b..078781afbe7 100644 --- a/crates/ui-egui/src/tests_dialog_settings_trust.rs +++ b/crates/ui-egui/src/tests_dialog_settings_trust.rs @@ -224,7 +224,7 @@ fn deleting_the_smart_previews_is_asked_about_when_the_folder_is_chosen() { let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); assert_eq!(smart(&mut h)["count"], 1); - show(&mut h, "performance"); + show(&mut h, "library"); // Given "Delete them" chosen for the previews already built click(&mut h, "button:settingsSmartExisting-2"); // When a new folder is chosen @@ -252,7 +252,7 @@ fn saying_yes_deletes_the_smart_previews_and_changes_the_folder() { let dir = TempFolder::new("settings-trust-smart-yes"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); click(&mut h, "button:settingsSmartExisting-2"); click(&mut h, "button:settingsSmartChoose"); assert_eq!(smart(&mut h)["count"], 1); @@ -268,7 +268,7 @@ fn moving_the_smart_previews_needs_no_question() { let dir = TempFolder::new("settings-trust-smart-move"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); click(&mut h, "button:settingsSmartChoose"); let now = smart(&mut h); assert_eq!((now["count"].clone(), now["custom"].clone()), (json!(1), json!(true)), "{now}"); @@ -278,7 +278,7 @@ fn moving_the_smart_previews_needs_no_question() { #[test] fn writing_xmp_by_itself_says_what_is_written_where() { let mut h = demo(); - show(&mut h, "import"); + show(&mut h, "files"); assert!(says(&h, "beside the photo"), "{:?}", h.painted_text().iter().filter(|t| t.contains("XMP")).collect::>()); } @@ -301,7 +301,7 @@ fn a_question_left_unanswered_is_gone_when_settings_is_opened_again() { let dir = TempFolder::new("settings-trust-smart-left"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); // Given the question about deleting, left unanswered click(&mut h, "button:settingsSmartExisting-2"); click(&mut h, "button:settingsSmartChoose"); @@ -309,7 +309,7 @@ fn a_question_left_unanswered_is_gone_when_settings_is_opened_again() { // When Settings is closed and opened again key(&mut h, "Escape"); assert!(h.app.ui.dialog.is_none()); - show(&mut h, "performance"); + show(&mut h, "library"); // Then nothing waits: no question, and the choice is back at "Move them" assert!(!has(&h, "button:settingsSmartDelete"), "the question does not outlive Settings"); click(&mut h, "button:settingsSmartChoose"); @@ -323,7 +323,7 @@ fn a_question_asked_in_one_library_is_not_there_in_another() { let (library_b, folder_b) = another_library(&dir); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); // Given the question about deleting asked in one library, and left click(&mut h, "button:settingsSmartExisting-2"); click(&mut h, "button:settingsSmartChoose"); @@ -332,7 +332,7 @@ fn a_question_asked_in_one_library_is_not_there_in_another() { // When another library is opened and its Settings looked at h.app.run("app.openLibrary", json!({"path": library_b})).unwrap(); h.settle(T); - show(&mut h, "performance"); + show(&mut h, "library"); // Then that library is not asked anything, and its smart previews are where they were assert!(!has(&h, "button:settingsSmartDelete"), "the question belongs to the library it was asked in"); let now = smart(&mut h); @@ -344,7 +344,7 @@ fn a_change_made_another_way_takes_the_question_away() { let dir = TempFolder::new("settings-trust-smart-other-way"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); click(&mut h, "button:settingsSmartExisting-2"); click(&mut h, "button:settingsSmartChoose"); assert!(has(&h, "button:settingsSmartDelete")); @@ -363,7 +363,7 @@ fn use_library_folder_asks_before_deleting_too() { let dir = TempFolder::new("settings-trust-smart-reset"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); // Given the previews moved to a chosen folder, then "Delete them" chosen click(&mut h, "button:settingsSmartChoose"); assert_eq!(smart(&mut h)["custom"], true); @@ -394,14 +394,14 @@ fn text_typed_in_copyright_is_saved_when_another_tab_is_opened() { #[test] fn esc_in_an_external_editing_box_leaves_settings_open_too() { let mut h = demo(); - show(&mut h, "general"); + show(&mut h, "files"); let before = h.app.ui.settings.external_editor.clone(); click(&mut h, "field:externalEditor"); h.request("ui.text", json!({"text": "Example Editor"}), T); steps(&mut h); key(&mut h, "Escape"); assert_eq!(h.app.ui.settings.external_editor, before, "Esc gives the text back"); - assert!(settings_open(&h, "general"), "and Settings stays open: {:?}", h.app.ui.dialog); + assert!(settings_open(&h, "files"), "and Settings stays open: {:?}", h.app.ui.dialog); } #[test] @@ -424,7 +424,7 @@ fn a_question_about_a_folder_that_has_changed_since_deletes_nothing() { let dir = TempFolder::new("settings-trust-smart-outside"); let to = dir.path("elsewhere"); let mut h = with_smart_preview(&dir, &to); - show(&mut h, "performance"); + show(&mut h, "library"); click(&mut h, "button:settingsSmartExisting-2"); click(&mut h, "button:settingsSmartChoose"); assert!(has(&h, "button:settingsSmartDelete")); diff --git a/docs/display-profiles.md b/docs/display-profiles.md index 67892a3cbba..ee715eaef4d 100644 --- a/docs/display-profiles.md +++ b/docs/display-profiles.md @@ -18,7 +18,7 @@ would correct twice; KWin keeps that profile in its own settings, not colord, so ## Using it -Settings ▸ Display ▸ **Choose Profile…** picks an `.icc` / `.icm` file (the dialog opens where the system keeps +Settings ▸ Monitor ▸ **Choose Profile…** picks an `.icc` / `.icm` file (the dialog opens where the system keeps them: `~/.local/share/icc` on Linux, ColorSync's folders on macOS, `…\spool\drivers\color` on Windows). **Use sRGB** (on macOS and Linux **Use Screen Profile**) goes back to no profile. The choice is an app setting (`ui.json`, `displayProfile`) and applies at once; a file that can't be used is reported there and previews stay sRGB. diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 7bb187811c1..23d7d0665df 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -424,7 +424,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts). | Id | Feature | Tier | Status | Evidence | Missing / notes | |---|---|---|---|---|---| -| LR-PREF-GENERAL | General settings | P0 | ✅ | `cmd:app.settings`, `cmd:app.openLibrary`, `crates/ui-egui/src/panels/settings.rs`, `crates/ui-egui/src/panels/notices.rs` | General / Import / Performance / Display / Interface tabs; app settings in ui.json (written atomically, saved when the library changes and every few seconds), library settings in prefs.json; a damaged settings file is kept as `.corrupt-