diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index 1e0691425f..1aedbd3bfa 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -73,38 +73,32 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW // LV_TABLE_PART_CELL1: Default table style lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_text_color(forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, Colors::lightGray); - lv_obj_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 6); // LV_TABLE_PART_CELL2: Condition icon lv_obj_set_style_local_border_color(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_BLACK); 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_obj_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, 6); // 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_obj_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, 6); // 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_obj_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, 6); // 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_obj_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, 6); // 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_set_style_local_pad_right(forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, 6); lv_obj_align(forecast, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { lv_table_set_col_width(forecast, i, 48); lv_table_set_cell_type(forecast, 1, i, LV_TABLE_PART_CELL2); - lv_table_set_cell_align(forecast, 0, i, LV_LABEL_ALIGN_RIGHT); - lv_table_set_cell_align(forecast, 1, i, LV_LABEL_ALIGN_RIGHT); - lv_table_set_cell_align(forecast, 2, i, LV_LABEL_ALIGN_RIGHT); - lv_table_set_cell_align(forecast, 3, i, LV_LABEL_ALIGN_RIGHT); + lv_table_set_cell_align(forecast, 0, i, LV_LABEL_ALIGN_CENTER); + lv_table_set_cell_align(forecast, 1, i, LV_LABEL_ALIGN_CENTER); + lv_table_set_cell_align(forecast, 2, i, LV_LABEL_ALIGN_CENTER); + lv_table_set_cell_align(forecast, 3, i, LV_LABEL_ALIGN_CENTER); } taskRefresh = lv_task_create(RefreshTaskCallback, 1000, LV_TASK_PRIO_MID, this); @@ -173,8 +167,27 @@ void Weather::Refresh() { minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0); 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); + // Pad cells based on the largest number of digits on each column + std::string maxPadding = ""; + std::string minPadding = ""; + int maxSize = snprintf(nullptr, 0, "%d", maxTemp); + int minSize = snprintf(nullptr, 0, "%d", minTemp); + switch (maxSize - minSize) { + case -2: + maxPadding = " "; + break; + case -1: + maxPadding = " "; + break; + case 1: + minPadding = " "; + break; + case 2: + minPadding = " "; + break; + } + lv_table_set_cell_value_fmt(forecast, 2, i, "%s%d", maxPadding.data(), maxTemp); + lv_table_set_cell_value_fmt(forecast, 3, i, "%s%d", minPadding.data(), minTemp); } } else { for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {