99
1010using namespace Pinetime ::Applications::Screens;
1111
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+
1236Weather::Weather (Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
1337 : settingsController {settingsController}, weatherService {weatherService} {
1438
@@ -56,6 +80,22 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
5680 lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
5781 lv_obj_set_style_local_text_font (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
5882 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 );
5999
60100 lv_obj_align (forecast, nullptr , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
61101
@@ -85,14 +125,7 @@ void Weather::Refresh() {
85125 int16_t temp = optCurrentWeather->temperature ;
86126 int16_t minTemp = optCurrentWeather->minTemperature ;
87127 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));
96129 char tempUnit = ' C' ;
97130 if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
98131 temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (temp);
@@ -106,7 +139,6 @@ void Weather::Refresh() {
106139 lv_label_set_text (icon, Symbols::GetSymbol (optCurrentWeather->iconId ));
107140 lv_label_set_text (condition, Symbols::GetCondition (optCurrentWeather->iconId ));
108141 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);
110142 lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
111143 lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
112144 } else {
@@ -128,6 +160,8 @@ void Weather::Refresh() {
128160 for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
129161 int16_t maxTemp = optCurrentForecast->days [i].maxTemperature ;
130162 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));
131165 if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
132166 maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (maxTemp);
133167 minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit (minTemp);
@@ -150,6 +184,8 @@ void Weather::Refresh() {
150184 lv_table_set_cell_value (forecast, 1 , i, " " );
151185 lv_table_set_cell_value (forecast, 2 , i, " " );
152186 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);
153189 }
154190 }
155191 }
0 commit comments