1use crate::lvgl;
2
3#[derive(Copy, Clone, Debug, PartialEq)]
4pub struct ColorRGB888 {
5 red: u8,
6 green: u8,
7 blue: u8,
8}
9
10impl ColorRGB888 {
11 pub const WHITE: ColorRGB888 = ColorRGB888::new(0xFF, 0xFF, 0xFF);
12 pub const BLACK: ColorRGB888 = ColorRGB888::new(0x00, 0x00, 0x00);
13
14 pub const fn new(red: u8, green: u8, blue: u8) -> Self {
15 Self { red, green, blue }
16 }
17
18 pub const fn get_red(&self) -> u8 {
19 self.red
20 }
21
22 pub const fn get_green(&self) -> u8 {
23 self.green
24 }
25
26 pub const fn get_blue(&self) -> u8 {
27 self.blue
28 }
29
30 pub const fn set_red(mut self, value: u8) -> Self {
31 self.red = value;
32 self
33 }
34
35 pub const fn set_green(mut self, value: u8) -> Self {
36 self.green = value;
37 self
38 }
39
40 pub const fn set_blue(mut self, value: u8) -> Self {
41 self.blue = value;
42 self
43 }
44
45 pub const fn from_lvgl_color(value: lvgl::lv_color_t) -> Self {
46 Self::new(value.red, value.green, value.blue)
47 }
48
49 pub const fn into_lvgl_color(self) -> lvgl::lv_color_t {
50 lvgl::lv_color_t {
51 red: self.get_red(),
52 green: self.get_green(),
53 blue: self.get_blue(),
54 }
55 }
56}
57
58impl From<ColorRGB888> for lvgl::lv_color_t {
59 fn from(value: ColorRGB888) -> Self {
60 value.into_lvgl_color()
61 }
62}
63
64impl From<lvgl::lv_color_t> for ColorRGB888 {
65 fn from(value: lvgl::lv_color_t) -> Self {
66 ColorRGB888::from_lvgl_color(value)
67 }
68}