Skip to main content

gpui_liveplot/
style.rs

1//! Style and theming configuration.
2//!
3//! Themes describe plot-level colors (background, grid, axes, overlays).
4
5use crate::render::Color;
6
7/// Visual theme for plot-level elements such as axes, grid, and overlays.
8///
9/// Themes are applied at the plot level and affect all series and overlays.
10#[derive(Debug, Clone, PartialEq)]
11pub struct Theme {
12    /// Plot background color.
13    pub background: Color,
14    /// Axis, tick, and label color.
15    pub axis: Color,
16    /// Major grid line color.
17    pub grid_major: Color,
18    /// Minor grid line color.
19    pub grid_minor: Color,
20    /// Hover tooltip background color.
21    pub hover_bg: Color,
22    /// Hover tooltip border color.
23    pub hover_border: Color,
24    /// Pin tooltip background color.
25    pub pin_bg: Color,
26    /// Pin tooltip border color.
27    pub pin_border: Color,
28    /// Selection rectangle fill color.
29    pub selection_fill: Color,
30    /// Selection rectangle border color.
31    pub selection_border: Color,
32    /// Legend background color.
33    pub legend_bg: Color,
34    /// Legend border color.
35    pub legend_border: Color,
36}
37
38impl Theme {
39    /// Create the default theme (alias of [`Theme::dark`]).
40    pub fn new() -> Self {
41        Self::default()
42    }
43
44    /// Create a light theme palette.
45    pub fn light() -> Self {
46        Self {
47            background: Color::new(1.0, 1.0, 1.0, 1.0),
48            axis: Color::new(0.2, 0.2, 0.2, 1.0),
49            grid_major: Color::new(0.86, 0.86, 0.86, 1.0),
50            grid_minor: Color::new(0.93, 0.93, 0.93, 1.0),
51            hover_bg: Color::new(1.0, 1.0, 1.0, 0.9),
52            hover_border: Color::new(0.2, 0.2, 0.2, 0.8),
53            pin_bg: Color::new(1.0, 1.0, 1.0, 0.92),
54            pin_border: Color::new(0.2, 0.2, 0.2, 0.8),
55            selection_fill: Color::new(0.1, 0.4, 0.9, 0.15),
56            selection_border: Color::new(0.1, 0.4, 0.9, 0.9),
57            legend_bg: Color::new(1.0, 1.0, 1.0, 0.85),
58            legend_border: Color::new(0.2, 0.2, 0.2, 0.6),
59        }
60    }
61
62    /// Create a dark theme palette.
63    pub fn dark() -> Self {
64        Self {
65            background: Color::new(0.08, 0.08, 0.09, 1.0),
66            axis: Color::new(0.85, 0.85, 0.85, 1.0),
67            grid_major: Color::new(0.25, 0.25, 0.28, 1.0),
68            grid_minor: Color::new(0.18, 0.18, 0.2, 1.0),
69            hover_bg: Color::new(0.12, 0.12, 0.13, 0.92),
70            hover_border: Color::new(0.6, 0.6, 0.6, 0.8),
71            pin_bg: Color::new(0.12, 0.12, 0.13, 0.92),
72            pin_border: Color::new(0.6, 0.6, 0.6, 0.85),
73            selection_fill: Color::new(0.2, 0.5, 0.95, 0.18),
74            selection_border: Color::new(0.3, 0.6, 1.0, 0.9),
75            legend_bg: Color::new(0.12, 0.12, 0.13, 0.9),
76            legend_border: Color::new(0.5, 0.5, 0.5, 0.7),
77        }
78    }
79}
80
81impl Default for Theme {
82    fn default() -> Self {
83        Self::dark()
84    }
85}