PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(ui): complete system appearance selection and styling (#2168)
Coy Geek414b7b9e4b81
diff --git a/crates/ui-egui/examples/snapshot.rs b/crates/ui-egui/examples/snapshot.rsindex c9ab51774..25ade0aa7 100644--- a/crates/ui-egui/examples/snapshot.rs+++ b/crates/ui-egui/examples/snapshot.rs@@ -6,6 +6,8 @@//! --script '[["ui.set", {"tool": "type"}], ["ui.menu.invoke", {"id": "image.imageSize"}]]'//! ```//!+//! `--system-theme light|dark|none` supplies a deterministic OS appearance for theme captures.+//!//! `--safe-gpu` draws the canvas on the CPU path, like the app's `--safe-gpu` launch.//! `--wayland-notice` previews the native file drag-and-drop guidance shown in Wayland sessions.//! `--custom-titlebar` draws the Windows/Linux title bar (caption buttons in the top bar).@@ -95,6 +97,17 @@ fn main() {v.inner_rect = Some(egui::Rect::from_min_size(egui::pos2(0.0, top), egui::vec2(w, h)));v.maximized = Some(false);}+ if let Some(appearance) = arg(&args, "--system-theme") {+ harness.input_mut().system_theme = match appearance.as_str() {+ "light" => Some(egui::Theme::Light),+ "dark" => Some(egui::Theme::Dark),+ "none" => None,+ _ => {+ eprintln!("--system-theme must be light, dark or none");+ std::process::exit(2);+ }+ };+ }harness.run_steps(4);let ctx = harness.ctx.clone();let timing = std::env::var_os("SNAPSHOT_TIMING").is_some();diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rsindex 813c643a9..f92f5546a 100644--- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs+++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs@@ -158,7 +158,8 @@ fn a_new_mask_is_targeted_so_the_next_footer_trash_keeps_its_layer() {h.state_mut().run("layer.new.layer", json!({"name": "Fresh mask"})).unwrap();let id = h.state().session.active().unwrap().active_layer.unwrap();h.run_steps(3);- let at = h.get_by_label("Add a mask (from the selection; Alt inverts)").rect().center();+ let label = format!("Add a mask (from the selection; {} inverts)", crate::shortcuts::pretty("Alt"));+ let at = h.get_by_label(&label).rect().center();click_with(&mut h, at, Modifiers::NONE);assert!(h.state().ui.mask_target && !h.state().ui.vector_mask_target);assert!(h.state().session.active().unwrap().doc.layer(id).unwrap().mask.is_some());diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 569e0e46e..319f71bfd 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -72,6 +72,7 @@ pub const UI_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[("window.theme.solarizedDark", "Solarized Dark Theme", &["Window", "Theme"], None),("window.theme.adwaita", "Adwaita Light Theme", &["Window", "Theme"], None),("window.theme.adwaitaDark", "Adwaita Dark Theme", &["Window", "Theme"], None),+ ("window.theme.system", "Sync with system", &["Window", "Theme"], None),("edit.search", "Search…", &["Edit"], Some("Cmd+F")),("help.discord", "Join the ArtCraft Discord…", &["Help"], None),("help.website", "PhotoCraft Website", &["Help"], None),@@ -307,6 +308,11 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:crate::prefs_ui::cycle_appearance(app, ctx);Ok(Value::Null)}+ "window.theme.system" => {+ app.run("prefs.set", json!({"path": "interface.appearanceMode", "value": "auto"}))?;+ crate::prefs_ui::sync_appearance(app, ctx);+ Ok(Value::Null)+ }"window.theme.pro"| "window.theme.proMedium"| "window.theme.studio"@@ -611,7 +617,8 @@ const MODE_CHECKS: [&str; 11] = ["rgb", "grayscale", "cmyk", "lab", "multichannefn checked(app: &PhotocraftApp, id: &str) -> Option<bool> {use photocraft_doc::{ColorMode, SampleType};if let Some(name) = id.strip_prefix("window.theme.").filter(|n| *n != "toggle") {- return Some(crate::theme::ThemeKind::from_name(name) == Some(app.ui.theme));+ let auto = app.session.prefs().interface.appearance_mode == photocraft_engine::prefs::AppearanceMode::Auto;+ return Some(if name == "system" { auto } else { !auto && crate::theme::ThemeKind::from_name(name) == Some(app.ui.theme) });}if let Some(c) = crate::view_cmds::checked(app, id) {return Some(c);@@ -1271,6 +1278,37 @@ pub fn apply_workspace(app: &mut PhotocraftApp) {mod tests {use super::*;+ #[test]+ fn sync_with_system_menu_keeps_saved_slots_and_its_checkmark_across_palettes() {+ use photocraft_engine::prefs::{AppearanceMode, DarkTheme, LightTheme};+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());+ let ctx = egui::Context::default();+ app.services.system_theme = Some(Box::new(|_| Some(egui::Theme::Light)));+ app.run("prefs.set", json!({"values": {"interface.darkTheme": "studio", "interface.lightTheme": "classic"}})).unwrap();+ invoke(&mut app, &ctx, "window.theme.system", json!({})).unwrap();+ assert_eq!(app.session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ assert_eq!(app.session.prefs().interface.dark_theme, DarkTheme::Studio);+ assert_eq!(app.session.prefs().interface.light_theme, LightTheme::Classic);+ assert_eq!(app.ui.theme, crate::theme::ThemeKind::Classic);+ for appearance in [egui::Theme::Dark, egui::Theme::Light] {+ app.services.system_theme = Some(Box::new(move |_| Some(appearance)));+ crate::prefs_ui::tick(&mut app, &ctx);+ let items = menu_items(&app);+ let item = items.iter().find(|i| i.id == "window.theme.system").unwrap();+ assert_eq!(item.label, "Sync with system");+ assert_eq!(item.path, ["Window", "Theme"]);+ assert!(item.enabled);+ assert_eq!(item.checked, Some(true));+ for kind in crate::theme::ThemeKind::ALL {+ assert_eq!(checked(&app, &format!("window.theme.{}", kind.id())), Some(false));+ }+ }+ invoke(&mut app, &ctx, "window.theme.studio", json!({})).unwrap();+ assert_eq!(app.session.prefs().interface.appearance_mode, AppearanceMode::Dark);+ assert_eq!(checked(&app, "window.theme.system"), Some(false));+ assert_eq!(checked(&app, "window.theme.studio"), Some(true));+ }+#[test]fn submenu_header_is_disabled_when_every_item_is() {let item = |label: &str, enabled: bool| MenuItem {diff --git a/crates/ui-egui/src/native_menu.rs b/crates/ui-egui/src/native_menu.rsindex 4a1ec2ca4..847217e98 100644--- a/crates/ui-egui/src/native_menu.rs+++ b/crates/ui-egui/src/native_menu.rs@@ -830,8 +830,19 @@ mod tests {assert_eq!(l.bar.find("window.theme.classic").unwrap().checked, Some(true));assert_eq!(l.bar.find("window.theme.pro").unwrap().checked, Some(false));assert_eq!(l.bar.find("window.theme.toggle").unwrap().label, "Next Appearance Mode");+ assert_eq!(l.bar.find("window.theme.system").unwrap().label, "Sync with system");+ assert_eq!(l.bar.find("window.theme.system").unwrap().checked, Some(false));let window = ids(&l.bar.menu(MenuRole::Window).unwrap().children);assert!(!window.iter().any(|id| id.starts_with("window.theme.") || id == "[Theme]"), "{window:?}");+ a.session.prefs.edit(|p| p.interface.appearance_mode = photocraft_engine::prefs::AppearanceMode::Auto);+ for palette in [crate::theme::ThemeKind::Classic, crate::theme::ThemeKind::ProMedium] {+ a.ui.theme = palette;+ let automatic = photocraft_layout(&crate::menus::menu_items(&a), Lang::EN, "auto");+ assert_eq!(automatic.bar.find("window.theme.system").unwrap().checked, Some(true));+ for kind in crate::theme::ThemeKind::ALL {+ assert_eq!(automatic.bar.find(&format!("window.theme.{}", kind.id())).unwrap().checked, Some(false));+ }+ }}/// Language follows Settings in the app menu: Auto and every UI language in its own name,diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rsindex 791a6b4a2..b547ef3ba 100644--- a/crates/ui-egui/src/prefs_ui.rs+++ b/crates/ui-egui/src/prefs_ui.rs@@ -298,6 +298,17 @@ fn sync_tooltips(app: &PhotocraftApp, ctx: &egui::Context) {}}+/// Resolve the saved appearance mode without changing it or either theme slot.+pub(crate) fn sync_appearance(app: &mut PhotocraftApp, ctx: &egui::Context) {+ // A restored or embedding-supplied pin must not suppress native appearance events.+ ctx.set_theme(egui::ThemePreference::System);+ // The native service also covers Wayland sessions where winit has no system theme.+ let selected = selected_theme(&app.session.prefs().interface, system_theme(app, ctx));+ if app.ui.theme != selected {+ app.apply_theme(ctx, selected);+ }+}+/// Per-frame upkeep: theme sync, persistence, autosave and the history log.pub fn tick(app: &mut PhotocraftApp, ctx: &egui::Context) {if !app.prefs_rt.loaded {@@ -305,11 +316,7 @@ pub fn tick(app: &mut PhotocraftApp, ctx: &egui::Context) {}recovery(app);sync_display_scale(app, ctx);- // The native service also covers Wayland sessions where winit has no system theme.- let selected = selected_theme(&app.session.prefs().interface, system_theme(app, ctx));- if app.ui.theme != selected {- app.apply_theme(ctx, selected);- }+ sync_appearance(app, ctx);crate::theme::set_ui_font_size(ctx, app.session.prefs().interface.ui_font_size);presets_store(app);sync_tooltips(app, ctx);@@ -1860,6 +1867,194 @@ mod tests {}}+ fn appearance_frame(app: &mut PhotocraftApp, ctx: &egui::Context, appearance: Option<egui::Theme>) {+ ctx.run_ui(egui::RawInput { system_theme: appearance, ..Default::default() }, |ui| tick(app, ui.ctx())).textures_delta.clear();+ }++ fn assert_palette(ctx: &egui::Context, kind: ThemeKind) {+ let t = Tokens::get(ctx);+ assert_eq!(t.kind, kind);+ for style in [ctx.global_style(), ctx.style_of(egui::Theme::Light), ctx.style_of(egui::Theme::Dark)] {+ assert_eq!(style.visuals.panel_fill, t.chrome);+ assert_eq!(style.visuals.window_fill, t.card);+ assert_eq!(style.visuals.override_text_color, Some(t.text));+ assert_eq!(style.visuals.widgets.inactive.bg_fill, t.field);+ assert_eq!(style.visuals.dark_mode, t.dark());+ assert_eq!(style.text_styles[&egui::TextStyle::Body].size, if t.pro { 12.0 } else { 12.5 });+ }+ assert_eq!(ctx.options(|o| o.theme_preference), egui::ThemePreference::System);+ }++ #[test]+ fn auto_appearance_follows_live_changes_without_saving_resolved_palettes() {+ for (dark, light) in [(ThemeKind::ProMedium, ThemeKind::StudioLight), (ThemeKind::SolarizedDark, ThemeKind::Adwaita)] {+ let (mut app, store) = app_with_store();+ let ctx = egui::Context::default();+ PhotocraftApp::setup_context(&ctx, Default::default());+ app.run("prefs.set", json!({"values": {"interface.appearanceMode": "auto", "interface.darkTheme": dark.id(), "interface.lightTheme": light.id()}}))+ .unwrap();+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Light));+ let revision = app.session.prefs.rev();+ let interface = app.session.prefs().interface.clone();+ let saved = store.lock().unwrap().clone().unwrap();+ assert_eq!(stored(&store)["interface"]["appearanceMode"], "auto");+ let gpu_style = canvas_style(&app);+ for (appearance, expected) in [(Some(egui::Theme::Light), light), (Some(egui::Theme::Dark), dark), (Some(egui::Theme::Light), light), (None, dark)]+ {+ appearance_frame(&mut app, &ctx, appearance);+ assert_palette(&ctx, expected);+ assert_eq!(app.ui.theme, expected);+ assert_eq!(app.session.prefs().interface, interface);+ assert_eq!(app.session.prefs.rev(), revision);+ assert_eq!(store.lock().unwrap().as_ref(), Some(&saved));+ assert_eq!(canvas_style(&app), gpu_style);+ assert_eq!(pasteboard_color(&app), None);+ }+ // A fresh launch resolves its saved Auto choice against the new OS input.+ for (appearance, expected) in [(Some(egui::Theme::Light), light), (Some(egui::Theme::Dark), dark), (None, dark)] {+ let (mut restarted, store) = app_with_saved(Some(saved.clone()));+ let fresh = egui::Context::default();+ PhotocraftApp::setup_context(&fresh, Default::default());+ appearance_frame(&mut restarted, &fresh, appearance);+ assert_palette(&fresh, expected);+ assert_eq!(restarted.ui.theme, expected);+ assert_eq!(restarted.session.prefs().interface, interface);+ assert_eq!(store.lock().unwrap().as_ref(), Some(&saved));+ }+ app.run("prefs.set", json!({"values": {"interface.canvasColor": "custom", "interface.canvasCustomColor": "#123456"}})).unwrap();+ for appearance in [Some(egui::Theme::Light), Some(egui::Theme::Dark)] {+ appearance_frame(&mut app, &ctx, appearance);+ assert_eq!(pasteboard_color(&app), Some(Color32::from_rgb(0x12, 0x34, 0x56)));+ assert_eq!(canvas_style(&app), gpu_style);+ }+ }+ }++ #[test]+ fn manual_theme_tokens_and_global_styles_stay_fixed_across_os_changes() {+ let (mut app, store) = app_with_store();+ let ctx = egui::Context::default();+ PhotocraftApp::setup_context(&ctx, Default::default());+ for kind in ThemeKind::ALL {+ app.run("prefs.set", json!({"path": "interface.theme", "value": kind.id()})).unwrap();+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Dark));+ let interface = app.session.prefs().interface.clone();+ let revision = app.session.prefs.rev();+ let saved = store.lock().unwrap().clone().unwrap();+ assert_eq!(interface.appearance_mode, if Tokens::for_kind(kind).dark() { AppearanceMode::Dark } else { AppearanceMode::Light });+ for appearance in [Some(egui::Theme::Dark), Some(egui::Theme::Light), Some(egui::Theme::Dark), None] {+ appearance_frame(&mut app, &ctx, appearance);+ assert_palette(&ctx, kind);+ assert_eq!(Tokens::get(&ctx), Tokens::for_kind(kind));+ assert_eq!(app.ui.theme, kind);+ assert_eq!(app.session.prefs().interface, interface);+ assert_eq!(app.session.prefs.rev(), revision);+ assert_eq!(store.lock().unwrap().as_ref(), Some(&saved));+ }+ }+ }++ #[test]+ fn auto_appearance_replaces_a_restored_egui_dark_pin() {+ let (mut app, _) = app_with_saved(Some(json!({"interface": {"appearanceMode": "auto"}}).to_string()));+ let ctx = egui::Context::default();+ ctx.set_theme(egui::ThemePreference::Dark);+ assert_eq!(ctx.options(|o| o.theme_preference), egui::ThemePreference::Dark);+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Light));+ assert_palette(&ctx, ThemeKind::StudioLight);+ assert_eq!(app.session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ // A restored pin must also clear when the concrete PhotoCraft palette stays the same.+ ctx.set_theme(egui::ThemePreference::Dark);+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Light));+ assert_eq!(ctx.options(|o| o.theme_preference), egui::ThemePreference::System);+ assert_palette(&ctx, ThemeKind::StudioLight);+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Dark));+ assert_palette(&ctx, ThemeKind::ProMedium);+ assert_eq!(app.session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ }++ #[test]+ fn system_theme_menu_choice_stays_checked_as_the_appearance_changes() {+ let (mut app, store) = app_with_store();+ let ctx = egui::Context::default();+ PhotocraftApp::setup_context(&ctx, Default::default());+ app.run("prefs.set", json!({"values": {"interface.darkTheme": "solarizedDark", "interface.lightTheme": "adwaita"}})).unwrap();+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Light));+ crate::menus::invoke(&mut app, &ctx, "window.theme.system", json!({})).unwrap();+ appearance_frame(&mut app, &ctx, Some(egui::Theme::Light));+ let interface = app.session.prefs().interface.clone();+ let saved = store.lock().unwrap().clone().unwrap();+ let revision = app.session.prefs.rev();+ for appearance in [Some(egui::Theme::Light), Some(egui::Theme::Dark), None] {+ appearance_frame(&mut app, &ctx, appearance);+ let items = crate::menus::menu_items(&app);+ let item = |id: &str| items.iter().find(|i| i.id == id).unwrap();+ assert_eq!(item("window.theme.system").checked, Some(true));+ assert!(item("window.theme.system").enabled);+ assert_eq!(item("window.theme.system").path, ["Window", "Theme"]);+ for kind in ThemeKind::ALL {+ assert_eq!(item(&format!("window.theme.{}", kind.id())).checked, Some(false));+ }+ assert_eq!(app.session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ assert_eq!(app.session.prefs().interface, interface);+ assert_eq!(app.session.prefs.rev(), revision);+ assert_eq!(store.lock().unwrap().as_ref(), Some(&saved));+ }+ crate::menus::invoke(&mut app, &ctx, "window.theme.solarizedDark", json!({})).unwrap();+ for appearance in [Some(egui::Theme::Light), Some(egui::Theme::Dark)] {+ appearance_frame(&mut app, &ctx, appearance);+ assert_palette(&ctx, ThemeKind::SolarizedDark);+ let items = crate::menus::menu_items(&app);+ let item = |id: &str| items.iter().find(|i| i.id == id).unwrap();+ assert_eq!(item("window.theme.solarizedDark").checked, Some(true));+ assert_eq!(item("window.theme.system").checked, Some(false));+ assert_eq!(stored(&store)["interface"]["appearanceMode"], "dark");+ assert_eq!(app.session.prefs().interface.light_theme, LightTheme::Adwaita);+ }+ }++ #[test]+ fn preferences_interface_offers_and_applies_sync_with_system() {+ use egui_kittest::{Harness, kittest::Queryable};+ let (mut app, store) = app_with_store();+ app.run("prefs.set", json!({"values": {"interface.language": "en", "interface.darkTheme": "solarizedDark", "interface.lightTheme": "adwaita"}}))+ .unwrap();+ let interface = app.session.prefs().interface.clone();+ open_preferences(&mut app, "interface");+ let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ app+ });+ h.input_mut().system_theme = Some(egui::Theme::Light);+ h.run_steps(4);+ for label in ["Adwaita", "Adwaita dark", "Solarized dark"] {+ assert!(h.query_by_label(label).is_some(), "missing theme choice {label}");+ }+ h.get_by_value("Dark").click();+ h.run_steps(2);+ h.get_by_label("Sync with system").click();+ h.run_steps(2);+ h.get_by_label("Apply").click();+ h.run_steps(4);+ assert_eq!(h.state().session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ assert_eq!(h.state().session.prefs().interface.dark_theme, interface.dark_theme);+ assert_eq!(h.state().session.prefs().interface.light_theme, interface.light_theme);+ assert_eq!(h.state().session.prefs().interface.theme, interface.theme);+ assert_palette(&h.ctx, ThemeKind::Adwaita);+ assert_eq!(stored(&store)["interface"]["appearanceMode"], "auto");+ let saved = store.lock().unwrap().clone().unwrap();+ let (mut restarted, reloaded) = app_with_saved(Some(saved.clone()));+ let fresh = egui::Context::default();+ PhotocraftApp::setup_context(&fresh, Default::default());+ appearance_frame(&mut restarted, &fresh, Some(egui::Theme::Dark));+ assert_palette(&fresh, ThemeKind::SolarizedDark);+ assert_eq!(restarted.session.prefs().interface.appearance_mode, AppearanceMode::Auto);+ assert_eq!(restarted.session.prefs().interface.dark_theme, interface.dark_theme);+ assert_eq!(restarted.session.prefs().interface.light_theme, interface.light_theme);+ assert_eq!(restarted.session.prefs().interface.theme, interface.theme);+ assert_eq!(reloaded.lock().unwrap().as_ref(), Some(&saved));+ }+/// Every generated preference label, section title and choice label has an entry in each/// language that claims complete menus (Japanese, Traditional Chinese, ...).#[test]diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rsindex 2d4910a9d..d7f93ff23 100644--- a/crates/ui-egui/src/theme.rs+++ b/crates/ui-egui/src/theme.rs@@ -676,6 +676,9 @@ pub fn mono(size: f32) -> FontId {/// Apply a theme to egui's global style and publish its tokens.pub fn apply(ctx: &egui::Context, kind: ThemeKind) {+ // Keep native windows at SystemDefault so macOS continues reporting OS appearance changes,+ // including when an integration or restored egui state pinned its own theme preference.+ ctx.set_theme(egui::ThemePreference::System);let t = Tokens::for_kind(kind);ctx.data_mut(|d| d.insert_temp(egui::Id::new("photocraft-theme"), t));let mut v = if t.dark() { Visuals::dark() } else { Visuals::light() };@@ -742,6 +745,11 @@ pub fn apply(ctx: &egui::Context, kind: ThemeKind) {s.spacing.scroll = if t.bevel { egui::style::ScrollStyle::solid() } else { egui::style::ScrollStyle::thin() };s.spacing.tooltip_width = 280.0;});+ // egui selects its style branch using OS appearance, independently of PhotoCraft's fixed+ // Dark/Light mode or platform appearance service. Both branches need the selected palette.+ let style = ctx.global_style();+ ctx.set_style_of(egui::Theme::Light, Arc::clone(&style));+ ctx.set_style_of(egui::Theme::Dark, style);}/// Seconds the pointer rests on a control before its tooltip shows.@@ -861,6 +869,32 @@ mod tests {assert_eq!(ThemeKind::from_name("neon"), None);}+ #[test]+ fn every_palette_keeps_complete_egui_styles_when_the_os_changes() {+ for kind in ThemeKind::ALL {+ let ctx = egui::Context::default();+ ctx.run_ui(egui::RawInput { system_theme: Some(egui::Theme::Dark), ..Default::default() }, |ui| apply(ui.ctx(), kind)).textures_delta.clear();+ let expected = ctx.global_style();+ for appearance in [Some(egui::Theme::Light), Some(egui::Theme::Dark), None] {+ ctx.run_ui(egui::RawInput { system_theme: appearance, ..Default::default() }, |_| {}).textures_delta.clear();+ assert_eq!(Tokens::get(&ctx), Tokens::for_kind(kind));+ assert_eq!(ctx.global_style(), expected, "{kind:?} changed with {appearance:?}");+ assert_eq!(ctx.style_of(egui::Theme::Light), expected);+ assert_eq!(ctx.style_of(egui::Theme::Dark), expected);+ }+ }+ }++ #[test]+ fn applying_a_palette_clears_a_pinned_native_appearance_preference() {+ for pinned in [egui::Theme::Light, egui::Theme::Dark] {+ let ctx = egui::Context::default();+ ctx.set_theme(pinned);+ apply(&ctx, ThemeKind::ProMedium);+ assert_eq!(ctx.options(|o| o.theme_preference), egui::ThemePreference::System);+ }+ }+#[test]fn studio_text_contrast_is_high() {let t = Tokens::for_kind(ThemeKind::Studio);diff --git a/docs/ui-design.md b/docs/ui-design.mdindex 1cbf69da0..10608369f 100644--- a/docs/ui-design.md+++ b/docs/ui-design.md@@ -15,6 +15,8 @@Edit → Preferences → Interface shows an Appearance Mode selector (Sync with system, Dark, Light) above separate light and dark theme cards with PhotoCraft editor previews and radio choices. Auto is opt-in and follows the operating system while the app is running. On Linux it reads the desktop portal once and then listens for its `SettingChanged` signal (no polling, and the UI repaints only when the value changes); `gsettings` runs at most once at start-up, by absolute path, when the portal gives no answer. A missing system appearance falls back to Dark. New installs keep Photoshop's default: Dark mode with Pro Medium (Studio Light is the saved light theme). Existing saved single-theme preferences migrate to a fixed Dark or Light mode with their chosen theme. The header appearance button cycles Auto → Light → Dark; its icon shows a monitor, moon or sun for the selected mode. Window → Theme and `ui.set {"theme":"classic"}` select a theme and fix the mode to its light or dark family.+Window → Theme and macOS PhotoCraft → Appearance also offer Sync with system. Its checkmark follows the saved Auto mode rather than the displayed palette; choosing a manual theme selects its fixed appearance mode.+The toolbar's foreground and background colour chips follow the `Tokens::round_chips` flag. Pro and Classic leave it off and draw Photoshop's overlapping squares with Default Colors and Switch Colors above them. Studio, Studio Light, Solarized Dark, Adwaita and Adwaita Dark (the Studio-layout themes) turn it on and draw large round chips with a curved Switch Colors arrow centred right under them, its heads touching the chips: stacked vertically in one tool column, with Default Colors at their top-right, and side by side in two tool columns, with Default Colors at the toolbar's left edge. Another non-Pro theme can opt in by setting the flag.## Rules