Skip to content

Commit ce2277c

Browse files
committed
infineat: Create colors at compile time.
lv_color_hex can't be evaluated at compile time, but LV_COLOR_MAKE can.
1 parent dd8a9a2 commit ce2277c

File tree

2 files changed

+119
-49
lines changed

2 files changed

+119
-49
lines changed

src/displayapp/screens/WatchFaceInfineat.cpp

+118-36
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,106 @@ namespace {
1717
auto* screen = static_cast<WatchFaceInfineat*>(obj->user_data);
1818
screen->UpdateSelected(obj, event);
1919
}
20+
21+
enum class colors {
22+
orange,
23+
blue,
24+
green,
25+
rainbow,
26+
gray,
27+
nordBlue,
28+
nordGreen,
29+
};
30+
31+
constexpr int nColors = 7; // must match number of colors in InfineatColors
32+
33+
constexpr int nLines = WatchFaceInfineat::nLines;
34+
35+
constexpr std::array<lv_color_t, nLines> orangeColors = {LV_COLOR_MAKE(0xfd, 0x87, 0x2b),
36+
LV_COLOR_MAKE(0xdb, 0x33, 0x16),
37+
LV_COLOR_MAKE(0x6f, 0x10, 0x00),
38+
LV_COLOR_MAKE(0xfd, 0x7a, 0x0a),
39+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
40+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
41+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
42+
LV_COLOR_MAKE(0xe8, 0x51, 0x02),
43+
LV_COLOR_MAKE(0xea, 0x1c, 0x00)};
44+
constexpr std::array<lv_color_t, nLines> blueColors = {LV_COLOR_MAKE(0xe7, 0xf8, 0xff),
45+
LV_COLOR_MAKE(0x22, 0x32, 0xd0),
46+
LV_COLOR_MAKE(0x18, 0x2a, 0x8b),
47+
LV_COLOR_MAKE(0xe7, 0xf8, 0xff),
48+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
49+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
50+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
51+
LV_COLOR_MAKE(0x59, 0x91, 0xff),
52+
LV_COLOR_MAKE(0x16, 0x36, 0xff)};
53+
constexpr std::array<lv_color_t, nLines> greenColors = {LV_COLOR_MAKE(0xb8, 0xff, 0x9b),
54+
LV_COLOR_MAKE(0x08, 0x86, 0x08),
55+
LV_COLOR_MAKE(0x00, 0x4a, 0x00),
56+
LV_COLOR_MAKE(0xb8, 0xff, 0x9b),
57+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
58+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
59+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
60+
LV_COLOR_MAKE(0x62, 0xd5, 0x15),
61+
LV_COLOR_MAKE(0x00, 0x74, 0x00)};
62+
constexpr std::array<lv_color_t, nLines> rainbowColors = {LV_COLOR_MAKE(0x2d, 0xa4, 0x00),
63+
LV_COLOR_MAKE(0xac, 0x09, 0xc4),
64+
LV_COLOR_MAKE(0xfe, 0x03, 0x03),
65+
LV_COLOR_MAKE(0x0d, 0x57, 0xff),
66+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
67+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
68+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
69+
LV_COLOR_MAKE(0xe0, 0xb9, 0x00),
70+
LV_COLOR_MAKE(0xe8, 0x51, 0x02)};
71+
constexpr std::array<lv_color_t, nLines> grayColors = {LV_COLOR_MAKE(0xee, 0xee, 0xee),
72+
LV_COLOR_MAKE(0x98, 0x95, 0x9b),
73+
LV_COLOR_MAKE(0x19, 0x19, 0x19),
74+
LV_COLOR_MAKE(0xee, 0xee, 0xee),
75+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
76+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
77+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
78+
LV_COLOR_MAKE(0x91, 0x91, 0x91),
79+
LV_COLOR_MAKE(0x3a, 0x3a, 0x3a)};
80+
constexpr std::array<lv_color_t, nLines> nordBlueColors = {LV_COLOR_MAKE(0xc3, 0xda, 0xf2),
81+
LV_COLOR_MAKE(0x4d, 0x78, 0xce),
82+
LV_COLOR_MAKE(0x15, 0x34, 0x51),
83+
LV_COLOR_MAKE(0xc3, 0xda, 0xf2),
84+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
85+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
86+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
87+
LV_COLOR_MAKE(0x5d, 0x8a, 0xd2),
88+
LV_COLOR_MAKE(0x21, 0x51, 0x8a)};
89+
constexpr std::array<lv_color_t, nLines> nordGreenColors = {LV_COLOR_MAKE(0xd5, 0xf0, 0xe9),
90+
LV_COLOR_MAKE(0x23, 0x83, 0x73),
91+
LV_COLOR_MAKE(0x1d, 0x41, 0x3f),
92+
LV_COLOR_MAKE(0xd5, 0xf0, 0xe9),
93+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
94+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
95+
LV_COLOR_MAKE(0xff, 0xff, 0xff),
96+
LV_COLOR_MAKE(0x2f, 0xb8, 0xa2),
97+
LV_COLOR_MAKE(0x11, 0x70, 0x5a)};
98+
99+
constexpr const std::array<lv_color_t, nLines>* returnColor(colors color) {
100+
if (color == colors::orange) {
101+
return &orangeColors;
102+
}
103+
if (color == colors::blue) {
104+
return &blueColors;
105+
}
106+
if (color == colors::green) {
107+
return &greenColors;
108+
}
109+
if (color == colors::rainbow) {
110+
return &rainbowColors;
111+
}
112+
if (color == colors::gray) {
113+
return &grayColors;
114+
}
115+
if (color == colors::nordBlue) {
116+
return &nordBlueColors;
117+
}
118+
return &nordGreenColors;
119+
}
20120
}
21121

