Skip to content

Commit 95bd649

Browse files
committed
weather: Colorize forecast temperatures
1 parent fe1f581 commit 95bd649

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/displayapp/screens/Weather.cpp

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

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

11+
namespace {
12+
uint8_t temperatureStyle(int16_t temperature) {
13+
if (temperature <= 0) { // freezing
14+
return LV_TABLE_PART_CELL3;
15+
} else if (temperature <= 400) { // ice danger
16+
return LV_TABLE_PART_CELL4;
17+
} else if (temperature >= 2700) { // hot
18+
return LV_TABLE_PART_CELL6;
19+
}
20+
return LV_TABLE_PART_CELL5;
21+
}
22+
}
23+
1124
Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService)
1225
: settingsController {settingsController}, weatherService {weatherService} {
1326

@@ -54,6 +67,19 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
5467
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
5568
lv_obj_set_style_local_text_font(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
5669

70+
// LV_TABLE_PART_CELL3: Freezing
71+
lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, LV_COLOR_BLACK);
72+
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, Colors::blue);
73+
// LV_TABLE_PART_CELL4: Ice
74+
lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_BLACK);
75+
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_CYAN);
76+
// LV_TABLE_PART_CELL5: Normal
77+
lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, LV_COLOR_BLACK);
78+
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, Colors::orange);
79+
// LV_TABLE_PART_CELL6: Hot
80+
lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, LV_COLOR_BLACK);
81+
lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, Colors::deepOrange);
82+
5783
lv_obj_align(forecast, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
5884

5985
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
@@ -124,6 +150,8 @@ void Weather::Refresh() {
124150
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
125151
int16_t maxTemp = optCurrentForecast->days[i].maxTemperature;
126152
int16_t minTemp = optCurrentForecast->days[i].minTemperature;
153+
uint8_t maxStyle = temperatureStyle(maxTemp);
154+
uint8_t minStyle = temperatureStyle(minTemp);
127155
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
128156
maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp);
129157
minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp);
@@ -137,7 +165,9 @@ void Weather::Refresh() {
137165
lv_table_set_cell_value(forecast, 0, i, WeekDays[wday]);
138166
lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i].iconId));
139167
lv_table_set_cell_value_fmt(forecast, 2, i, "%d", maxTemp);
168+
lv_table_set_cell_type(forecast, 2, i, maxStyle);
140169
lv_table_set_cell_value_fmt(forecast, 3, i, "%d", minTemp);
170+
lv_table_set_cell_type(forecast, 3, i, minStyle);
141171
}
142172
} else {
143173
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {

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)