LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
UI: add favorite themes and appearance shortcuts
Luniiya43662e695911
diff --git a/crates/ui-egui/locales/de.json b/crates/ui-egui/locales/de.jsonindex 27d2c2aa2..a374d35e2 100644--- a/crates/ui-egui/locales/de.json+++ b/crates/ui-egui/locales/de.json@@ -2044,5 +2044,8 @@"Downloading model": "Modell wird heruntergeladen","Finding faces": "Gesichter werden gesucht","Synchronizing folder": "Ordner wird synchronisiert",- "Looking for changes": "Änderungen werden gesucht"+ "Looking for changes": "Änderungen werden gesucht",+ "Appearance Settings…": "Erscheinungsbild-Einstellungen…",+ "Add to favorites": "Zu Favoriten hinzufügen",+ "Remove from favorites": "Aus Favoriten entfernen"}diff --git a/crates/ui-egui/locales/es.json b/crates/ui-egui/locales/es.jsonindex bf4911bfb..9f189b733 100644--- a/crates/ui-egui/locales/es.json+++ b/crates/ui-egui/locales/es.json@@ -1889,5 +1889,8 @@"Downloading model": "Descargando modelo","Finding faces": "Buscando caras","Synchronizing folder": "Sincronizando carpeta",- "Looking for changes": "Buscando cambios"+ "Looking for changes": "Buscando cambios",+ "Appearance Settings…": "Ajustes de apariencia…",+ "Add to favorites": "Añadir a favoritos",+ "Remove from favorites": "Quitar de favoritos"}diff --git a/crates/ui-egui/locales/fr.json b/crates/ui-egui/locales/fr.jsonindex f3422bc0a..0430e9c5a 100644--- a/crates/ui-egui/locales/fr.json+++ b/crates/ui-egui/locales/fr.json@@ -1876,5 +1876,8 @@"Downloading model": "Téléchargement du modèle","Finding faces": "Recherche des visages","Synchronizing folder": "Synchronisation du dossier",- "Looking for changes": "Recherche des modifications"+ "Looking for changes": "Recherche des modifications",+ "Appearance Settings…": "Réglages d’apparence…",+ "Add to favorites": "Ajouter aux favoris",+ "Remove from favorites": "Retirer des favoris"}diff --git a/crates/ui-egui/locales/ja.json b/crates/ui-egui/locales/ja.jsonindex 66e0d179f..5fb2588af 100644--- a/crates/ui-egui/locales/ja.json+++ b/crates/ui-egui/locales/ja.json@@ -1891,5 +1891,8 @@"Downloading model": "モデルをダウンロード中","Finding faces": "顔を検索中","Synchronizing folder": "フォルダを同期中",- "Looking for changes": "変更を確認中"+ "Looking for changes": "変更を確認中",+ "Appearance Settings…": "外観設定…",+ "Add to favorites": "お気に入りに追加",+ "Remove from favorites": "お気に入りから削除"}diff --git a/crates/ui-egui/locales/pt-br.json b/crates/ui-egui/locales/pt-br.jsonindex eaadb8bb6..7334a0f49 100644--- a/crates/ui-egui/locales/pt-br.json+++ b/crates/ui-egui/locales/pt-br.json@@ -1889,5 +1889,8 @@"Downloading model": "Baixando modelo","Finding faces": "Procurando rostos","Synchronizing folder": "Sincronizando pasta",- "Looking for changes": "Procurando alterações"+ "Looking for changes": "Procurando alterações",+ "Appearance Settings…": "Configurações de aparência…",+ "Add to favorites": "Adicionar aos favoritos",+ "Remove from favorites": "Remover dos favoritos"}diff --git a/crates/ui-egui/locales/ru.json b/crates/ui-egui/locales/ru.jsonindex 508235243..d4bed8e6a 100644--- a/crates/ui-egui/locales/ru.json+++ b/crates/ui-egui/locales/ru.json@@ -1603,5 +1603,8 @@"Finding faces": "Поиск лиц","Quit Anyway": "Всё равно выйти","Synchronizing folder": "Синхронизация папки",- "Looking for changes": "Поиск изменений"+ "Looking for changes": "Поиск изменений",+ "Appearance Settings…": "Настройки оформления…",+ "Add to favorites": "Добавить в избранное",+ "Remove from favorites": "Удалить из избранного"}diff --git a/crates/ui-egui/locales/uk.json b/crates/ui-egui/locales/uk.jsonindex c73c05b93..5efb0e00c 100644--- a/crates/ui-egui/locales/uk.json+++ b/crates/ui-egui/locales/uk.json@@ -2070,5 +2070,8 @@"Downloading model": "Завантаження моделі","Finding faces": "Пошук облич","Synchronizing folder": "Синхронізація папки",- "Looking for changes": "Пошук змін"+ "Looking for changes": "Пошук змін",+ "Appearance Settings…": "Налаштування вигляду…",+ "Add to favorites": "Додати до вибраного",+ "Remove from favorites": "Видалити з вибраного"}diff --git a/crates/ui-egui/locales/zh-hans.json b/crates/ui-egui/locales/zh-hans.jsonindex 5cf956ebd..8500cebf0 100644--- a/crates/ui-egui/locales/zh-hans.json+++ b/crates/ui-egui/locales/zh-hans.json@@ -1889,5 +1889,8 @@"Downloading model": "正在下载模型","Finding faces": "正在查找人脸","Synchronizing folder": "正在同步文件夹",- "Looking for changes": "正在查找更改"+ "Looking for changes": "正在查找更改",+ "Appearance Settings…": "外观设置…",+ "Add to favorites": "添加到收藏",+ "Remove from favorites": "从收藏中移除"}diff --git a/crates/ui-egui/locales/zh-hant.json b/crates/ui-egui/locales/zh-hant.jsonindex ec24d431f..de59fb15f 100644--- a/crates/ui-egui/locales/zh-hant.json+++ b/crates/ui-egui/locales/zh-hant.json@@ -1889,5 +1889,8 @@"Downloading model": "正在下載模型","Finding faces": "正在尋找臉孔","Synchronizing folder": "正在同步資料夾",- "Looking for changes": "正在尋找變更"+ "Looking for changes": "正在尋找變更",+ "Appearance Settings…": "外觀設定…",+ "Add to favorites": "加入最愛",+ "Remove from favorites": "從最愛移除"}diff --git a/crates/ui-egui/src/headless.rs b/crates/ui-egui/src/headless.rsindex 171ee9b73..381af6773 100644--- a/crates/ui-egui/src/headless.rs+++ b/crates/ui-egui/src/headless.rs@@ -3135,9 +3135,10 @@ mod tests {assert_eq!(h.app.ui.settings.startup_view, crate::state::StartupView::Detail);// Interface: filmstrip names off, grid badges alwaysh.request("ui.clickWidget", json!({"id": "button:settingsTab-interface"}), t);- // Appearance cards sit above these controls; scroll the compact settings viewport.+ // Appearance cards (one row per theme, with its favorite star) sit above these controls;+ // scroll the compact settings viewport past them.h.request("ui.hoverWidget", json!({"id": "radio:theme-charcoal"}), t);- h.request("ui.scroll", json!({"dy": -350.0}), t);+ h.request("ui.scroll", json!({"dy": -700.0}), t);for _ in 0..4 {h.step();}@@ -3145,7 +3146,7 @@ mod tests {assert!(!h.app.ui.settings.film_names);h.request("ui.clickWidget", json!({"id": "button:settingsGridBadges-1"}), t);assert_eq!(h.app.ui.settings.grid_badges, crate::state::GridBadges::Always);- h.request("ui.scroll", json!({"dy": 350.0}), t);+ h.request("ui.scroll", json!({"dy": 700.0}), t);for _ in 0..4 {h.step();}diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rsindex a6998a7ee..0e590ccc7 100644--- a/crates/ui-egui/src/panels/settings.rs+++ b/crates/ui-egui/src/panels/settings.rs@@ -637,9 +637,9 @@ fn appearance(ui: &mut egui::Ui, t: &Tokens, s: &mut crate::state::AppSettings,let mut cards = |ui: &mut egui::Ui, width: f32| {ui.spacing_mut().item_spacing.x = 12.0;let light: Vec<_> = LightTheme::ALL.iter().map(|l| (*l, l.kind())).collect();- theme_card(ui, t, "Light Theme", light_active, &light, &mut s.light_theme, width);+ theme_card(ui, t, "Light Theme", light_active, &light, &mut s.light_theme, &mut s.favorite_themes, width);let dark: Vec<_> = DarkTheme::ALL.iter().map(|d| (*d, d.kind())).collect();- theme_card(ui, t, "Dark Theme", !light_active, &dark, &mut s.dark_theme, width);+ theme_card(ui, t, "Dark Theme", !light_active, &dark, &mut s.dark_theme, &mut s.favorite_themes, width);};if available < 440.0 {ui.vertical(|ui| cards(ui, available));@@ -658,6 +658,7 @@ fn theme_card<V: PartialEq + Copy>(active: bool,options: &[(V, crate::theme::ThemeKind)],value: &mut V,+ favorites: &mut Vec<String>,width: f32,) {egui::Frame::new()@@ -677,12 +678,47 @@ fn theme_card<V: PartialEq + Copy>(});let shown = options.iter().find(|(v, _)| v == value).or(options.first()).map(|(_, k)| *k).unwrap_or_default();theme_preview(ui, shown, inner);- ui.horizontal(|ui| {- for (v, kind) in options {+ for (v, kind) in options {+ let row = egui::Rect::from_min_size(ui.cursor().min, egui::vec2(ui.available_width(), 24.0));+ let hovered = ui.ctx().pointer_hover_pos().is_some_and(|p| row.contains(p));+ ui.horizontal(|ui| {let r = ui.radio_value(value, *v, crate::i18n::tr(kind.label()));register(ui.ctx(), format!("radio:theme-{}", kind.id()), r.rect);- }- });+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {+ let favorite = favorites.iter().any(|id| id == kind.id());+ let r = ui+ .add_visible(favorite || hovered, egui::Button::new("").min_size(egui::vec2(24.0, 24.0)).frame(false))+ .on_hover_text(crate::i18n::tr(if favorite { "Remove from favorites" } else { "Add to favorites" }));+ r.widget_info(|| {+ egui::WidgetInfo::labeled(+ egui::WidgetType::Button,+ true,+ format!(+ "{}: {}",+ crate::i18n::tr(if favorite { "Remove from favorites" } else { "Add to favorites" }),+ crate::i18n::tr(kind.label())+ ),+ )+ });+ register(ui.ctx(), format!("button:themeFavorite-{}", kind.id()), r.rect);+ if favorite || hovered {+ crate::icons::paint(+ ui.painter(),+ r.rect.shrink(4.0),+ if favorite { crate::icons::Icon::StarFilled } else { crate::icons::Icon::Star },+ if favorite { t.accent } else { t.text_dim },+ );+ }+ if r.clicked() {+ if favorite {+ favorites.retain(|id| id != kind.id());+ } else {+ favorites.push(kind.id().into());+ }+ }+ });+ });+ }});});}diff --git a/crates/ui-egui/src/panels/topbar.rs b/crates/ui-egui/src/panels/topbar.rsindex 68543bac1..a95805f83 100644--- a/crates/ui-egui/src/panels/topbar.rs+++ b/crates/ui-egui/src/panels/topbar.rs@@ -198,6 +198,30 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {if resp.clicked() {let _ = app.run("view.appearance", json!({}));}+ resp.context_menu(|ui| {+ let settings = ui.button(crate::i18n::tr("Appearance Settings…"));+ register(ui.ctx(), "menu:appearanceSettings", settings.rect);+ if settings.clicked() {+ let _ = app.run("app.settings", json!({"tab": "interface"}));+ ui.close();+ }+ let favorites = app.ui.settings.favorite_themes.clone();+ for dark in [false, true] {+ let group: Vec<_> =+ crate::theme::ThemeKind::ALL.iter().filter(|k| k.is_dark() == dark && favorites.iter().any(|id| id == k.id())).collect();+ if !group.is_empty() {+ ui.separator();+ }+ for kind in group {+ let r = ui.selectable_label(app.ui.settings.theme(app.system_theme(ui.ctx())) == *kind, crate::i18n::tr(kind.label()));+ register(ui.ctx(), format!("menu:themeFavorite-{}", kind.id()), r.rect);+ if r.clicked() {+ let _ = app.run("view.theme", json!({"theme": kind.id()}));+ ui.close();+ }+ }+ }+ });let _ = Align2::CENTER_CENTER;});}diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 3ac0bd68e..7f0cc61b4 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -223,6 +223,9 @@ pub struct AppSettings {pub dark_theme: DarkTheme,/// The theme of the light appearance.pub light_theme: LightTheme,+ /// Theme shortcuts in the appearance context menu.+ #[serde(deserialize_with = "deserialize_favorite_themes")]+ pub favorite_themes: Vec<String>,/// The monitor's ICC profile previews are shown through (`app.displayProfile`; "" = none:/// the display is treated as sRGB).pub display_profile: String,@@ -245,6 +248,7 @@ impl Default for AppSettings {appearance_mode: AppearanceMode::Dark,dark_theme: DarkTheme::Charcoal,light_theme: LightTheme::Silver,+ favorite_themes: Vec::new(),display_profile: String::new(),}}@@ -1033,3 +1037,14 @@ impl UiState {self}}++fn deserialize_favorite_themes<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Vec<String>, D::Error> {+ let values = Vec::<String>::deserialize(d)?;+ let mut seen = std::collections::BTreeSet::new();+ for id in &values {+ if !crate::theme::ThemeKind::ALL.iter().any(|k| k.id() == id) || !seen.insert(id) {+ return Err(serde::de::Error::custom("unknown or duplicate favorite theme"));+ }+ }+ Ok(values)+}diff --git a/crates/ui-egui/src/tests_appearance.rs b/crates/ui-egui/src/tests_appearance.rsindex 2f4ab65ae..947e6cf9f 100644--- a/crates/ui-egui/src/tests_appearance.rs+++ b/crates/ui-egui/src/tests_appearance.rs@@ -195,3 +195,53 @@ fn interface_settings_fit_small_windows_and_stack_theme_choices() {assert!(silver.right() <= window.right(), "theme choices stay inside the modal");}}++#[test]+fn favorites_validate_roundtrip_and_stars_toggle_without_selecting() {+ for bad in [json!(["paper", "paper"]), json!(["unknown"]), json!([3]), json!("paper")] {+ assert!(serde_json::from_value::<AppSettings>(json!({"favoriteThemes": bad})).is_err());+ }+ let mut h = Headless::new(app(), [1400.0, 900.0], 1.0);+ h.app.ui.dialog = Some(crate::state::Dialog::Settings { tab: "interface".into() });+ for _ in 0..4 {+ h.step();+ }+ assert_eq!(h.request("ui.hoverWidget", json!({"id": "radio:theme-paper"}), T)["ok"], true);+ h.step();+ assert_eq!(h.request("ui.clickWidget", json!({"id": "button:themeFavorite-paper"}), T)["ok"], true);+ h.step();+ assert_eq!(h.app.ui.settings.favorite_themes, vec!["paper"]);+ if let Some(path) = std::env::var_os("FAVORITES_SCREENSHOT_DIR") {+ h.request("ui.scroll", json!({"dy": -90.0}), T);+ for _ in 0..4 {+ h.step();+ }+ let pixels = h.paint();+ let image =+ lightcraft_raster::Rgba8 { width: pixels.size[0], height: pixels.size[1], data: pixels.pixels.iter().map(|c| c.to_array()).collect() };+ let png = lightcraft_codecs::encode_png(&lightcraft_codecs::EncodeImage::rgba8(&image), &lightcraft_codecs::EncodeMeta::default()).unwrap();+ std::fs::create_dir_all(&path).unwrap();+ std::fs::write(std::path::Path::new(&path).join("lightcraft-favorites.png"), png).unwrap();+ }+ assert_eq!(h.app.ui.settings.light_theme, LightTheme::Silver, "starring does not select");+ let saved = serde_json::to_value(&h.app.ui.settings).unwrap();+ assert_eq!(serde_json::from_value::<AppSettings>(saved).unwrap(), h.app.ui.settings);+ assert_eq!(h.request("ui.clickWidget", json!({"id": "button:themeFavorite-paper"}), T)["ok"], true);+ h.step();+ assert!(h.app.ui.settings.favorite_themes.is_empty());+ h.app.ui.dialog = None;+ h.app.ui.settings.favorite_themes = vec!["midnight".into(), "paper".into()];+ h.step();+ assert_eq!(h.request("ui.clickWidget", json!({"id": "icon:appearance", "button": "right"}), T)["ok"], true);+ h.step();+ h.step();+ let light = h.app.widgets.iter().find(|(id, _)| id == "menu:themeFavorite-paper").unwrap().1;+ let dark = h.app.widgets.iter().find(|(id, _)| id == "menu:themeFavorite-midnight").unwrap().1;+ assert!(light.top() < dark.top(), "light favorites precede dark favorites");+ assert_eq!(h.request("ui.clickWidget", json!({"id": "menu:themeFavorite-paper"}), T)["ok"], true);+ h.step();+ h.step();+ assert_eq!(h.app.ui.settings.appearance_mode, AppearanceMode::Light);+ assert_eq!(h.app.ui.settings.light_theme, LightTheme::Paper);+ assert_eq!(h.app.ui.settings.dark_theme, DarkTheme::Charcoal);+}diff --git a/docs/parity.md b/docs/parity.mdindex ac04a8395..4d81d1e4c 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -489,7 +489,7 @@ under the UI command that wraps it (a no-op error); the UI command now wins.| 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-<time>` and reported, an unreadable one is not overwritten that session (`library.info` → `settingsWarnings`); quitting with unsaved changes retries, then asks || LR-PREF-LOCALSTORAGE | Storage & cache | P1 | ✅ | `cmd:library.preferences`, `cmd:library.clearPreviews`, `cmd:library.compact` | thumbnail cache size + clear in Settings → Performance; library location + Open Library… in General || LR-PREF-ACCOUNT | Account | OOS | 🚫 | | |-| LR-PREF-INTERFACE | Interface options | P1 | ✅ | `cmd:app.settings`, `cmd:view.appearance`, `cmd:view.theme` | Appearance Mode (Sync with System / Dark / Light; the top bar button cycles Auto, Light, Dark) with separate dark (Charcoal, Midnight) and light (Silver, Paper) themes previewed in cards; filmstrip names/badges, grid badges (auto/always/never), square-grid names, navigator, info overlay |+| LR-PREF-INTERFACE | Interface options | P1 | ✅ | `cmd:app.settings`, `cmd:view.appearance`, `cmd:view.theme` | Appearance Mode (Sync with System / Dark / Light; the top bar button cycles Auto, Light, Dark) with separate dark (Charcoal, Midnight) and light (Silver, Paper) themes previewed in cards; hover stars persist favorite themes, the appearance button context menu opens Interface settings and lists light favorites before dark favorites; filmstrip names/badges, grid badges (auto/always/never), square-grid names, navigator, info overlay || LR-PREF-DISPLAY | Monitor (display) colour management | P1 | 🟡 | `cmd:app.displayProfile`, `crates/codecs/src/display.rs`, `crates/engine/src/display.rs`, `crates/ui-egui/src/panels/settings.rs`, `docs/display-profiles.md` | Settings ▸ Display: a monitor ICC profile (matrix/TRC exactly, LUT-based through the CMS) chosen by hand; the loupe, Before, Compare, hover previews and the second window render into the display's primaries (its full gamut, CPU and GPU), thumbnails and stand-ins are converted from sRGB; histogram, preview caches and exports stay sRGB; soft proofing's display gamut warning uses the display's gamut. Missing: picking up the profile the OS assigns (X11 `_ICC_PROFILE`, colord, ColorSync, WCS), per-monitor profiles || LR-PREF-PERFORMANCE | GPU / performance | P1 | ✅ | `cmd:app.gpu`, `cmd:app.memoryBudget`, `cmd:app.settings` | GPU on/off, preview size (Automatic = the whole-frame loupe render at canvas size, up to 2560 px; or a 1600–5120 px size for it; zoomed views add a window at up to 100 %, issue #323), memory budget (a quarter of it is the idle per-view stage caches' share; the open photo's views are counted and reported, and cut only past four times that, the before side's and the zoom window's first — a Before/After at 1:1 on a 2800 px canvas holds about 1 GB of GPU stages, plus the one 288 MB copy of the original, which `ui.inspect` reports as `sharedSourceBytes`), thumbnail cache size in Settings |