22122
WatchFaceInfineat::WatchFaceInfineat(Controllers::DateTime& dateTimeController,
@@ -57,13 +157,12 @@ WatchFaceInfineat::WatchFaceInfineat(Controllers::DateTime& dateTimeController,
57157

58158
static constexpr lv_style_int_t lineWidths[nLines] = {18, 15, 14, 22, 20, 18, 18, 52, 48};
59159

160+
const std::array<lv_color_t, nLines>* colors = returnColor(static_cast<enum colors>(settingsController.GetInfineatColorIndex()));
60161
for (int i = 0; i < nLines; i++) {
61162
lines[i] = lv_line_create(lv_scr_act(), nullptr);
62163
lv_obj_set_style_local_line_width(lines[i], LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lineWidths[i]);
63-
lv_obj_set_style_local_line_color(lines[i],
64-
LV_LINE_PART_MAIN,
65-
LV_STATE_DEFAULT,
66-
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + i]));
164+
lv_color_t color = (*colors)[i];
165+
lv_obj_set_style_local_line_color(lines[i], LV_LINE_PART_MAIN, LV_STATE_DEFAULT, color);
67166
lv_line_set_points(lines[i], linePoints[i], 2);
68167
}
69168

@@ -73,21 +172,15 @@ WatchFaceInfineat::WatchFaceInfineat(Controllers::DateTime& dateTimeController,
73172

74173
lineBattery = lv_line_create(lv_scr_act(), nullptr);
75174
lv_obj_set_style_local_line_width(lineBattery, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 24);
76-
lv_obj_set_style_local_line_color(lineBattery,
77-
LV_LINE_PART_MAIN,
78-
LV_STATE_DEFAULT,
79-
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 4]));
175+
lv_obj_set_style_local_line_color(lineBattery, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, (*colors)[4]);
80176
lv_obj_set_style_local_line_opa(lineBattery, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 190);
81177
lineBatteryPoints[0] = {27, 105};
82178
lineBatteryPoints[1] = {27, 106};
83179
lv_line_set_points(lineBattery, lineBatteryPoints, 2);
84180
lv_obj_move_foreground(lineBattery);
85181

86182
notificationIcon = lv_obj_create(lv_scr_act(), nullptr);
87-
lv_obj_set_style_local_bg_color(notificationIcon,
88-
LV_BTN_PART_MAIN,
89-
LV_STATE_DEFAULT,
90-
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 7]));
183+
lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, (*colors)[7]);
91184
lv_obj_set_style_local_radius(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
92185
lv_obj_set_size(notificationIcon, 13, 13);
93186
lv_obj_set_hidden(notificationIcon, true);
@@ -125,25 +218,26 @@ WatchFaceInfineat::WatchFaceInfineat(Controllers::DateTime& dateTimeController,
125218
lv_obj_set_size(dateContainer, 60, 30);
126219
lv_obj_align(dateContainer, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 5);
127220

221+
static constexpr lv_color_t grayColor = LV_COLOR_MAKE(0x99, 0x99, 0x99);
128222
labelDate = lv_label_create(lv_scr_act(), nullptr);
129-
lv_obj_set_style_local_text_color(labelDate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
223+
lv_obj_set_style_local_text_color(labelDate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, grayColor);
130224
lv_obj_set_style_local_text_font(labelDate, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_teko);
131225
lv_obj_align(labelDate, dateContainer, LV_ALIGN_IN_TOP_MID, 0, 0);
132226
lv_label_set_text_static(labelDate, "Mon 01");
133227

134228
bleIcon = lv_label_create(lv_scr_act(), nullptr);
135-
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
229+
lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, grayColor);
136230
lv_label_set_text_static(bleIcon, Symbols::bluetooth);
137231
lv_obj_align(bleIcon, dateContainer, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
138232

139233
stepValue = lv_label_create(lv_scr_act(), nullptr);
140-
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
234+
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, grayColor);
141235
lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_teko);
142236
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 10, 0);
143237
lv_label_set_text_static(stepValue, "0");
144238

145239
stepIcon = lv_label_create(lv_scr_act(), nullptr);
146-
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
240+
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, grayColor);
147241
lv_label_set_text_static(stepIcon, Symbols::shoe);
148242
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
149243

