embedded_graphics_simulator/
theme.rs

1use embedded_graphics::pixelcolor::{Rgb888, RgbColor};
2
3/// Color theme for binary displays
4#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
5pub enum BinaryColorTheme {
6    /// A simple on/off, non-styled display with black background and white pixels
7    #[default]
8    Default,
9
10    /// Inverted colors.
11    Inverted,
12
13    /// An on/off classic LCD-like display with white background
14    LcdWhite,
15
16    /// An on/off classic LCD-like display with green background and dark grey pixels
17    LcdGreen,
18
19    /// An on/off LCD-like display with light blue background and blue-white pixels
20    LcdBlue,
21
22    /// An on/off OLED-like display with a black background and white pixels
23    OledWhite,
24
25    /// An on/off OLED-like display with a dark blue background and light blue pixels
26    OledBlue,
27}
28
29fn map_color(color: Rgb888, color_off: Rgb888, color_on: Rgb888) -> Rgb888 {
30    match color {
31        Rgb888::BLACK => color_off,
32        _ => color_on,
33    }
34}
35
36impl BinaryColorTheme {
37    /// Gets the theme's pixel color for a given pixel state.
38    pub(crate) fn convert(self, color: Rgb888) -> Rgb888 {
39        match self {
40            BinaryColorTheme::Default => color,
41            BinaryColorTheme::Inverted => {
42                Rgb888::new(255 - color.r(), 255 - color.g(), 255 - color.b())
43            }
44            BinaryColorTheme::LcdWhite => {
45                map_color(color, Rgb888::new(245, 245, 245), Rgb888::new(32, 32, 32))
46            }
47            BinaryColorTheme::LcdGreen => {
48                map_color(color, Rgb888::new(120, 185, 50), Rgb888::new(32, 32, 32))
49            }
50            BinaryColorTheme::LcdBlue => {
51                map_color(color, Rgb888::new(70, 80, 230), Rgb888::new(230, 230, 255))
52            }
53            BinaryColorTheme::OledBlue => {
54                map_color(color, Rgb888::new(0, 20, 40), Rgb888::new(0, 210, 255))
55            }
56            BinaryColorTheme::OledWhite => map_color(color, Rgb888::new(20, 20, 20), Rgb888::WHITE),
57        }
58    }
59}