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