SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Logo: an option to draw it in the theme's accent (#8133)
dudedagger424a34a258e18c
diff --git a/assets/locales/pending/logo-accent.json b/assets/locales/pending/logo-accent.jsonnew file mode 100644index 0000000000..fea992c218--- /dev/null+++ b/assets/locales/pending/logo-accent.json@@ -0,0 +1,32 @@+{+ "en": {+ "prefs.logo": "Logo",+ "prefs.logo_theme": "Theme's colors",+ "prefs.logo_accent": "Accent"+ },+ "ar": {+ "prefs.logo": "الشعار",+ "prefs.logo_theme": "ألوان السمة",+ "prefs.logo_accent": "لون التمييز"+ },+ "he": {+ "prefs.logo": "לוגו",+ "prefs.logo_theme": "צבעי ערכת הנושא",+ "prefs.logo_accent": "צבע הדגשה"+ },+ "ja": {+ "prefs.logo": "ロゴ",+ "prefs.logo_theme": "テーマの色",+ "prefs.logo_accent": "アクセント"+ },+ "vi": {+ "prefs.logo": "Logo",+ "prefs.logo_theme": "Màu của chủ đề",+ "prefs.logo_accent": "Màu nhấn"+ },+ "zh": {+ "prefs.logo": "标志",+ "prefs.logo_theme": "主题颜色",+ "prefs.logo_accent": "强调色"+ }+}diff --git a/crates/ui-egui/src/colour_tokens_tests.rs b/crates/ui-egui/src/colour_tokens_tests.rsindex 0561d047ba..8be8a444c7 100644--- a/crates/ui-egui/src/colour_tokens_tests.rs+++ b/crates/ui-egui/src/colour_tokens_tests.rs@@ -289,3 +289,34 @@ fn every_engine_colour_tag_is_placed() {placed.sort_unstable();assert_eq!(names, placed, "an engine colour tag must be mapped to a token in `viewport::sketch_color` or listed as neutral");}++/// Preferences › Interface › Logo: the logo in shades of the theme's accent (the accent itself in+/// the middle, a lighter and a darker face), in a built-in theme and a theme file alike, and back+/// to the theme's own logo colours.+#[test]+fn the_logo_can_take_the_themes_accent() {+ struct Reset;+ impl Drop for Reset {+ fn drop(&mut self) {+ crate::theme::set_logo_accent(false);+ }+ }+ let _reset = Reset;+ let mut h = crate::scenario::Harness::new();+ for theme in ["dark", "gruvbox-dark"] {+ h.call("ui.prefs", serde_json::json!({"theme": theme, "logo_accent": false}));+ h.frames(1);+ let own = Tokens::get();+ h.call("ui.prefs", serde_json::json!({"logo_accent": true}));+ h.frames(1);+ let t = Tokens::get();+ let accent = t.accent.to_opaque();+ assert_eq!(t.logo[1], accent, "{theme}");+ let lum = |c: Color32| u32::from(c.r()) + u32::from(c.g()) + u32::from(c.b());+ assert!(lum(t.logo[0]) > lum(accent) && lum(t.logo[2]) < lum(accent), "{theme}: {:?}", t.logo);+ assert_eq!(Tokens { logo: own.logo, ..t }, own, "{theme}: only the logo changes");+ h.call("ui.prefs", serde_json::json!({"logo_accent": false}));+ h.frames(1);+ assert_eq!(Tokens::get().logo, own.logo, "{theme}: the theme's own again");+ }+}diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 78705119c6..54769d1d9e 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -833,6 +833,8 @@ preference_settings! {/// The 3D view's colours: the theme's own, or the Light or Dark theme's whatever the window/// uses (#4146).viewport_theme: crate::theme::ViewportTheme = crate::theme::ViewportTheme::Theme, PAGE_INTERFACE;+ /// The application bar's logo in the theme's accent instead of the theme's logo colours.+ logo_accent: bool = false, PAGE_INTERFACE;/// Imported theme files (`theme_files`), kept here so they also work in the browser.custom_themes: Vec<crate::theme_files::ThemeFile> = Vec::new();/// Desktop: a `solidcraft-theme/1` file another tool writes, followed as the theme and@@ -1525,6 +1527,9 @@ pub fn apply(app: &mut SolveApp, ctx: &egui::Context) {if crate::theme::set_custom(custom) {app.styled = false;}+ if crate::theme::set_logo_accent(app.preferences.logo_accent) {+ app.styled = false;+ }// egui's end-of-frame shortcuts only change its context; the saved preference would// overwrite that change next frame. Consume the desktop shortcuts into the preference.if ctx.options(|o| o.zoom_with_keyboard) && !crate::keymap::capturing(app) {diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rsindex b7b616f99a..7793e182a0 100644--- a/crates/ui-egui/src/prefs/interface.rs+++ b/crates/ui-egui/src/prefs/interface.rs@@ -45,6 +45,15 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {app.preferences.viewport_theme = *view;}});+ // The logo in the theme's own logo colours or in its accent.+ let label = app.tr("prefs.logo");+ ui_kit::row(ui, label, |ui| {+ let labels = [crate::i18n::tr("prefs.logo_theme"), crate::i18n::tr("prefs.logo_accent")];+ let mut selected = usize::from(app.preferences.logo_accent);+ if ui_kit::settings_segments(ui, label, &mut selected, &labels) {+ app.preferences.logo_accent = selected == 1;+ }+ });// A theme file another tool writes, reloaded when it changes (#7573).if FOLLOW_AVAILABLE {follow_row(app, ui);diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rsindex e21b43e230..1f9a4865a6 100644--- a/crates/ui-egui/src/theme.rs+++ b/crates/ui-egui/src/theme.rs@@ -25,6 +25,9 @@ thread_local! {/// The palette of a theme file (`theme_files`) in place of the built-in one of its base/// (dark or light), per thread like the rest. `None`: the built-in palettes.static CUSTOM: Cell<Option<Custom>> = const { Cell::new(None) };+ /// The application bar's logo in the theme's accent instead of its own logo colours+ /// (Preferences › Interface › Logo), per thread like the rest.+ static LOGO_ACCENT: Cell<bool> = const { Cell::new(false) };/// The 3D view's own dark or light when Preferences give it one ([`ViewportTheme`], #4146),/// per thread like the rest. `None`: the view is as dark as the window.static VIEWPORT_DARK: Cell<Option<bool>> = const { Cell::new(None) };@@ -230,6 +233,12 @@ pub fn set_custom(custom: Option<Custom>) -> bool {CUSTOM.with(|c| c.replace(custom) != custom)}+/// Draw the logo in the theme's accent (`true`) or its own logo colours. Returns whether that+/// changed anything (the visuals follow on the next [`apply`]).+pub fn set_logo_accent(on: bool) -> bool {+ LOGO_ACCENT.with(|c| c.replace(on) != on)+}+/// Isolated widget tests restore the thread's theme even when an assertion fails.#[cfg(test)]pub(crate) fn scoped_tokens(tokens: Tokens) -> impl Drop {@@ -944,7 +953,17 @@ impl Tokens {/// that base ([`set_custom`]), else the built-in one; the colour vision mode on top.pub fn themed(dark: bool, mode: ColorVision) -> Tokens {let custom = CUSTOM.get().filter(|c| c.dark == dark).map(|c| c.tokens);- custom.unwrap_or(if dark { Tokens::dark() } else { Tokens::light() }).with_vision(dark, mode)+ let t = custom.unwrap_or(if dark { Tokens::dark() } else { Tokens::light() });+ let t = if LOGO_ACCENT.get() { t.with_accent_logo() } else { t };+ t.with_vision(dark, mode)+ }++ /// These tokens with the logo's three faces in shades of the accent: lighter, the accent+ /// itself, darker (as the built-in logo's blues are).+ pub fn with_accent_logo(mut self) -> Tokens {+ let accent = self.accent.to_opaque();+ self.logo = [accent.lerp_to_gamma(Color32::WHITE, 0.22), accent, accent.lerp_to_gamma(Color32::BLACK, 0.2)];+ self}/// These tokens with a colour vision mode's values on top (the tables in `palettes.rs`); Offdiff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.mdindex f12a08cf03..f19c8764cc 100644--- a/docs/book/src/guide/ui-tour.md+++ b/docs/book/src/guide/ui-tour.md@@ -157,7 +157,7 @@ History at the bottom is unchanged.### Colour themesInterface › **Theme** lists Dark, Light and System (follows the operating system), the built-in-themes and any themes you have imported. A choice applies at once. Under the themes, **Viewport** draws the 3D view in the Light or Dark theme's colours whatever the window uses, for example the model on a light view in a dark window (**Follow theme**, the default, keeps the theme's own). The built-in themes are Gruvbox+themes and any themes you have imported. A choice applies at once. Under the themes, **Viewport** draws the 3D view in the Light or Dark theme's colours whatever the window uses, for example the model on a light view in a dark window (**Follow theme**, the default, keeps the theme's own). **Logo** draws the SolidCraft logo at the top left in shades of the theme's accent instead of the theme's logo colours. The built-in themes are Gruvbox(dark and light, each in hard, normal and soft contrast), SolidCraft 95, Platinum 9, Cupertino,Green Phosphor, Amber Phosphor, Blueprint, One Dark, Tokyo Night, Solarized Light, Nord, HighContrast, Graphite, Nosferatu, Catppuccin Mocha, Okibi and Akari (dark and light, from thediff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex 9477ba867e..8139dc8cfd 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -336,6 +336,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own- `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres)- `language` (`en`, `ar`, `ja`, `de`, `fr`, `he`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md))- `length_decimals`+- `logo_accent` (bool, default false: the application bar's logo in shades of the theme's accent instead of the theme's logo colours)- `look_at_anim`- `look_at_speed`- `middle_double_click` (`home` (default), `fit`, `off`)