microcad_core/
theme.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Color theme
5
6use crate::color::Color;
7
8/// Represents a color theme.
9#[derive(Clone, Debug, PartialEq)]
10pub struct Theme {
11    /// Name of the theme.
12    pub name: String,
13    /// Filename of the theme, if it was loaded from file.
14    pub filename: Option<String>,
15    /// Background color of the drawing canvas
16    pub background: Color,
17    /// Color used for grid lines
18    pub grid: Color,
19    /// Color used for selected entities
20    pub selection: Color,
21    /// Color used for highlighting hovered entities
22    pub highlight: Color,
23    /// Default color for entities
24    pub entity: Color,
25    /// Default color for entity outlines
26    pub outline: Color,
27    /// Color used for active construction lines
28    pub active: Color,
29    /// Color used for inactive construction lines
30    pub inactive: Color,
31    /// Color for dimensions and annotations
32    pub measure: Color,
33    /// Color for snapping indicators
34    pub snap_indicator: Color,
35    /// Color for guidelines (e.g. inference lines)
36    pub guide: Color,
37}
38
39impl Theme {
40    /// Dark theme.
41    pub fn dark() -> Self {
42        Self {
43            name: "default/dark".into(),
44            filename: None,
45            background: Color::rgb(0.1, 0.1, 0.1),
46            grid: Color::rgb(0.2, 0.2, 0.2),
47            selection: Color::rgb(1.0, 0.6, 0.0),
48            highlight: Color::rgb(1.0, 1.0, 0.0),
49            entity: Color::rgba(0.9, 0.9, 0.9, 0.7),
50            outline: Color::rgb(0.1, 0.1, 0.1),
51            active: Color::rgb(0.8, 0.8, 0.8),
52            inactive: Color::rgb(0.4, 0.4, 0.4),
53            measure: Color::rgb(0.0, 0.8, 0.8),
54            snap_indicator: Color::rgb(0.0, 1.0, 1.0),
55            guide: Color::rgb(0.6, 0.6, 0.6),
56        }
57    }
58
59    /// Light theme.
60    pub fn light() -> Self {
61        Self {
62            name: "default/light".into(),
63            filename: None,
64            background: Color::rgb(1.0, 1.0, 1.0),
65            grid: Color::rgb(0.85, 0.85, 0.85),
66            selection: Color::rgb(0.0, 0.4, 0.8),
67            highlight: Color::rgb(1.0, 0.6, 0.0),
68            entity: Color::rgba(0.7, 0.7, 0.7, 0.7),
69            outline: Color::rgb(0.1, 0.1, 0.1),
70            active: Color::rgb(0.2, 0.2, 0.2),
71            inactive: Color::rgb(0.8, 0.8, 0.8),
72            measure: Color::rgb(0.0, 0.8, 0.8),
73            snap_indicator: Color::rgb(0.0, 0.8, 0.8),
74            guide: Color::rgb(0.6, 0.6, 0.6),
75        }
76    }
77}
78
79impl Default for Theme {
80    fn default() -> Self {
81        Self::light()
82    }
83}