diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index 3ad0100487..993ef9bd41 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -8,6 +8,30 @@ using namespace Pinetime::Applications::Screens; +namespace { + lv_color_t temperatureColor(int16_t temperature) { + if (temperature <= 0) { // freezing + return Colors::blue; + } else if (temperature <= 400) { // ice + return LV_COLOR_CYAN; + } else if (temperature >= 2700) { // hot + return Colors::deepOrange; + } + return Colors::orange; // normal + } + + uint8_t temperatureStyle(int16_t temperature) { + if (temperature <= 0) { // freezing + return LV_TABLE_PART_CELL3; + } else if (temperature <= 400) { // ice + return LV_TABLE_PART_CELL4; + } else if (temperature >= 2700) { // hot + return LV_TABLE_PART_CELL6; + } + return LV_TABLE_PART_CELL5; // normal + } +} + Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleWeatherService& weatherService) : settingsController {settingsController}, weatherService {weatherService} { @@ -54,6 +78,19 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_style_local_text_font(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons); + // LV_TABLE_PART_CELL3: Freezing + lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, Colors::blue); + // LV_TABLE_PART_CELL4: Ice + lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_CYAN); + // LV_TABLE_PART_CELL5: Normal + lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, Colors::orange); + // LV_TABLE_PART_CELL6: Hot + lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, Colors::deepOrange); + lv_obj_align(forecast, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { @@ -81,14 +118,7 @@ void Weather::Refresh() { int16_t temp = optCurrentWeather->temperature; int16_t minTemp = optCurrentWeather->minTemperature; int16_t maxTemp = optCurrentWeather->maxTemperature; - lv_color_t color = Colors::orange; - if (temp <= 0) { // freezing - color = Colors::blue; - } else if (temp <= 400) { // ice danger - color = LV_COLOR_CYAN; - } else if (temp >= 2700) { // hot - color = Colors::deepOrange; - } + lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, temperatureColor(temp)); char tempUnit = 'C'; if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp); @@ -96,15 +126,11 @@ void Weather::Refresh() { maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp); tempUnit = 'F'; } - temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0); - minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0); - maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0); lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId)); lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId)); - lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit); - lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); - lv_label_set_text_fmt(minTemperature, "%d°", minTemp); - lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp); + lv_label_set_text_fmt(temperature, "%d°%c", temp / 100, tempUnit); + lv_label_set_text_fmt(minTemperature, "%d°", minTemp / 100); + lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp / 100); } else { lv_label_set_text(icon, ""); lv_label_set_text(condition, ""); @@ -124,20 +150,20 @@ void Weather::Refresh() { for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { int16_t maxTemp = optCurrentForecast->days[i].maxTemperature; int16_t minTemp = optCurrentForecast->days[i].minTemperature; + lv_table_set_cell_type(forecast, 2, i, temperatureStyle(maxTemp)); + lv_table_set_cell_type(forecast, 3, i, temperatureStyle(minTemp)); if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { maxTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(maxTemp); minTemp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(minTemp); } - maxTemp = maxTemp / 100 + (maxTemp % 100 >= 50 ? 1 : 0); - minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0); uint8_t wday = localTime.tm_wday + i + 1; if (wday > 6) { wday -= 7; } lv_table_set_cell_value(forecast, 0, i, WeekDays[wday]); lv_table_set_cell_value(forecast, 1, i, Symbols::GetSymbol(optCurrentForecast->days[i].iconId)); - lv_table_set_cell_value_fmt(forecast, 2, i, "%d", maxTemp); - lv_table_set_cell_value_fmt(forecast, 3, i, "%d", minTemp); + lv_table_set_cell_value_fmt(forecast, 2, i, "%d", maxTemp / 100); + lv_table_set_cell_value_fmt(forecast, 3, i, "%d", minTemp / 100); } } else { for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { @@ -145,6 +171,8 @@ void Weather::Refresh() { lv_table_set_cell_value(forecast, 1, i, ""); lv_table_set_cell_value(forecast, 2, i, ""); lv_table_set_cell_value(forecast, 3, i, ""); + lv_table_set_cell_type(forecast, 2, i, LV_TABLE_PART_CELL1); + lv_table_set_cell_type(forecast, 3, i, LV_TABLE_PART_CELL1); } } } diff --git a/src/libs/lv_conf.h b/src/libs/lv_conf.h index e96778ecf8..c23647f2c0 100644 --- a/src/libs/lv_conf.h +++ b/src/libs/lv_conf.h @@ -729,7 +729,9 @@ typedef void* lv_obj_user_data_t; #define LV_USE_TABLE 1 #if LV_USE_TABLE #define LV_TABLE_COL_MAX 12 -#define LV_TABLE_CELL_STYLE_CNT 5 +#define LV_TABLE_CELL_STYLE_CNT 6 +#define LV_TABLE_PART_CELL5 5 +#define LV_TABLE_PART_CELL6 6 #endif