File tree 1 file changed +9
-21
lines changed
1 file changed +9
-21
lines changed Original file line number Diff line number Diff line change @@ -35,47 +35,35 @@ namespace Colors {
35
35
36
36
class Color {
37
37
public:
38
- constexpr Color (uint32_t color) {
39
- data.hexcode = color;
38
+ constexpr Color (uint32_t color) : data {color} {
40
39
}
41
40
42
41
operator uint32_t () const {
43
- return data. hexcode ;
42
+ return data;
44
43
}
45
44
46
- constexpr Color (uint8_t r, uint8_t g, uint8_t b) {
47
- data.argb .red = r;
48
- data.argb .green = g;
49
- data.argb .blue = b;
45
+ constexpr Color (uint8_t r, uint8_t g, uint8_t b)
46
+ : data {(static_cast <uint32_t >(r) << 16 ) | (static_cast <uint32_t >(g) << 8 ) | static_cast <uint32_t >(b)} {
50
47
}
51
48
52
49
operator lv_color_t () const {
53
- return lv_color_hex (data. hexcode );
50
+ return lv_color_hex (data);
54
51
}
55
52
56
53
uint8_t red () const {
57
- return data. argb . red ;
54
+ return ( data & 0xFF0000 ) >> 16 ;
58
55
}
59
56
60
57
uint8_t green () const {
61
- return data. argb . green ;
58
+ return ( data & 0x00FF00 ) >> 8 ;
62
59
}
63
60
64
61
uint8_t blue () const {
65
- return data. argb . blue ;
62
+ return ( data & 0x0000FF ) ;
66
63
}
67
64
68
65
private:
69
- union {
70
- uint32_t hexcode = 0 ;
71
-
72
- struct {
73
- uint8_t blue = 0 ;
74
- uint8_t green = 0 ;
75
- uint8_t red = 0 ;
76
- uint8_t alpha = 0 ;
77
- } argb;
78
- } data;
66
+ uint32_t data;
79
67
};
80
68
81
69
Color linear_gradient (Color startingColor, Color endingColor, uint8_t progress);
You can’t perform that action at this time.
0 commit comments