Skip to content

Commit 851fb29

Browse files
committed
weather: Colorize forecast temperatures
1 parent 1d03907 commit 851fb29

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

src/displayapp/screens/Weather.cpp

+45-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88

99
using namespace Pinetime::Applications::Screens;
1010

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+
1135
Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
1236
: settingsController {settingsController}, weatherService {weatherService} {
1337

@@ -55,6 +79,22 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
5579
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
5680
lv_obj_set_style_local_text_font(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
5781
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);
5898

5999
lv_obj_align(forecast, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
60100

@@ -84,14 +124,7 @@ void Weather::Refresh() {
84124
int16_t temp = optCurrentWeather->temperature;
85125
int16_t minTemp = optCurrentWeather->minTemperature;
86126
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));
95128
char tempUnit = 'C';
96129
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
97130
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
@@ -105,7 +138,6 @@ void Weather::Refresh() {
105138
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId));
106139
lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId));
107140
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);
109141
lv_label_set_text_fmt(minTemperature, "%d°", minTemp);
110142
lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp);
111143
} else {
@@ -127,6 +159,8 @@ void Weather::Refresh() {
127159
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
128160
int16_t maxTemp = optCurrentForecast->days[i].maxTemperature;
129161
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));
130164
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
131165
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp);
132166
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp);
@@ -148,6 +182,8 @@ void Weather::Refresh() {
148182
lv_table_set_cell_value(forecast, 1, i, "");
149183
lv_table_set_cell_value(forecast, 2, i, "");
150184
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);
151187
}
152188
}
153189
}

src/libs/lv_conf.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,9 @@ typedef void* lv_obj_user_data_t;
729729
#define LV_USE_TABLE 1
730730
#if LV_USE_TABLE
731731
#define LV_TABLE_COL_MAX 12
732-
#define LV_TABLE_CELL_STYLE_CNT 5
732+
#define LV_TABLE_CELL_STYLE_CNT 6
733+
#define LV_TABLE_PART_CELL5 5
734+
#define LV_TABLE_PART_CELL6 6
733735
#endif
734736

735737

0 commit comments

Comments
 (0)