@@ -285,20 +379,13 @@ void WatchFaceInfineat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
285379
settingsController.SetInfineatColorIndex(colorIndex);
286380
}
287381
if (object == btnNextColor || object == btnPrevColor) {
382+
const std::array<lv_color_t, nLines>* colors = returnColor(static_cast<enum colors>(settingsController.GetInfineatColorIndex()));
288383
for (int i = 0; i < nLines; i++) {
289-
lv_obj_set_style_local_line_color(lines[i],
290-
LV_LINE_PART_MAIN,
291-
LV_STATE_DEFAULT,
292-
lv_color_hex(infineatColors.orange[colorIndex * nLines + i]));
384+
lv_color_t color = (*colors)[i];
385+
lv_obj_set_style_local_line_color(lines[i], LV_LINE_PART_MAIN, LV_STATE_DEFAULT, color);
293386
}
294-
lv_obj_set_style_local_line_color(lineBattery,
295-
LV_LINE_PART_MAIN,
296-
LV_STATE_DEFAULT,
297-
lv_color_hex(infineatColors.orange[colorIndex * nLines + 4]));
298-
lv_obj_set_style_local_bg_color(notificationIcon,
299-
LV_BTN_PART_MAIN,
300-
LV_STATE_DEFAULT,
301-
lv_color_hex(infineatColors.orange[colorIndex * nLines + 7]));
387+
lv_obj_set_style_local_line_color(lineBattery, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, (*colors)[4]);
388+
lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, (*colors)[7]);
302389
}
303390
}
304391
}
@@ -420,14 +507,9 @@ void WatchFaceInfineat::ToggleBatteryIndicatorColor(bool showSideCover) {
420507
lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
421508
} else {
422509
lv_obj_set_style_local_image_recolor_opa(logoPine, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);
423-
lv_obj_set_style_local_line_color(lineBattery,
424-
LV_LINE_PART_MAIN,
425-
LV_STATE_DEFAULT,
426-
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 4]));
427-
lv_obj_set_style_local_bg_color(notificationIcon,
428-
LV_BTN_PART_MAIN,
429-
LV_STATE_DEFAULT,
430-
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 7]));
510+
const std::array<lv_color_t, nLines>* colors = returnColor(static_cast<enum colors>(settingsController.GetInfineatColorIndex()));
511+
lv_obj_set_style_local_line_color(lineBattery, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, (*colors)[4]);
512+
lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, (*colors)[7]);
431513
}
432514
}
433515

src/displayapp/screens/WatchFaceInfineat.h

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Pinetime {
2121

2222
class WatchFaceInfineat : public Screen {
2323
public:
24+
static constexpr int nLines = 9;
2425
WatchFaceInfineat(Controllers::DateTime& dateTimeController,
2526
const Controllers::Battery& batteryController,
2627
const Controllers::Ble& bleController,
@@ -84,21 +85,8 @@ namespace Pinetime {
8485
lv_obj_t* labelBtnSettings;
8586
lv_obj_t* lblToggle;
8687

87-
static constexpr int nLines = 9;
88-
static constexpr int nColors = 7; // must match number of colors in InfineatColors
89-
9088
lv_obj_t* lines[nLines];
9189

92-
struct InfineatColors {
93-
int orange[nLines] = {0xfd872b, 0xdb3316, 0x6f1000, 0xfd7a0a, 0xffffff, 0xffffff, 0xffffff, 0xe85102, 0xea1c00};
94-
int blue[nLines] = {0xe7f8ff, 0x2232d0, 0x182a8b, 0xe7f8ff, 0xffffff, 0xffffff, 0xffffff, 0x5991ff, 0x1636ff};
95-
int green[nLines] = {0xb8ff9b, 0x088608, 0x004a00, 0xb8ff9b, 0xffffff, 0xffffff, 0xffffff, 0x62d515, 0x007400};
96-
int rainbow[nLines] = {0x2da400, 0xac09c4, 0xfe0303, 0x0d57ff, 0xffffff, 0xffffff, 0xffffff, 0xe0b900, 0xe85102};
97-
int gray[nLines] = {0xeeeeee, 0x98959b, 0x191919, 0xeeeeee, 0xffffff, 0xffffff, 0xffffff, 0x919191, 0x3a3a3a};
98-
int nordBlue[nLines] = {0xc3daf2, 0x4d78ce, 0x153451, 0xc3daf2, 0xffffff, 0xffffff, 0xffffff, 0x5d8ad2, 0x21518a};
99-
int nordGreen[nLines] = {0xd5f0e9, 0x238373, 0x1d413f, 0xd5f0e9, 0xffffff, 0xffffff, 0xffffff, 0x2fb8a2, 0x11705a};
100-
} infineatColors;
101-
10290
Controllers::DateTime& dateTimeController;
10391
const Controllers::Battery& batteryController;
10492
const Controllers::Ble& bleController;

0 commit comments

Comments
 (0)