Skip to content

Commit 31bc47d

Browse files
committed
Settings : use enums instead of ints to store colors. Group all PTS settings into a struct.
PTS/SettingsPTS : Convert to/from LVGL color and Settings::Color, add functions to reduce code duplication. Adapt SettingPineTimeStyle with the last Screen Interface
1 parent ef9f809 commit 31bc47d

8 files changed

Lines changed: 144 additions & 116 deletions

File tree

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
418418
displayapp/screens/BatteryInfo.cpp
419419
displayapp/screens/Steps.cpp
420420
displayapp/screens/Timer.cpp
421+
displayapp/Colors.cpp
421422

422423
## Settings
423424
displayapp/screens/settings/QuickSettings.cpp
@@ -611,6 +612,7 @@ set(INCLUDE_FILES
611612
displayapp/screens/Metronome.h
612613
displayapp/screens/Motion.h
613614
displayapp/screens/Timer.h
615+
displayapp/Colors.h
614616
drivers/St7789.h
615617
drivers/SpiNorFlash.h
616618
drivers/SpiMaster.h

src/components/settings/Settings.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ namespace Pinetime {
1717
DoubleTap = 1,
1818
RaiseWrist = 2,
1919
};
20+
enum class Colors : uint8_t {
21+
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
22+
};
23+
struct PineTimeStyle {
24+
Colors ColorTime = Colors::Teal;
25+
Colors ColorBar = Colors::Teal;
26+
Colors ColorBG = Colors::Black;
27+
};
2028

2129
Settings(Pinetime::Controllers::FS& fs);
2230

@@ -33,37 +41,38 @@ namespace Pinetime {
3341
return settings.clockFace;
3442
};
3543

36-
void SetPTSColorTime(uint8_t colorTime) {
37-
if (colorTime != settings.PTSColorTime)
44+
void SetPTSColorTime(Colors colorTime) {
45+
if (colorTime != settings.PTS.ColorTime)
3846
settingsChanged = true;
39-
settings.PTSColorTime = colorTime;
47+
settings.PTS.ColorTime = colorTime;
4048
};
41-
uint8_t GetPTSColorTime() const {
42-
return settings.PTSColorTime;
49+
Colors GetPTSColorTime() const {
50+
return settings.PTS.ColorTime;
4351
};
4452

45-
void SetPTSColorBar(uint8_t colorBar) {
46-
if (colorBar != settings.PTSColorBar)
53+
void SetPTSColorBar(Colors colorBar) {
54+
if (colorBar != settings.PTS.ColorBar)
4755
settingsChanged = true;
48-
settings.PTSColorBar = colorBar;
56+
settings.PTS.ColorBar = colorBar;
4957
};
50-
uint8_t GetPTSColorBar() const {
51-
return settings.PTSColorBar;
58+
Colors GetPTSColorBar() const {
59+
return settings.PTS.ColorBar;
5260
};
5361

54-
void SetPTSColorBG(uint8_t colorBG) {
55-
if (colorBG != settings.PTSColorBG)
62+
void SetPTSColorBG(Colors colorBG) {
63+
if (colorBG != settings.PTS.ColorBG)
5664
settingsChanged = true;
57-
settings.PTSColorBG = colorBG;
65+
settings.PTS.ColorBG = colorBG;
5866
};
59-
uint8_t GetPTSColorBG() const {
60-
return settings.PTSColorBG;
67+
Colors GetPTSColorBG() const {
68+
return settings.PTS.ColorBG;
6169
};
6270

6371
void SetAppMenu(uint8_t menu) {
6472
appMenu = menu;
6573
};
66-
uint8_t GetAppMenu() {
74+
75+
uint8_t GetAppMenu() const {
6776
return appMenu;
6877
};
6978

@@ -156,7 +165,6 @@ namespace Pinetime {
156165

157166
static constexpr uint32_t settingsVersion = 0x0002;
158167
struct SettingsData {
159-
160168
uint32_t version = settingsVersion;
161169
uint32_t stepsGoal = 10000;
162170
uint32_t screenTimeOut = 15000;
@@ -166,9 +174,7 @@ namespace Pinetime {
166174

167175
uint8_t clockFace = 0;
168176

169-
uint8_t PTSColorTime = 11;
170-
uint8_t PTSColorBar = 11;
171-
uint8_t PTSColorBG = 3;
177+
PineTimeStyle PTS;
172178

173179
std::bitset<3> wakeUpMode {0};
174180

src/displayapp/Colors.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "Colors.h"
2+
3+
using namespace Pinetime::Applications;
4+
using namespace Pinetime::Controllers;
5+
6+
lv_color_t Pinetime::Applications::Convert(Pinetime::Controllers::Settings::Colors color) {
7+
switch (color) {
8+
case Pinetime::Controllers::Settings::Colors::White: return LV_COLOR_WHITE;
9+
case Pinetime::Controllers::Settings::Colors::Silver: return LV_COLOR_SILVER;
10+
case Pinetime::Controllers::Settings::Colors::Gray: return LV_COLOR_GRAY;
11+
case Pinetime::Controllers::Settings::Colors::Black: return LV_COLOR_BLACK;
12+
case Pinetime::Controllers::Settings::Colors::Red: return LV_COLOR_RED;
13+
case Pinetime::Controllers::Settings::Colors::Maroon: return LV_COLOR_MAROON;
14+
case Pinetime::Controllers::Settings::Colors::Yellow: return LV_COLOR_YELLOW;
15+
case Pinetime::Controllers::Settings::Colors::Olive: return LV_COLOR_OLIVE;
16+
case Pinetime::Controllers::Settings::Colors::Lime: return LV_COLOR_LIME;
17+
case Pinetime::Controllers::Settings::Colors::Green: return LV_COLOR_GREEN;
18+
case Pinetime::Controllers::Settings::Colors::Cyan: return LV_COLOR_CYAN;
19+
case Pinetime::Controllers::Settings::Colors::Teal: return LV_COLOR_TEAL;
20+
case Pinetime::Controllers::Settings::Colors::Blue: return LV_COLOR_BLUE;
21+
case Pinetime::Controllers::Settings::Colors::Navy: return LV_COLOR_NAVY;
22+
case Pinetime::Controllers::Settings::Colors::Magenta: return LV_COLOR_MAGENTA;
23+
case Pinetime::Controllers::Settings::Colors::Purple: return LV_COLOR_PURPLE;
24+
case Pinetime::Controllers::Settings::Colors::Orange: return LV_COLOR_ORANGE;
25+
default: return LV_COLOR_WHITE;
26+
}
27+
}

src/displayapp/Colors.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <lvgl/src/lv_misc/lv_color.h>
4+
#include <components/settings/Settings.h>
5+
6+
namespace Pinetime {
7+
namespace Applications {
8+
lv_color_t Convert(Controllers::Settings::Colors color);
9+
}
10+
}

src/displayapp/screens/PineTimeStyle.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <date/date.h>
2424
#include <lvgl/lvgl.h>
2525
#include <cstdio>
26+
#include <displayapp/Colors.h>
2627
#include "BatteryIcon.h"
2728
#include "BleIcon.h"
2829
#include "NotificationIcon.h"
@@ -63,33 +64,33 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
6364

6465
//Create a 200px wide background rectangle
6566
timebar = lv_obj_create(lv_scr_act(), nullptr);
66-
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorBG()]);
67+
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorBG()));
6768
lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
6869
lv_obj_set_size(timebar, 200, 240);
6970
lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 0);
7071

7172
// Display the time
7273
timeDD1 = lv_label_create(lv_scr_act(), nullptr);
7374
lv_obj_set_style_local_text_font(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light);
74-
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorTime()]);
75+
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorTime()));
7576
lv_label_set_text(timeDD1, "12");
7677
lv_obj_align(timeDD1, timebar, LV_ALIGN_IN_TOP_MID, 5, 5);
7778

7879
timeDD2 = lv_label_create(lv_scr_act(), nullptr);
7980
lv_obj_set_style_local_text_font(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light);
80-
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorTime()]);
81+
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorTime()));
8182
lv_label_set_text(timeDD2, "34");
8283
lv_obj_align(timeDD2, timebar, LV_ALIGN_IN_BOTTOM_MID, 5, -5);
8384

