8
8
9
9
using namespace Pinetime ::Applications::Screens;
10
10
11
+ namespace {
12
+ lv_color_t temperatureColor (int16_t temperature) {
13
+ if (temperature <= 0 ) { // freezing
14
+ return Colors::blue;
15
+ } else if (temperature <= 400 ) { // ice
16
+ return LV_COLOR_CYAN;
17
+ } else if (temperature >= 2700 ) { // hot
18
+ return Colors::deepOrange;
19
+ }
20
+ return Colors::orange; // normal
21
+ }
22
+
23
+ uint8_t temperatureStyle (int16_t temperature) {
24
+ if (temperature <= 0 ) { // freezing
25
+ return LV_TABLE_PART_CELL3;
26
+ } else if (temperature <= 400 ) { // ice
27
+ return LV_TABLE_PART_CELL4;
28
+ } else if (temperature >= 2700 ) { // hot
29
+ return LV_TABLE_PART_CELL6;
30
+ }
31
+ return LV_TABLE_PART_CELL5; // normal
32
+ }
33
+ }
34
+
11
35
Weather::Weather (Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
12
36
: settingsController {settingsController}, weatherService {weatherService} {
13
37
@@ -55,6 +79,22 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
55
79
lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
56
80
lv_obj_set_style_local_text_font (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
57
81
lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, 6 );
82
+ // LV_TABLE_PART_CELL3: Freezing
83
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, LV_COLOR_BLACK);
84
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, Colors::blue);
85
+ lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, 6 );
86
+ // LV_TABLE_PART_CELL4: Ice
87
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_BLACK);
88
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_CYAN);
89
+ lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, 6 );
90
+ // LV_TABLE_PART_CELL5: Normal
91
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, LV_COLOR_BLACK);
92
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, Colors::orange);
93
+ lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, 6 );
94
+ // LV_TABLE_PART_CELL6: Hot
95
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, LV_COLOR_BLACK);
96
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, Colors::deepOrange);
97
+ lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, 6 );
58
98
59
99
lv_obj_align (forecast, nullptr , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
60
100
@@ -84,14 +124,7 @@ void Weather::Refresh() {
84
124
int16_t temp = optCurrentWeather->temperature ;
85
125
int16_t minTemp = optCurrentWeather->minTemperature ;
86
126
int16_t maxTemp = optCurrentWeather->maxTemperature ;
87
- lv_color_t color = Colors::orange;
88
- if (temp <= 0 ) { // freezing
89
- color = Colors::blue;
90
- } else if (temp <= 400 ) { // ice danger
91
- color = LV_COLOR_CYAN;
92
- } else if (temp >= 2700 ) { // hot
93
- color = Colors::deepOrange;
94
- }
127
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, temperatureColor (temp));
95
128
char tempUnit = ' C' ;
96
129
if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
97
130
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (temp);
@@ -105,7 +138,6 @@ void Weather::Refresh() {
105
138
lv_label_set_text (icon, Symbols::GetSymbol (optCurrentWeather->iconId ));
106
139
lv_label_set_text (condition, Symbols::GetCondition (optCurrentWeather->iconId ));
107
140
lv_label_set_text_fmt (temperature, " %d°%c" , temp, tempUnit);
108
- lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color);
109
141
lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
110
142
lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
111
143
} else {
@@ -127,6 +159,8 @@ void Weather::Refresh() {
127
159
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
128
160
int16_t maxTemp = optCurrentForecast->days [i].maxTemperature ;
129
161
int16_t minTemp = optCurrentForecast->days [i].minTemperature ;
162
+ lv_table_set_cell_type (forecast, 2 , i, temperatureStyle (maxTemp));
163
+ lv_table_set_cell_type (forecast, 3 , i, temperatureStyle (minTemp));
130
164
if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
131
165
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (maxTemp);
132
166
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (minTemp);
@@ -148,6 +182,8 @@ void Weather::Refresh() {
148
182
lv_table_set_cell_value (forecast, 1 , i, " " );
149
183
lv_table_set_cell_value (forecast, 2 , i, " " );
150
184
lv_table_set_cell_value (forecast, 3 , i, " " );
185
+ lv_table_set_cell_type (forecast, 2 , i, LV_TABLE_PART_CELL1);
186
+ lv_table_set_cell_type (forecast, 3 , i, LV_TABLE_PART_CELL1);
151
187
}
152
188
}
153
189
}
0 commit comments