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
@@ -54,6 +78,19 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
54
78
lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
55
79
lv_obj_set_style_local_text_font (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
56
80
81
+ // LV_TABLE_PART_CELL3: Freezing
82
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, LV_COLOR_BLACK);
83
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, Colors::blue);
84
+ // LV_TABLE_PART_CELL4: Ice
85
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_BLACK);
86
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_CYAN);
87
+ // LV_TABLE_PART_CELL5: Normal
88
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, LV_COLOR_BLACK);
89
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, Colors::orange);
90
+ // LV_TABLE_PART_CELL6: Hot
91
+ lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, LV_COLOR_BLACK);
92
+ lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, Colors::deepOrange);
93
+
57
94
lv_obj_align (forecast, nullptr , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
58
95
59
96
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
@@ -81,30 +118,19 @@ void Weather::Refresh() {
81
118
int16_t temp = optCurrentWeather->temperature ;
82
119
int16_t minTemp = optCurrentWeather->minTemperature ;
83
120
int16_t maxTemp = optCurrentWeather->maxTemperature ;
84
- lv_color_t color = Colors::orange;
85
- if (temp <= 0 ) { // freezing
86
- color = Colors::blue;
87
- } else if (temp <= 400 ) { // ice danger
88
- color = LV_COLOR_CYAN;
89
- } else if (temp >= 2700 ) { // hot
90
- color = Colors::deepOrange;
91
- }
121
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, temperatureColor (temp));
92
122
char tempUnit = ' C' ;
93
123
if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
94
124
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (temp);
95
125
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (minTemp);
96
126
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (maxTemp);
97
127
tempUnit = ' F' ;
98
128
}
99
- temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0 );
100
- minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0 );
101
- maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0 );
102
129
lv_label_set_text (icon, Symbols::GetSymbol (optCurrentWeather->iconId ));
103
130
lv_label_set_text (condition, Symbols::GetCondition (optCurrentWeather->iconId ));
104
- lv_label_set_text_fmt (temperature, " %d°%c" , temp, tempUnit);
105
- lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color);
106
- lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
107
- lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
131
+ lv_label_set_text_fmt (temperature, " %d°%c" , temp / 100 , tempUnit);
132
+ lv_label_set_text_fmt (minTemperature, " %d°" , minTemp / 100 );
133
+ lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp / 100 );
108
134
} else {
109
135
lv_label_set_text (icon, " " );
110
136
lv_label_set_text (condition, " " );
@@ -124,27 +150,29 @@ void Weather::Refresh() {
124
150
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
125
151
int16_t maxTemp = optCurrentForecast->days [i].maxTemperature ;
126
152
int16_t minTemp = optCurrentForecast->days [i].minTemperature ;
153
+ lv_table_set_cell_type (forecast, 2 , i, temperatureStyle (maxTemp));
154
+ lv_table_set_cell_type (forecast, 3 , i, temperatureStyle (minTemp));
127
155
if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
128
156
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (maxTemp);
129
157
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (minTemp);
130
158
}
131
- maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0 );
132
- minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0 );
133
159
uint8_t wday = localTime.tm_wday + i + 1 ;
134
160
if (wday > 6 ) {
135
161
wday -= 7 ;
136
162
}
137
163
lv_table_set_cell_value (forecast, 0 , i, WeekDays[wday]);
138
164
lv_table_set_cell_value (forecast, 1 , i, Symbols::GetSymbol (optCurrentForecast->days [i].iconId ));
139
- lv_table_set_cell_value_fmt (forecast, 2 , i, " %d" , maxTemp);
140
- lv_table_set_cell_value_fmt (forecast, 3 , i, " %d" , minTemp);
165
+ lv_table_set_cell_value_fmt (forecast, 2 , i, " %d" , maxTemp / 100 );
166
+ lv_table_set_cell_value_fmt (forecast, 3 , i, " %d" , minTemp / 100 );
141
167
}
142
168
} else {
143
169
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
144
170
lv_table_set_cell_value (forecast, 0 , i, " " );
145
171
lv_table_set_cell_value (forecast, 1 , i, " " );
146
172
lv_table_set_cell_value (forecast, 2 , i, " " );
147
173
lv_table_set_cell_value (forecast, 3 , i, " " );
174
+ lv_table_set_cell_type (forecast, 2 , i, LV_TABLE_PART_CELL1);
175
+ lv_table_set_cell_type (forecast, 3 , i, LV_TABLE_PART_CELL1);
148
176
}
149
177
}
150
178
}
0 commit comments