8485
timeAMPM = lv_label_create(lv_scr_act(), nullptr);
85-
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorTime()]);
86+
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorTime()));
8687
lv_obj_set_style_local_text_line_space(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, -3);
8788
lv_label_set_text(timeAMPM, "");
8889
lv_obj_align(timeAMPM, timebar, LV_ALIGN_IN_BOTTOM_LEFT, 2, -20);
8990

9091
// Create a 40px wide bar down the right side of the screen
9192
sidebar = lv_obj_create(lv_scr_act(), nullptr);
92-
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorBar()]);
93+
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorBar()));
9394
lv_obj_set_style_local_radius(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
9495
lv_obj_set_size(sidebar, 40, 240);
9596
lv_obj_align(sidebar, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);

src/displayapp/screens/PineTimeStyle.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ namespace Pinetime {
6868
lv_obj_t* notificationIcon;
6969
lv_obj_t* stepGauge;
7070
lv_color_t needle_colors[1];
71-
lv_color_t pts_colors[17] = {LV_COLOR_WHITE, LV_COLOR_SILVER, LV_COLOR_GRAY, LV_COLOR_BLACK,
72-
LV_COLOR_RED, LV_COLOR_MAROON, LV_COLOR_YELLOW, LV_COLOR_OLIVE,
73-
LV_COLOR_LIME, LV_COLOR_GREEN, LV_COLOR_CYAN, LV_COLOR_TEAL,
74-
LV_COLOR_BLUE, LV_COLOR_NAVY, LV_COLOR_MAGENTA, LV_COLOR_PURPLE,
75-
LV_COLOR_ORANGE};
7671

7772
Controllers::DateTime& dateTimeController;
7873
Controllers::Battery& batteryController;

0 commit comments

Comments
 (0)