PhotoCraft: An open-source, photo editor written by scratch in pure Rust
feat(ui): Darken and Lighten Interface (Ctrl/Cmd+Shift+F1, F2) (#3709)
FinnNkc208e8ffc145
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex c256200fc..9b63b9633 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -3753,6 +3753,10 @@ navigator Zoom ZvětšeníSent to {printer} Odesláno do {printer}set in Print Settings… nastavuje se v nastavení tisku…ICO is limited to 256 × 256 pixels ICO je omezen na 256 × 256 pixelů++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Ztmavit rozhraní+ Lighten Interface Zesvětlit rozhraní# Bevel & Emboss Technique.Technique TechnikaChisel Hard Tvrdé tesánídiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 7e403a498..42bbbc993 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -3143,6 +3143,10 @@ curves Smooth GlättenSent to {printer} An {printer} gesendetset in Print Settings… in den Druckeinstellungen festlegen…ICO is limited to 256 × 256 pixels ICO ist auf 256 × 256 Pixel begrenzt++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Benutzeroberfläche abdunkeln+ Lighten Interface Benutzeroberfläche aufhellen# Bevel & Emboss Technique.Technique TechnikChisel Hard Meißeln hartdiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 0b53fe2b7..a7d6b6f87 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3843,6 +3843,10 @@ curves Smooth ΕξομάλυνσηSent to {printer} Στάλθηκε στον {printer}set in Print Settings… ορίζεται στις ρυθμίσεις εκτύπωσης…ICO is limited to 256 × 256 pixels Το ICO περιορίζεται σε 256 × 256 εικονοστοιχεία++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Σκουρότερο περιβάλλον+ Lighten Interface Φωτεινότερο περιβάλλον# Bevel & Emboss Technique.Technique ΤεχνικήChisel Hard Σκληρή σμίλευσηdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex f3a9df7e2..3fa765518 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2830,6 +2830,10 @@ curves Smooth SuavizarSent to {printer} Enviado a {printer}set in Print Settings… se establece en Ajustes de impresión…ICO is limited to 256 × 256 pixels ICO está limitado a 256 × 256 píxeles++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Oscurecer interfaz+ Lighten Interface Aclarar interfaz# Bevel & Emboss Technique.Technique TécnicaChisel Hard Cincelar durodiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 8d54a8cdc..f1d11f19a 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -3147,6 +3147,10 @@ curves Smooth LisserSent to {printer} Envoyé à {printer}set in Print Settings… défini dans les paramètres d’impression…ICO is limited to 256 × 256 pixels Le format ICO est limité à 256 × 256 pixels++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Assombrir l'interface+ Lighten Interface Éclaircir l'interface# Bevel & Emboss Technique.Technique TechniqueChisel Hard Ciselage durdiff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex 78a661346..e3f427921 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -4066,6 +4066,10 @@ cameraRaw Yellow SárgaInk Characteristics Festék jellemzőiSolidity: Fedőképesség:Redrawing Újrarajzolás++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Felület sötétítése+ Lighten Interface Felület világosítása# Bevel & Emboss Technique.Technique TechnikaChisel Hard Kemény vésésdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 6497616c4..6b7aca6ff 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -3134,6 +3134,10 @@ curves Smooth HaluskanSent to {printer} Dikirim ke {printer}set in Print Settings… diatur di Pengaturan Cetak…ICO is limited to 256 × 256 pixels ICO dibatasi hingga 256 × 256 piksel++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Gelapkan Antarmuka+ Lighten Interface Cerahkan Antarmuka# Bevel & Emboss Technique.Technique TeknikChisel Hard Pahat Kerasdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex bea1a0867..06efc8d9f 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -4108,6 +4108,9 @@ navigator Zoom ZoomSent to {printer} Inviato a {printer}set in Print Settings… impostato nelle impostazioni di stampa…ICO is limited to 256 × 256 pixels ICO è limitato a 256 × 256 pixel+# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Scurisci interfaccia+ Lighten Interface Schiarisci interfaccia# Bevel & Emboss Technique.Technique TecnicaChisel Hard Cesello durodiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 901549c75..7890c916f 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3822,6 +3822,9 @@ curves Smooth スムーズReset All Locked Settings ロックされた設定をすべて初期化Copy Texture to Other Tools テクスチャを他のツールにコピーICO is limited to 256 × 256 pixels ICO は 256 × 256 ピクセルまでです+# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface インターフェイスを暗くする+ Lighten Interface インターフェイスを明るくする# Bevel & Emboss Technique.Technique テクニックChisel Hard チゼルハードdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex 79cc195b7..0ed7c3c67 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3320,6 +3320,10 @@ curves Smooth 매끄럽게Sent to {printer} {printer}(으)로 전송됨set in Print Settings… 인쇄 설정에서 지정…ICO is limited to 256 × 256 pixels ICO는 256 × 256픽셀로 제한됩니다++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface 인터페이스 어둡게+ Lighten Interface 인터페이스 밝게# Bevel & Emboss Technique.Technique 기법Chisel Hard 단단하게 조각diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex dce4d0920..0ea0ce047 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -3905,6 +3905,10 @@ curves Smooth Vloeiend makenSent to {printer} Verzonden naar {printer}set in Print Settings… instellen in de afdrukinstellingen…ICO is limited to 256 × 256 pixels ICO is beperkt tot 256 × 256 pixels++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Interface donkerder maken+ Lighten Interface Interface lichter maken# Bevel & Emboss Technique.Technique TechniekChisel Hard Beitel harddiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 9a8f77098..7d22a6ae7 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3743,6 +3743,10 @@ curves Smooth WygładźSent to {printer} Wysłano do {printer}set in Print Settings… ustawiane w ustawieniach druku…ICO is limited to 256 × 256 pixels ICO jest ograniczony do 256 × 256 pikseli++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Przyciemnij interfejs+ Lighten Interface Rozjaśnij interfejs# Bevel & Emboss Technique.Technique TechnikaChisel Hard Dłuto twardediff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex f89e09eb0..a36fb9561 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -3935,6 +3935,10 @@ layerLabel No Color Sem corSent to {printer} Enviado para {printer}set in Print Settings… definido nas configurações de impressão…ICO is limited to 256 × 256 pixels ICO é limitado a 256 × 256 pixels++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Escurecer interface+ Lighten Interface Clarear interface# Bevel & Emboss Technique.Technique TécnicaChisel Hard Cinzel durodiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex e32e5114b..3f7bd7524 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -3111,6 +3111,10 @@ curves Smooth СгладитьGray Value (Median) Уровень серого (медиана)Integrated Density Интегральная плотностьLength Длина++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Сделать интерфейс темнее+ Lighten Interface Сделать интерфейс светлее# Bevel & Emboss Technique.Technique МетодChisel Hard Жесткая огранкаdiff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsvindex 8365404d7..bdca95361 100644--- a/crates/ui-egui/src/i18n/sr.tsv+++ b/crates/ui-egui/src/i18n/sr.tsv@@ -4219,6 +4219,10 @@ shape Appearance IzgledInk Characteristics Karakteristike mastilaSolidity: Punoća:Redrawing Ponovno iscrtavanje++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Zatamni interfejs+ Lighten Interface Posvetli interfejs# Bevel & Emboss Technique.Technique TehnikaChisel Hard Tvrdo klesanjediff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsvindex eaa32fcbb..4fcf00c6b 100644--- a/crates/ui-egui/src/i18n/tr.tsv+++ b/crates/ui-egui/src/i18n/tr.tsv@@ -3877,6 +3877,10 @@ cameraData Lens LensInk Characteristics Mürekkep ÖzellikleriSolidity: Doluluk:Redrawing Yeniden çiziliyor++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Arayüzü koyulaştır+ Lighten Interface Arayüzü açıklaştır# Bevel & Emboss Technique.Technique TeknikChisel Hard Sert Keskidiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex c6212c5d0..353e97c3b 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -3844,6 +3844,10 @@ curves Smooth ЗгладитиSent to {printer} Надіслано на {printer}set in Print Settings… задається в параметрах друку…ICO is limited to 256 × 256 pixels ICO обмежено розміром 256 × 256 пікселів++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Зробити інтерфейс темнішим+ Lighten Interface Зробити інтерфейс світлішим# Bevel & Emboss Technique.Technique МетодChisel Hard Жорстке різьбленняdiff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsvindex 9208112bf..41c7b7c0b 100644--- a/crates/ui-egui/src/i18n/vi.tsv+++ b/crates/ui-egui/src/i18n/vi.tsv@@ -3632,6 +3632,10 @@ curves Smooth Làm mượtSent to {printer} Đã gửi tới {printer}set in Print Settings… đặt trong thiết lập in…ICO is limited to 256 × 256 pixels ICO giới hạn ở 256 × 256 pixel++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface Làm tối giao diện+ Lighten Interface Làm sáng giao diện# Bevel & Emboss Technique.Technique Kỹ thuậtChisel Hard Đục cứngdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 2ebc4c71c..c420d748c 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2755,6 +2755,10 @@ curves Smooth 平滑Sent to {printer} 已发送到 {printer}set in Print Settings… 在打印设置中设置…ICO is limited to 256 × 256 pixels ICO 最大为 256 × 256 像素++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface 界面变暗+ Lighten Interface 界面变亮# Bevel & Emboss Technique.Technique 方法Chisel Hard 雕刻清晰diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 92302285c..c4f9f4098 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2740,6 +2740,10 @@ curves Smooth 平滑Sent to {printer} 已傳送至 {printer}set in Print Settings… 在列印設定中設定…ICO is limited to 256 × 256 pixels ICO 最大為 256 × 256 像素++# Darken / Lighten Interface (⇧⌘F1 / ⇧⌘F2)+ Darken Interface 介面變暗+ Lighten Interface 介面變亮# Bevel & Emboss Technique.Technique 方法Chisel Hard 雕刻清晰diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex c20967b16..592acbc62 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -53,6 +53,9 @@ pub const UI_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[("view.extras", "Extras", &["View"], Some("Cmd+H")),("view.show.targetPath", "Target Path", &["View", "Show"], Some("Cmd+Shift+H")),("view.screenMode.cycle", "Cycle Screen Mode", &[], Some("F")),+ // Photoshop's interface brightness shortcuts: step through the four Pro themes.+ ("view.darkenInterface", "Darken Interface", &[], Some("Cmd+Shift+F1")),+ ("view.lightenInterface", "Lighten Interface", &[], Some("Cmd+Shift+F2")),("edit.freeTransformCopy", "Free Transform a Copy", &[], Some("Cmd+Alt+T")),("type.editText", "Edit Type", &[], None),("view.zoomIn", "Zoom In", &["View"], Some("Cmd+=")),@@ -376,6 +379,10 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:crate::prefs_ui::cycle_appearance(app, ctx);Ok(Value::Null)}+ "view.darkenInterface" | "view.lightenInterface" => {+ crate::prefs_ui::step_brightness(app, ctx, id == "view.lightenInterface")?;+ Ok(json!({"theme": app.ui.theme.id()}))+ }"window.theme.system" => {app.run("prefs.set", json!({"path": "interface.appearanceMode", "value": "auto"}))?;crate::prefs_ui::sync_appearance(app, ctx);@@ -752,6 +759,8 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> bool {i if i.starts_with(DOCUMENT_ITEM) => true,i if crate::links::url_for(i).is_some() => true,i if i.starts_with("window.theme.") => true,+ // Interface brightness works with or without a document, as in Photoshop.+ "view.darkenInterface" | "view.lightenInterface" => true,"file.save" | "file.saveAs" | "file.export.exportAs" | "file.export.quickExportAsPng" => {app.session.active().is_some() && app.services.export.is_some()}diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rsindex 513b25701..7dd2ce2ea 100644--- a/crates/ui-egui/src/prefs_ui.rs+++ b/crates/ui-egui/src/prefs_ui.rs@@ -128,6 +128,26 @@ pub(crate) fn cycle_appearance(app: &mut PhotocraftApp, ctx: &egui::Context) {}}+/// Photoshop's four interface brightnesses, darkest first.+const BRIGHTNESSES: [ThemeKind; 4] = [ThemeKind::Pro, ThemeKind::ProMedium, ThemeKind::ProLightGray, ThemeKind::ProLight];++/// Darken Interface (⇧⌘F1, `lighter` false) and Lighten Interface (⇧⌘F2): the next of+/// Photoshop's four brightnesses from the theme on screen, stopping at either end, as in+/// Photoshop. Another theme steps from the nearest brightness: Medium Gray for a dark one, Light+/// Gray for a light one. The choice is saved like picking it in Preferences › Interface.+pub(crate) fn step_brightness(app: &mut PhotocraftApp, ctx: &egui::Context, lighter: bool) -> Result<(), String> {+ let current = app.ui.theme;+ let at = BRIGHTNESSES.iter().position(|k| *k == current).unwrap_or(if crate::theme::Tokens::for_kind(current).dark() { 1 } else { 2 });+ let next = if lighter { (at + 1).min(BRIGHTNESSES.len() - 1) } else { at.saturating_sub(1) };+ let Some(&kind) = BRIGHTNESSES.get(next) else { return Ok(()) };+ if kind == current {+ return Ok(());+ }+ app.run("prefs.set", json!({"path": "interface.theme", "value": kind.id()}))?;+ sync_appearance(app, ctx);+ Ok(())+}+const LIGHT_THEME_OPTIONS: &[(&str, ThemeKind)] = &[("proLight", ThemeKind::ProLight),("proLightGray", ThemeKind::ProLightGray),@@ -2169,6 +2189,65 @@ mod tests {}}+ #[test]+ fn darken_and_lighten_interface_step_through_photoshops_brightnesses_and_stop_at_the_ends() {+ let ctx = egui::Context::default();+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ sync_appearance(&mut app, &ctx);+ assert_eq!(app.ui.theme, ThemeKind::ProMedium, "Photoshop's default brightness");+ let press = |app: &mut PhotocraftApp, id: &str| crate::menus::invoke(app, &ctx, id, json!({})).unwrap();+ for expected in [ThemeKind::ProLightGray, ThemeKind::ProLight, ThemeKind::ProLight] {+ press(&mut app, "view.lightenInterface");+ assert_eq!(app.ui.theme, expected);+ }+ // Saved like a choice in Preferences › Interface: the light slot and the Light appearance.+ let i = &app.session.prefs().interface;+ assert_eq!((i.appearance_mode, i.light_theme), (AppearanceMode::Light, LightTheme::ProLight));+ for expected in [ThemeKind::ProLightGray, ThemeKind::ProMedium, ThemeKind::Pro, ThemeKind::Pro] {+ press(&mut app, "view.darkenInterface");+ assert_eq!(app.ui.theme, expected);+ }+ let i = &app.session.prefs().interface;+ assert_eq!((i.appearance_mode, i.dark_theme), (AppearanceMode::Dark, DarkTheme::Pro));+ // Another theme steps from the nearest brightness.+ for (theme, id, expected) in [+ ("studio", "view.darkenInterface", ThemeKind::Pro),+ ("studio", "view.lightenInterface", ThemeKind::ProLightGray),+ ("classic", "view.darkenInterface", ThemeKind::ProMedium),+ ("classic", "view.lightenInterface", ThemeKind::ProLight),+ ] {+ app.run("prefs.set", json!({"path": "interface.theme", "value": theme})).unwrap();+ sync_appearance(&mut app, &ctx);+ press(&mut app, id);+ assert_eq!(app.ui.theme, expected, "{theme} {id}");+ }+ }++ #[test]+ fn ctrl_shift_f1_and_f2_darken_and_lighten_the_interface() {+ for (id, shortcut) in [("view.darkenInterface", "Cmd+Shift+F1"), ("view.lightenInterface", "Cmd+Shift+F2")] {+ assert_eq!(crate::shortcuts::default_shortcut(id).as_deref(), Some(shortcut), "{id}");+ }+ let ctx = egui::Context::default();+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ sync_appearance(&mut app, &ctx);+ let press = |app: &mut PhotocraftApp, key| {+ let modifiers = egui::Modifiers::COMMAND | egui::Modifiers::SHIFT;+ let raw = egui::RawInput {+ events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],+ ..Default::default()+ };+ ctx.begin_pass(raw);+ crate::shortcuts::handle(app, &ctx);+ ctx.end_pass().textures_delta.clear();+ };+ press(&mut app, egui::Key::F1);+ assert_eq!(app.ui.theme, ThemeKind::Pro);+ press(&mut app, egui::Key::F2);+ press(&mut app, egui::Key::F2);+ assert_eq!(app.ui.theme, ThemeKind::ProLightGray);+ }+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();}