Skip to content

Commit 1ecedf7

Browse files
committed
weather: Colorize forecast temperatures
1 parent 80d84a5 commit 1ecedf7

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
@@ -9,6 +9,30 @@
99

1010
using 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+
1236
Weather::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
}

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)