Skip to main content

matrix_gui/
style.rs

1use crate::ui_font::{DEFAULT_FONT_ASCII, DEFAULT_FONT_LATIN_6, UiFont};
2use embedded_graphics::pixelcolor::{BinaryColor, PixelColor, Rgb565};
3use embedded_graphics::prelude::*;
4
5/// Macro to create Rgb565 colors from 24-bit RGB values, eg. `rgb565!(0xRRGGBB)`
6#[macro_export]
7macro_rules! rgb565 {
8    ($rgb:expr) => {
9        Rgb565::new(
10            (($rgb >> (3 + 16)) & 0xFF) as u8,
11            (($rgb >> (2 + 8)) & 0xFF) as u8,
12            (($rgb >> 3) & 0xFF) as u8,
13        )
14    };
15}
16
17pub fn rgb565_debug_style() -> Style<Rgb565> {
18    Style {
19        background_color: Rgb565::BLACK,
20        border_color: Rgb565::RED,
21        text_color: Rgb565::WHITE,
22        border_width: 1,
23        default_font: DEFAULT_FONT_LATIN_6,
24        default_padding: Size::new(4, 4),
25        corner_radius: 5,
26    }
27}
28
29pub fn rgb565_basic_style() -> Style<Rgb565> {
30    Style {
31        background_color: Rgb565::new(0x4, 0x8, 0x4),
32        border_color: Rgb565::RED,
33        text_color: Rgb565::WHITE,
34        border_width: 1,
35        default_font: DEFAULT_FONT_LATIN_6,
36        default_padding: Size::new(2, 2),
37        corner_radius: 5,
38    }
39}
40
41pub fn rgb565_light_style() -> Style<Rgb565> {
42    Style {
43        background_color: Rgb565::CSS_WHITE,
44        border_color: Rgb565::CSS_BLACK,
45        text_color: Rgb565::CSS_BLACK,
46        border_width: 1,
47        default_font: DEFAULT_FONT_LATIN_6,
48        default_padding: Size::new(2, 2),
49        corner_radius: 5,
50    }
51}
52
53pub fn rgb565_binary_style() -> Style<BinaryColor> {
54    Style {
55        background_color: BinaryColor::Off,
56        border_color: BinaryColor::On,
57        text_color: BinaryColor::On,
58        border_width: 1,
59        default_font: DEFAULT_FONT_ASCII,
60        default_padding: Size::new(2, 2),
61        corner_radius: 0,
62    }
63}
64
65#[derive(Debug, Clone, Copy)]
66pub struct Style<COL: PixelColor> {
67    pub default_font: UiFont<'static>,
68    pub background_color: COL,
69    pub border_color: COL,
70    pub text_color: COL,
71    pub default_padding: Size,
72    pub corner_radius: u8,
73    pub border_width: u8,
74}