Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Add the built-in 1-bit and 1-bit Dark themes (#7550) (#7557)

raykholo236b5c9ebf00
diff --git a/assets/styles/ui/palettes.rs b/assets/styles/ui/palettes.rs
index cf1fda870a..e535b3b1e5 100644
--- a/assets/styles/ui/palettes.rs
+++ b/assets/styles/ui/palettes.rs
@@ -73,6 +73,7 @@ impl Tokens {
form_ink: Color32::from_rgb(27, 36, 48),
form_dim: Color32::from_rgb(74, 88, 104),
form_primary: Color32::from_rgb(35, 110, 173),
+ form_primary_fill: Color32::from_rgb(35, 110, 173),
form_error: Color32::from_rgb(161, 52, 44),
form_error_fill: Color32::from_rgb(252, 239, 237),
form_success: Color32::from_rgb(39, 107, 44),
@@ -363,6 +364,7 @@ impl Tokens {
t.form_ink = t.text;
t.form_dim = Color32::from_rgb(180, 187, 200);
t.form_primary = t.accent;
+ t.form_primary_fill = t.form_primary;
t.form_error = t.error;
t.form_error_fill = t.timeline_item_error;
t.form_success = Color32::from_rgb(143, 219, 154);
diff --git a/assets/styles/ui/themes/1-bit-dark.json b/assets/styles/ui/themes/1-bit-dark.json
new file mode 100644
index 0000000000..cea69a7a9e
--- /dev/null
+++ b/assets/styles/ui/themes/1-bit-dark.json
@@ -0,0 +1,247 @@
+{
+ "base": "dark",
+ "colors": {
+ "accent": "#ffffff",
+ "accent_soft": "#000000",
+ "agent_busy": "#ffffff",
+ "agent_ok": "#ffffff",
+ "app_bar": "#000000",
+ "app_bar_hover": "#000000",
+ "app_bar_hover_button": "#000000",
+ "app_bar_hover_strong": "#000000",
+ "app_bar_hover_subtle": "#000000",
+ "app_bar_separator": "#ffffff",
+ "app_bar_tab_active": "#000000",
+ "app_bar_text": "#ffffff",
+ "axis_x": "#ffffff",
+ "axis_y": "#ffffff",
+ "axis_z": "#ffffff",
+ "bend_down": "#ffffff",
+ "bend_up": "#ffffff",
+ "body": "#000000",
+ "body_edge": "#ffffff",
+ "body_selected": "#ffffff",
+ "border": "#ffffff",
+ "box_crossing": "#ffffff",
+ "box_window": "#ffffff",
+ "chip": "#ffffff",
+ "construction_geom": "#ffffff",
+ "construction_plane": "#000000",
+ "continuity": [
+ "#ffffff",
+ "#ffffff",
+ "#ffffff",
+ "#ffffff"
+ ],
+ "control_border": "#ffffff",
+ "control_fill": "#000000",
+ "cube_border": "#ffffff",
+ "cube_face": "#000000",
+ "cube_hover": "#000000",
+ "cube_text": "#ffffff",
+ "dialog_bg": "#000000",
+ "dialog_body": "#000000",
+ "dialog_border": "#ffffff",
+ "dialog_footer": "#000000",
+ "dialog_label": "#ffffff",
+ "dialog_rule": "#ffffff",
+ "dimension": "#ffffff",
+ "dimension_driven": "#ffffff",
+ "error": "#ffffff",
+ "field": "#000000",
+ "file_background": "#000000",
+ "file_border": "#ffffff",
+ "file_dim": "#ffffff",
+ "file_image_tint": "#ffffff",
+ "file_primary": "#000000",
+ "file_primary_border": "#ffffff",
+ "file_primary_ink": "#ffffff",
+ "file_rail": "#000000",
+ "file_rail_hover": "#000000",
+ "file_rail_ink": "#ffffff",
+ "file_recovery": "#000000",
+ "file_recovery_border": "#ffffff",
+ "file_recovery_ink": "#ffffff",
+ "file_recovery_well": "#000000",
+ "file_surface": "#000000",
+ "form_accent": "#ffffff",
+ "form_dim": "#ffffff",
+ "form_error": "#ffffff",
+ "form_error_fill": "#000000",
+ "form_fill": "#ffffff",
+ "form_ink": "#ffffff",
+ "form_primary": "#000000",
+ "form_primary_fill": "#ffffff",
+ "form_soft": "#000000",
+ "form_success": "#ffffff",
+ "form_success_fill": "#000000",
+ "form_tab_ink": "#ffffff",
+ "glyph_bg": "#000000",
+ "glyph_edge": "#ffffff",
+ "glyph_text": "#ffffff",
+ "grid": "#000000",
+ "grid_major": "#ffffff",
+ "hover": "#000000",
+ "hover_edge": "#ffffff",
+ "hover_edge_halo": "#000000",
+ "hover_profile": "#ffffff",
+ "hover_profile_edge": "#000000",
+ "icon": "#ffffff",
+ "icons.agent": "#ffffff",
+ "icons.highlight": "#000000",
+ "icons.marker_halo": "#000000",
+ "interference": "#ffffff",
+ "logo": [
+ "#ffffff",
+ "#ffffff",
+ "#ffffff"
+ ],
+ "manipulator": "#ffffff",
+ "mesh_accent": "#ffffff",
+ "mesh_fill": "#ffffff",
+ "mesh_ink": "#ffffff",
+ "mesh_soft": "#000000",
+ "on_accent": "#000000",
+ "origin_plane": "#000000",
+ "origin_plane_edge": "#ffffff",
+ "origin_plane_hover": "#ffffff",
+ "origin_point": "#ffffff",
+ "overlay": "#000000",
+ "panel": "#000000",
+ "panel_header": "#000000",
+ "preview_add": "#ffffff",
+ "preview_cut": "#ffffff",
+ "preview_new": "#ffffff",
+ "preview_sketch": "#ffffff",
+ "profile_fill": "#000000",
+ "render_accent": "#ffffff",
+ "render_fill": "#ffffff",
+ "render_ink": "#ffffff",
+ "render_soft": "#000000",
+ "rubber_band": "#ffffff",
+ "section_cap": "#ffffff",
+ "sel_edge": "#000000",
+ "sel_edge_rim": "#000000",
+ "sel_face": "#ffffff",
+ "sel_profile": "#ffffff",
+ "sel_profile_edge": "#000000",
+ "sel_vertex": "#ffffff",
+ "selected_bg": "#ffffff",
+ "selected_ink": "#000000",
+ "sheet_fill": "#ffffff",
+ "sheet_ink": "#ffffff",
+ "sheet_soft": "#000000",
+ "sketch": "#ffffff",
+ "sketch_accent": "#ffffff",
+ "sketch_centerline": "#ffffff",
+ "sketch_construction": "#ffffff",
+ "sketch_fixed": "#ffffff",
+ "sketch_halo": "#000000",
+ "sketch_ink": "#ffffff",
+ "sketch_locked": "#ffffff",
+ "sketch_lost": "#ffffff",
+ "sketch_point": "#ffffff",
+ "sketch_point_free": "#ffffff",
+ "sketch_projected": "#ffffff",
+ "sketch_soft": "#000000",
+ "surface_accent": "#ffffff",
+ "surface_fill": "#ffffff",
+ "surface_ink": "#ffffff",
+ "surface_soft": "#000000",
+ "tab_on_fill_dark": "#ffffff",
+ "text": "#ffffff",
+ "text_dim": "#ffffff",
+ "timeline": "#000000",
+ "timeline_item": "#000000",
+ "timeline_item_error": "#000000",
+ "timeline_marker": "#ffffff",
+ "toolbar": "#000000",
+ "viewport_bottom": "#000000",
+ "viewport_top": "#000000",
+ "warning": "#ffffff"
+ },
+ "format": "solidcraft-theme/1",
+ "name": "1-bit Dark",
+ "radii": {
+ "radius_sm": 0,
+ "radius_md": 0,
+ "radius_lg": 0,
+ "radius_xl": 0,
+ "control_radius": 0,
+ "sketch_mode_radius": 0
+ },
+ "icon_palette": {
+ "ink": "#ffffff",
+ "line": "#ffffff",
+ "passive-1": "#000000",
+ "passive-2": "#000000",
+ "passive-3": "#000000",
+ "guide": "#ffffff",
+ "solid": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "surface": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "mesh": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "form": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "sketch": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "constraint": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "construction": [
+ "#000000",
+ "#000000",
+ "#ffffff"
+ ],
+ "active-1": "#000000",
+ "active-2": "#000000",
+ "active-3": "#ffffff",
+ "component-orange-1": "#000000",
+ "component-orange-2": "#000000",
+ "component-orange-3": "#ffffff",
+ "component-yellow-1": "#000000",
+ "component-yellow-2": "#000000",
+ "component-yellow-3": "#ffffff"
+ },
+ "borders": {
+ "primary": {
+ "width": 1,
+ "color": "#ffffff"
+ },
+ "secondary": {
+ "width": 1,
+ "color": "#ffffff"
+ },
+ "tertiary": {
+ "width": 1,
+ "color": "#ffffff"
+ },
+ "container": {
+ "width": 1,
+ "color": "#ffffff"
+ },
+ "control": {
+ "width": 1,
+ "color": "#ffffff"
+ }
+ }
+}
diff --git a/assets/styles/ui/themes/1-bit.json b/assets/styles/ui/themes/1-bit.json
new file mode 100644
index 0000000000..a8c8c8ff2b
--- /dev/null
+++ b/assets/styles/ui/themes/1-bit.json
@@ -0,0 +1,247 @@
+{
+ "base": "light",
+ "colors": {
+ "accent": "#000000",
+ "accent_soft": "#ffffff",
+ "agent_busy": "#000000",
+ "agent_ok": "#000000",
+ "app_bar": "#ffffff",
+ "app_bar_hover": "#ffffff",
+ "app_bar_hover_button": "#ffffff",
+ "app_bar_hover_strong": "#ffffff",
+ "app_bar_hover_subtle": "#ffffff",
+ "app_bar_separator": "#000000",
+ "app_bar_tab_active": "#ffffff",
+ "app_bar_text": "#000000",
+ "axis_x": "#000000",
+ "axis_y": "#000000",
+ "axis_z": "#000000",
+ "bend_down": "#000000",
+ "bend_up": "#000000",
+ "body": "#ffffff",
+ "body_edge": "#000000",
+ "body_selected": "#000000",
+ "border": "#000000",
+ "box_crossing": "#000000",
+ "box_window": "#000000",
+ "chip": "#000000",
+ "construction_geom": "#000000",
+ "construction_plane": "#ffffff",
+ "continuity": [
+ "#000000",
+ "#000000",
+ "#000000",
+ "#000000"
+ ],
+ "control_border": "#000000",
+ "control_fill": "#ffffff",
+ "cube_border": "#000000",
+ "cube_face": "#ffffff",
+ "cube_hover": "#ffffff",
+ "cube_text": "#000000",
+ "dialog_bg": "#ffffff",
+ "dialog_body": "#ffffff",
+ "dialog_border": "#000000",
+ "dialog_footer": "#ffffff",
+ "dialog_label": "#000000",
+ "dialog_rule": "#000000",
+ "dimension": "#000000",
+ "dimension_driven": "#000000",
+ "error": "#000000",
+ "field": "#ffffff",
+ "file_background": "#ffffff",
+ "file_border": "#000000",
+ "file_dim": "#000000",
+ "file_image_tint": "#ffffff",
+ "file_primary": "#ffffff",
+ "file_primary_border": "#000000",
+ "file_primary_ink": "#000000",
+ "file_rail": "#ffffff",
+ "file_rail_hover": "#ffffff",
+ "file_rail_ink": "#000000",
+ "file_recovery": "#ffffff",
+ "file_recovery_border": "#000000",
+ "file_recovery_ink": "#000000",
+ "file_recovery_well": "#ffffff",
+ "file_surface": "#ffffff",
+ "form_accent": "#000000",
+ "form_dim": "#000000",
+ "form_error": "#000000",
+ "form_error_fill": "#ffffff",
+ "form_fill": "#000000",
+ "form_ink": "#000000",
+ "form_primary": "#ffffff",
+ "form_primary_fill": "#000000",
+ "form_soft": "#ffffff",
+ "form_success": "#000000",
+ "form_success_fill": "#ffffff",
+ "form_tab_ink": "#000000",
+ "glyph_bg": "#ffffff",
+ "glyph_edge": "#000000",
+ "glyph_text": "#000000",
+ "grid": "#ffffff",
+ "grid_major": "#000000",
+ "hover": "#ffffff",
+ "hover_edge": "#000000",
+ "hover_edge_halo": "#ffffff",
+ "hover_profile": "#000000",
+ "hover_profile_edge": "#ffffff",
+ "icon": "#000000",
+ "icons.agent": "#000000",
+ "icons.highlight": "#ffffff",
+ "icons.marker_halo": "#ffffff",
+ "interference": "#000000",
+ "logo": [
+ "#000000",
+ "#000000",
+ "#000000"
+ ],
+ "manipulator": "#000000",
+ "mesh_accent": "#000000",
+ "mesh_fill": "#000000",
+ "mesh_ink": "#000000",
+ "mesh_soft": "#ffffff",
+ "on_accent": "#ffffff",
+ "origin_plane": "#ffffff",
+ "origin_plane_edge": "#000000",
+ "origin_plane_hover": "#000000",
+ "origin_point": "#000000",
+ "overlay": "#ffffff",
+ "panel": "#ffffff",
+ "panel_header": "#ffffff",
+ "preview_add": "#000000",
+ "preview_cut": "#000000",
+ "preview_new": "#000000",
+ "preview_sketch": "#000000",
+ "profile_fill": "#ffffff",
+ "render_accent": "#000000",
+ "render_fill": "#000000",
+ "render_ink": "#000000",
+ "render_soft": "#ffffff",
+ "rubber_band": "#000000",
+ "section_cap": "#000000",
+ "sel_edge": "#ffffff",
+ "sel_edge_rim": "#ffffff",
+ "sel_face": "#000000",
+ "sel_profile": "#000000",
+ "sel_profile_edge": "#ffffff",
+ "sel_vertex": "#000000",
+ "selected_bg": "#000000",
+ "selected_ink": "#ffffff",
+ "sheet_fill": "#000000",
+ "sheet_ink": "#000000",
+ "sheet_soft": "#ffffff",
+ "sketch": "#000000",
+ "sketch_accent": "#000000",
+ "sketch_centerline": "#000000",
+ "sketch_construction": "#000000",
+ "sketch_fixed": "#000000",
+ "sketch_halo": "#ffffff",
+ "sketch_ink": "#000000",
+ "sketch_locked": "#000000",
+ "sketch_lost": "#000000",
+ "sketch_point": "#000000",
+ "sketch_point_free": "#000000",
+ "sketch_projected": "#000000",
+ "sketch_soft": "#ffffff",
+ "surface_accent": "#000000",
+ "surface_fill": "#000000",
+ "surface_ink": "#000000",
+ "surface_soft": "#ffffff",
+ "tab_on_fill_dark": "#000000",
+ "text": "#000000",
+ "text_dim": "#000000",
+ "timeline": "#ffffff",
+ "timeline_item": "#ffffff",
+ "timeline_item_error": "#ffffff",
+ "timeline_marker": "#000000",
+ "toolbar": "#ffffff",
+ "viewport_bottom": "#ffffff",
+ "viewport_top": "#ffffff",
+ "warning": "#000000"
+ },
+ "format": "solidcraft-theme/1",
+ "name": "1-bit",
+ "radii": {
+ "radius_sm": 0,
+ "radius_md": 0,
+ "radius_lg": 0,
+ "radius_xl": 0,
+ "control_radius": 0,
+ "sketch_mode_radius": 0
+ },
+ "icon_palette": {
+ "ink": "#000000",
+ "line": "#000000",
+ "passive-1": "#ffffff",
+ "passive-2": "#ffffff",
+ "passive-3": "#ffffff",
+ "guide": "#000000",
+ "solid": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "surface": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "mesh": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "form": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "sketch": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "constraint": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "construction": [
+ "#ffffff",
+ "#ffffff",
+ "#000000"
+ ],
+ "active-1": "#ffffff",
+ "active-2": "#ffffff",
+ "active-3": "#000000",
+ "component-orange-1": "#ffffff",
+ "component-orange-2": "#ffffff",
+ "component-orange-3": "#000000",
+ "component-yellow-1": "#ffffff",
+ "component-yellow-2": "#ffffff",
+ "component-yellow-3": "#000000"
+ },
+ "borders": {
+ "primary": {
+ "width": 1,
+ "color": "#000000"
+ },
+ "secondary": {
+ "width": 1,
+ "color": "#000000"
+ },
+ "tertiary": {
+ "width": 1,
+ "color": "#000000"
+ },
+ "container": {
+ "width": 1,
+ "color": "#000000"
+ },
+ "control": {
+ "width": 1,
+ "color": "#000000"
+ }
+ }
+}
diff --git a/assets/styles/ui/themes/cga.json b/assets/styles/ui/themes/cga.json
index 56bc8b3e90..ce334652dd 100644
--- a/assets/styles/ui/themes/cga.json
+++ b/assets/styles/ui/themes/cga.json
@@ -71,6 +71,7 @@
"form_fill": "#ff5555",
"form_ink": "#ffffff",
"form_primary": "#ff55ff",
+ "form_primary_fill": "#ff55ff",
"form_soft": "#000000",
"form_success": "#55ff55",
"form_success_fill": "#000000",
diff --git a/attribution/pending/theme-1-bit.md b/attribution/pending/theme-1-bit.md
new file mode 100644
index 0000000000..f5f8868e99
--- /dev/null
+++ b/attribution/pending/theme-1-bit.md
@@ -0,0 +1,2 @@
+| assets/styles/ui/themes/1-bit.json | SolidCraft contributors | original SolidCraft theme file | MIT OR Apache-2.0 |
+| assets/styles/ui/themes/1-bit-dark.json | SolidCraft contributors | original SolidCraft theme file | MIT OR Apache-2.0 |
diff --git a/crates/ui-egui/src/colour_vision_tests.rs b/crates/ui-egui/src/colour_vision_tests.rs
index 9b54848c77..607835ebfc 100644
--- a/crates/ui-egui/src/colour_vision_tests.rs
+++ b/crates/ui-egui/src/colour_vision_tests.rs
@@ -387,6 +387,7 @@ const NO_MEANING: &[(&str, &str)] = &[
("borders.bevel", "structural chrome: hierarchy uses width, pattern and placement, not hue"),
("icon_palette", "optional SVG palette; actual roles and theme contrast are guarded in icon and theme tests"),
("file_dim", "File view secondary text, WCAG guarded in theme tests"),
+ ("form_primary_fill", "ground under a filled primary field; form_primary carries the meaning, contrast guarded in theme tests"),
("file_recovery_well", "decorative recovery icon ground"),
("file_action_height", "layout dimension"),
("file_back_height", "layout dimension"),
diff --git a/crates/ui-egui/src/icon_svg.rs b/crates/ui-egui/src/icon_svg.rs
index 05552ea0dc..7a75fb3322 100644
--- a/crates/ui-egui/src/icon_svg.rs
+++ b/crates/ui-egui/src/icon_svg.rs
@@ -853,7 +853,8 @@ mod tests {
for file in crate::theme_files::builtin() {
let tokens = crate::theme_files::resolve(file);
let palette = tokens.icon_palette.expect("shipped icon palette");
- for ramp in palette.accents.into_iter().flatten() {
+ // Two colours can't make a pale/medium/strong ramp three distinct shades (1-bit, 1-bit Dark).
+ for ramp in palette.accents.into_iter().flatten().filter(|_| !crate::theme_files::is_two_colour(&file.id)) {
// Ordered faces stay visibly distinct without changing accepted paths.
assert_ne!(ramp[0], ramp[1], "{} pale/medium", file.id);
assert_ne!(ramp[1], ramp[2], "{} medium/strong", file.id);
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index 71086dba59..16358f2177 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -587,6 +587,8 @@ pub struct Tokens {
pub form_ink: Color32,
pub form_dim: Color32,
pub form_primary: Color32,
+ /// Primary action fill; theme files without this token inherit `form_primary`.
+ pub form_primary_fill: Color32,
pub form_error: Color32,
pub form_error_fill: Color32,
/// Successful validation text and its badge surface.
diff --git a/crates/ui-egui/src/theme_files.rs b/crates/ui-egui/src/theme_files.rs
index dbe6bde907..d877e69187 100644
--- a/crates/ui-egui/src/theme_files.rs
+++ b/crates/ui-egui/src/theme_files.rs
@@ -313,7 +313,7 @@ theme_keys! {
sketch_ink, sketch_soft, surface_fill, surface_ink, surface_soft, mesh_fill, mesh_ink, mesh_soft, form_fill, form_tab_ink, form_soft, sheet_fill, sheet_ink, sheet_soft, render_fill, render_ink, render_soft, tab_on_fill_dark,
app_bar_separator, surface_accent, mesh_accent, form_accent, render_accent, on_accent, agent_ok, agent_busy, app_bar_hover_subtle,
app_bar_hover_button, app_bar_hover_strong, app_bar_tab_active,
- form_ink, form_dim, form_primary, form_error, form_error_fill, form_success, form_success_fill, dialog_body, dialog_footer, dialog_rule, control_fill, control_border, dialog_label, selected_ink, selected_bg,
+ form_ink, form_dim, form_primary, form_primary_fill, form_error, form_error_fill, form_success, form_success_fill, dialog_body, dialog_footer, dialog_rule, control_fill, control_border, dialog_label, selected_ink, selected_bg,
],
many: [continuity, logo],
icons: [highlight, agent, marker_halo],
@@ -487,6 +487,9 @@ pub fn resolve(theme: &ThemeFile) -> Tokens {
s.copy_from_slice(&c);
}
}
+ if !theme.colors.contains_key("form_primary_fill") {
+ t.form_primary_fill = t.form_primary;
+ }
for (key, value) in &theme.radii {
if *value <= MAX_RADIUS
&& let Some(slot) = radius_slot(&mut t, key)
@@ -610,8 +613,8 @@ pub fn export(name: &str, base: Base, t: &Tokens) -> Value {
json!({"format": FORMAT, "name": name, "base": base, "colors": colors, "radii": radii, "borders": borders, "icon_palette": icon_palette})
}
-/// The theme files that come with SolidCraft (original files; Gruvbox, Tokyo Night, Solarized, Nord, Nosferatu and Catppuccin map open-source palettes, MIT; Okibi and Akari map the Okibi design system; Clay and Clay Dark are original warm paper and charcoal palettes; CGA keeps to the 16 colours of the IBM Color Graphics Adapter).
-const BUILTIN: [(&str, &str); 25] = [
+/// The theme files that come with SolidCraft (original files; Gruvbox, Tokyo Night, Solarized, Nord, Nosferatu and Catppuccin map open-source palettes, MIT; Okibi and Akari map the Okibi design system; Clay and Clay Dark are original warm paper and charcoal palettes; CGA keeps to the 16 colours of the IBM Color Graphics Adapter; 1-bit and 1-bit Dark are original black-and-white palettes).
+const BUILTIN: [(&str, &str); 27] = [
("gruvbox-dark", include_str!("../../../assets/styles/ui/themes/gruvbox-dark.json")),
("gruvbox-dark-hard", include_str!("../../../assets/styles/ui/themes/gruvbox-dark-hard.json")),
("gruvbox-dark-soft", include_str!("../../../assets/styles/ui/themes/gruvbox-dark-soft.json")),
@@ -619,6 +622,8 @@ const BUILTIN: [(&str, &str); 25] = [
("gruvbox-light-hard", include_str!("../../../assets/styles/ui/themes/gruvbox-light-hard.json")),
("gruvbox-light-soft", include_str!("../../../assets/styles/ui/themes/gruvbox-light-soft.json")),
("solidcraft-95", include_str!("../../../assets/styles/ui/themes/solidcraft-95.json")),
+ ("1-bit", include_str!("../../../assets/styles/ui/themes/1-bit.json")),
+ ("1-bit-dark", include_str!("../../../assets/styles/ui/themes/1-bit-dark.json")),
("platinum-9", include_str!("../../../assets/styles/ui/themes/platinum-9.json")),
("cupertino", include_str!("../../../assets/styles/ui/themes/cupertino.json")),
("green-phosphor", include_str!("../../../assets/styles/ui/themes/green-phosphor.json")),
@@ -639,6 +644,13 @@ const BUILTIN: [(&str, &str); 25] = [
("cga", include_str!("../../../assets/styles/ui/themes/cga.json")),
];
+/// The two-colour built-in themes (1-bit and 1-bit Dark): pure black and white, so a few looks
+/// other themes tell apart by colour are told apart by text or shape instead.
+#[cfg(test)]
+pub(crate) fn is_two_colour(id: &str) -> bool {
+ matches!(id, "1-bit" | "1-bit-dark")
+}
+
/// The built-in themes, read once (one that fails to read is left out; a test reads them all).
pub fn builtin() -> &'static [ThemeFile] {
static THEMES: OnceLock<Vec<ThemeFile>> = OnceLock::new();
@@ -804,23 +816,106 @@ mod tests {
for file in builtin() {
let t = resolve(file);
assert!(t.icon_palette.is_some(), "{} has no icon palette", file.id);
+ // A two-colour theme (1-bit, 1-bit Dark) can't give each workspace its own fill; it
+ // still has to keep every tab readable, below.
+ let two_colour = is_two_colour(&file.id);
let mut fills = std::collections::HashSet::new();
for tab in ["MODEL", "SURFACE", "MESH", "FORM", "SHEET METAL", "RENDER", "SKETCH"] {
let accent = TabAccent::for_tab(&t, tab);
- assert!(fills.insert(accent.color), "{} repeats {tab}", file.id);
+ assert!(fills.insert(accent.color) || two_colour, "{} repeats {tab}", file.id);
assert!(contrast_ratio(accent.ink, accent.soft) >= 4.5, "{} {tab} soft text", file.id);
assert!(contrast_ratio(accent.on_fill(&t), accent.color) >= 4.5, "{} {tab} pill text", file.id);
}
}
}
+ #[test]
+ fn one_bit_themes_are_complete_opaque_black_and_white() {
+ for (id, name, base) in [("1-bit", "1-bit", Base::Light), ("1-bit-dark", "1-bit Dark", Base::Dark)] {
+ assert!(is_two_colour(id));
+ let file = find(id, &[]).unwrap();
+ assert_eq!(file.name, name);
+ assert_eq!(file.base, base);
+ one_bit_is_complete_opaque_black_and_white(file);
+ }
+ }
+
+ fn one_bit_is_complete_opaque_black_and_white(file: &ThemeFile) {
+ let t = resolve(file);
+ let exported = export(&file.name, file.base, &t);
+ let mut resolved = t;
+ for key in keys() {
+ for color in slot(&mut resolved, key).unwrap() {
+ let [r, g, b, _] = color.to_srgba_unmultiplied();
+ assert!(matches!([r, g, b], [0, 0, 0] | [255, 255, 255]), "{}: {key}: {color:?}", file.id);
+ }
+ assert!(file.colors.contains_key(key), "{}: missing {key}", file.id);
+ }
+ fn check(value: &Value) {
+ match value {
+ Value::String(color) if color.starts_with('#') => {
+ assert!(matches!(color.as_str(), "#000000" | "#ffffff"), "{color}");
+ }
+ Value::Array(values) => values.iter().for_each(check),
+ Value::Object(values) => values.values().for_each(check),
+ _ => {}
+ }
+ }
+ check(&exported);
+ for role in crate::icon_svg::ROLE_NAMES.iter().filter(|role| **role != "gap") {
+ assert!(file.icon_palette.contains_key(*role), "{}: missing icon role {role}", file.id);
+ }
+ for ramp in std::iter::once("solid").chain(crate::icon_svg::ACCENT_NAMES.iter().copied()) {
+ assert!(file.icon_palette.contains_key(ramp), "{}: missing icon ramp {ramp}", file.id);
+ }
+ assert_eq!(radius_values(t), [0; 6]);
+ }
+
+ #[test]
+ fn one_bit_selection_and_viewport_tokens_have_full_contrast() {
+ for (id, paper, ink) in [("1-bit", Color32::WHITE, Color32::BLACK), ("1-bit-dark", Color32::BLACK, Color32::WHITE)] {
+ one_bit_has_full_contrast(&resolve(find(id, &[]).unwrap()), id, paper, ink);
+ }
+ }
+
+ /// `paper` is the theme's page (panels, viewport, bodies, hover); `ink` its text, and its selection.
+ fn one_bit_has_full_contrast(t: &Tokens, id: &str, paper: Color32, ink: Color32) {
+ assert_eq!((t.text, t.panel), (ink, paper), "{id}");
+ for (fg, bg) in [
+ (t.text, t.panel),
+ (t.text_dim, t.field),
+ (t.icon, t.toolbar),
+ (t.app_bar_text, t.app_bar_tab_active),
+ (t.selected_ink, t.selected_bg),
+ (t.text, t.hover),
+ (t.app_bar_text, t.app_bar_hover),
+ (t.body_edge, t.body),
+ (t.sel_edge, t.body_selected),
+ (t.dimension, t.viewport_top),
+ (t.sketch, t.viewport_bottom),
+ (t.glyph_text, t.glyph_bg),
+ (t.dialog_label, t.dialog_body),
+ ] {
+ assert_eq!(crate::theme::contrast_ratio(fg, bg), 21.0, "{id}: {fg:?} on {bg:?}");
+ }
+ assert_eq!((t.viewport_top, t.viewport_bottom, t.body), (paper, paper, paper), "{id}");
+ assert_eq!((t.selected_bg, t.body_selected), (ink, ink), "{id}");
+ // Hover fills are the paper, so a hovered row, card or tab never swallows its ink label.
+ for hover in [t.hover, t.app_bar_hover, t.app_bar_hover_subtle, t.app_bar_hover_button, t.app_bar_hover_strong] {
+ assert_eq!(hover, paper, "{id}: hover fill");
+ }
+ assert_eq!((t.body_edge, t.selected_ink), (ink, paper), "{id}");
+ // Thumbnails and other pictures keep their own pixels: the tint stays neutral white.
+ assert_eq!(t.file_image_tint, Color32::WHITE, "{id}");
+ }
+
#[test]
fn built_in_themes_read_and_differ_from_their_base() {
assert_eq!(builtin().len(), BUILTIN.len(), "every built-in theme file reads");
for t in builtin() {
let base = if t.base.is_dark() { Tokens::dark() } else { Tokens::light() };
assert_ne!(resolve(t), base, "{}", t.id);
- if t.id.starts_with("gruvbox-") {
+ if t.id.starts_with("gruvbox-") || is_two_colour(&t.id) {
assert_eq!(t.base.is_dark(), t.id.contains("dark"), "{}", t.id);
}
}
diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rs
index 823ca7e67d..98c9fbf867 100644
--- a/crates/ui-egui/src/ui_kit/actions.rs
+++ b/crates/ui-egui/src/ui_kit/actions.rs
@@ -195,7 +195,7 @@ impl ActionLook {
} else if danger {
t.form_error
} else {
- t.form_primary
+ t.form_primary_fill
};
let primary_ink = if t.borders.bevel.is_some() && !danger {
t.form_ink
@@ -409,8 +409,8 @@ fn button_widget(label: egui::WidgetText, options: Button) -> egui::Button<'stat
match options {
Button::Small => egui::Button::new(label).small(),
Button::Primary => {
- let ink = if crate::theme::contrast_ratio(t.on_accent, t.form_primary) >= 4.5 { t.on_accent } else { t.tab_on_fill_dark };
- egui::Button::new(label.color(ink)).fill(t.form_primary)
+ let ink = if crate::theme::contrast_ratio(t.on_accent, t.form_primary_fill) >= 4.5 { t.on_accent } else { t.tab_on_fill_dark };
+ egui::Button::new(label.color(ink)).fill(t.form_primary_fill)
}
Button::Ghost => egui::Button::new(label).frame(false),
Button::SmallSelected => {
@@ -480,7 +480,7 @@ pub(crate) fn wide_primary_button(ui: &mut Ui, label: &str) -> Response {
.inner_margin(egui::Margin::symmetric(t.space_10 as i8, t.space_6 as i8))
.show(ui, |ui| {
let button = egui::Button::new(crate::fonts::RichTextExt::bold_face(text))
- .fill(if bevel { t.control_fill } else { t.form_primary })
+ .fill(if bevel { t.control_fill } else { t.form_primary_fill })
.stroke(egui::Stroke::NONE)
.corner_radius(t.control_radius);
ui.add_sized(vec2(dimension(ui.available_width()), t.form_button_height), button)
diff --git a/crates/ui-egui/src/ui_kit/actions_tests.rs b/crates/ui-egui/src/ui_kit/actions_tests.rs
index 1f8a933223..d714b7e062 100644
--- a/crates/ui-egui/src/ui_kit/actions_tests.rs
+++ b/crates/ui-egui/src/ui_kit/actions_tests.rs
@@ -136,3 +136,51 @@ fn positioned_shared_buttons_center_text_and_respect_disabled_clicks_in_both_the
}
crate::theme::set_dark(previous);
}
+
+#[test]
+fn one_bit_primary_actions_keep_inverted_labels_and_legacy_fills() {
+ use crate::theme::{Tokens, scoped_tokens};
+ use egui::{Color32, Shape};
+
+ for base in [crate::theme_files::Base::Dark, crate::theme_files::Base::Light] {
+ let old = crate::theme_files::parse(&format!(
+ r##"{{"format":"solidcraft-theme/1","name":"Old","base":"{}","colors":{{"form_primary":"#123456"}}}}"##,
+ if base.is_dark() { "dark" } else { "light" }
+ ))
+ .unwrap();
+ let t = crate::theme_files::resolve(&old);
+ assert_eq!(t.form_primary_fill, t.form_primary);
+ }
+ for theme in crate::theme_files::builtin().iter().filter(|theme| !crate::theme_files::is_two_colour(&theme.id)) {
+ let t = crate::theme_files::resolve(theme);
+ assert_eq!(t.form_primary_fill, t.form_primary, "{} retains its primary fill", theme.id);
+ }
+ // 1-bit's primary actions are black with white labels; 1-bit Dark's the reverse.
+ for (id, fill, ink) in [("1-bit", Color32::BLACK, Color32::WHITE), ("1-bit-dark", Color32::WHITE, Color32::BLACK)] {
+ let t = crate::theme_files::resolve(crate::theme_files::find(id, &[]).unwrap());
+ let _restore = scoped_tokens(t);
+ assert_eq!(Tokens::get().form_primary_fill, fill, "{id}");
+ let ctx = crate::fonts::test_context();
+ let mut rects = Vec::new();
+ let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
+ ui.set_width(400.0);
+ scope(ui, |ui| {
+ rects.push(primary_button(ui, "Primary").rect);
+ rects.push(wide_primary_button(ui, "Wide").rect);
+ footer(ui, "OK", "Cancel", true, Footer::default());
+ rects.push(scenario::rect_of("dialog:ok").unwrap());
+ });
+ });
+ output.textures_delta.clear();
+ for rect in rects {
+ assert!(
+ output.shapes.iter().any(|shape| matches!(&shape.shape, Shape::Rect(r) if rect.contains_rect(r.rect) && r.fill == fill)),
+ "{id}: {rect:?} has its fill"
+ );
+ assert!(
+ output.shapes.iter().any(|shape| matches!(&shape.shape, Shape::Text(text) if rect.contains(text.pos) && text.galley.job.sections.iter().all(|section| section.format.color == ink))),
+ "{id}: {rect:?} has its label ink"
+ );
+ }
+ }
+}
diff --git a/crates/ui-egui/src/ui_kit/checks.rs b/crates/ui-egui/src/ui_kit/checks.rs
index e17bd2c47e..de96a13a10 100644
--- a/crates/ui-egui/src/ui_kit/checks.rs
+++ b/crates/ui-egui/src/ui_kit/checks.rs
@@ -26,7 +26,7 @@ pub(super) fn paint_box(ui: &Ui, square: Rect, response: &Response, on: bool, mi
let fill = if t.borders.bevel.is_some() {
t.input_fill()
} else if selected {
- t.form_primary
+ t.form_primary_fill
} else if response.hovered() {
t.hover
} else {
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index 78aff21534..5d5b391762 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -313,17 +313,21 @@ pub(crate) fn selection_field(ui: &mut Ui, text: &str, options: Selection) -> Re
let Selection { active, filled } = options;
let t = Tokens::get();
let (rect, response) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::CLICK);
- if active && !filled {
+ // A separate action fill lets two-colour palettes reserve the focus accent for inverted ink.
+ let inverted = t.form_primary_fill != t.form_primary;
+ if active && !filled && !inverted {
ui.painter().rect_filled(rect, t.control_radius, t.selected_bg);
}
let (fill, border) = match (active, filled) {
+ (true, _) if inverted => (t.selected_bg, t.form_primary),
+ (false, _) if inverted => (t.control_fill, t.control_border),
(true, true) => (t.selected_bg, t.form_primary),
(true, false) => (t.control_fill, t.form_primary),
(false, true) => (t.control_fill.lerp_to_gamma(t.form_ink, 0.06), t.control_border.lerp_to_gamma(t.form_ink, 0.35)),
(false, false) => (t.control_fill, t.control_border),
};
ui.painter().rect(
- if active && !filled { rect.shrink(t.space_2) } else { rect },
+ if active && !filled && !inverted { rect.shrink(t.space_2) } else { rect },
t.control_radius,
fill,
match (active, filled) {
@@ -345,6 +349,7 @@ pub(crate) fn selection_field(ui: &mut Ui, text: &str, options: Selection) -> Re
text,
crate::fonts::medium(t.font_label),
match (active, filled) {
+ (true, _) if inverted => t.selected_ink,
(true, true) => t.selected_ink,
(false, true) => t.form_ink,
_ => t.form_dim,
diff --git a/crates/ui-egui/src/ui_kit/fields_tests.rs b/crates/ui-egui/src/ui_kit/fields_tests.rs
index 4a57eb5c7c..c3376ef071 100644
--- a/crates/ui-egui/src/ui_kit/fields_tests.rs
+++ b/crates/ui-egui/src/ui_kit/fields_tests.rs
@@ -358,8 +358,31 @@ fn selection_field_has_three_distinct_looks_in_every_theme() {
assert!(!accented(&filled), "{name}: a filled inactive input is not accented: {filled:?}");
assert!(!accented(&empty), "{name}: an empty inactive input is not accented: {empty:?}");
let outline = |l: &Look| l.0.last().copied().unwrap();
- assert_ne!(outline(&filled).0, outline(&empty).0, "{name}: filled and empty fills differ");
- assert_ne!(outline(&filled).1, outline(&empty).1, "{name}: filled and empty borders differ");
+ // Two colours can't give filled and empty their own fill and border on top of the accent;
+ // in 1-bit and 1-bit Dark the text itself tells them apart (a count against the prompt).
+ if crate::theme_files::is_two_colour(&name) {
+ // Inactive inputs are the page with an ink border: white on black in 1-bit, the
+ // reverse in 1-bit Dark.
+ let (paper, ink) = if dark { (egui::Color32::BLACK, egui::Color32::WHITE) } else { (egui::Color32::WHITE, egui::Color32::BLACK) };
+ for look in [&active_filled, &active_empty, &filled, &empty] {
+ for &(fill, border) in &look.0 {
+ for color in [fill, border] {
+ assert!(matches!(color, egui::Color32::BLACK | egui::Color32::WHITE), "{name}: {look:?}");
+ }
+ }
+ }
+ for look in [&active_filled, &active_empty] {
+ assert_eq!(outline(look).0, t.selected_bg, "{name}");
+ assert_eq!(outline(look).0, ink, "{name}: the active input is inverted");
+ assert_eq!(look.1, Some(t.selected_ink), "{name}");
+ }
+ for look in [&filled, &empty] {
+ assert_eq!(outline(look), (paper, ink), "{name}");
+ }
+ } else {
+ assert_ne!(outline(&filled).0, outline(&empty).0, "{name}: filled and empty fills differ");
+ assert_ne!(outline(&filled).1, outline(&empty).1, "{name}: filled and empty borders differ");
+ }
assert_eq!(filled.1, Some(t.form_ink), "{name}: a filled input's count is in text colour");
assert_eq!(empty.1, Some(t.form_dim), "{name}: an empty input's prompt is dim");
}
diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md
index dcddfb5bda..f8723fe447 100644
--- a/docs/book/src/guide/ui-tour.md
+++ b/docs/book/src/guide/ui-tour.md
@@ -141,9 +141,11 @@ Interface › **Theme** lists Dark, Light and System (follows the operating syst
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
(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, High
-Contrast, Graphite, Nosferatu, Catppuccin Mocha, and Okibi and Akari (dark and light, from the
-[Okibi design system](https://kaievns.github.io/okibi-akiri-design-system-spec/)), and Clay and
-Clay Dark (warm ivory paper and warm charcoal, with a terracotta accent and rounded corners).
+Contrast, Graphite, Nosferatu, Catppuccin Mocha, Okibi and Akari (dark and light, from the
+[Okibi design system](https://kaievns.github.io/okibi-akiri-design-system-spec/)), Clay and
+Clay Dark (warm ivory paper and warm charcoal, with a terracotta accent and rounded corners), and
+1-bit and 1-bit Dark (pure black and white with square corners: black on white, or white on
+black, with selections drawn inverted).
A theme is a small JSON file that starts from the Dark or Light palette and changes any of its
colours and corner radii by name:
@@ -186,7 +188,7 @@ respectively. The first four style small accents through large surfaces; `contro
styles form controls, and `sketch_mode_radius` styles sketch creation buttons. Themes own
these settings, with matching shapes across light and dark variants. Dock joins remain
square, circular controls remain circular, and control sizes and spacing stay the same.
-Platinum 9 and the phosphor themes use square corners, SolidCraft 95 uses subtle 3-point
+Platinum 9, 1-bit, 1-bit Dark, and the phosphor themes use square corners, SolidCraft 95 uses subtle 3-point
corners, Blueprint uses the standard radii, Cupertino uses softer corners, and Clay and Clay Dark use rounded corners. Other built-in
themes retain the defaults.