@@ -73,38 +73,32 @@ Weather::Weather(Controllers::Settings& settingsController, Controllers::SimpleW
73
73
// LV_TABLE_PART_CELL1: Default table style
74
74
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_BLACK);
75
75
lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, Colors::lightGray);
76
- lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 6 );
77
76
// LV_TABLE_PART_CELL2: Condition icon
78
77
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_BLACK);
79
78
lv_obj_set_style_local_text_color (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
80
79
lv_obj_set_style_local_text_font (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, &fontawesome_weathericons);
81
- lv_obj_set_style_local_pad_right (forecast, LV_TABLE_PART_CELL2, LV_STATE_DEFAULT, 6 );
82
80
// LV_TABLE_PART_CELL3: Freezing
83
81
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL3, LV_STATE_DEFAULT, LV_COLOR_BLACK);
84
82
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
83
// LV_TABLE_PART_CELL4: Ice
87
84
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL4, LV_STATE_DEFAULT, LV_COLOR_BLACK);
88
85
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
86
// LV_TABLE_PART_CELL5: Normal
91
87
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL5, LV_STATE_DEFAULT, LV_COLOR_BLACK);
92
88
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
89
// LV_TABLE_PART_CELL6: Hot
95
90
lv_obj_set_style_local_border_color (forecast, LV_TABLE_PART_CELL6, LV_STATE_DEFAULT, LV_COLOR_BLACK);
96
91
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 );
98
92
99
93
lv_obj_align (forecast, nullptr , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
100
94
101
95
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
102
96
lv_table_set_col_width (forecast, i, 48 );
103
97
lv_table_set_cell_type (forecast, 1 , i, LV_TABLE_PART_CELL2);
104
- lv_table_set_cell_align (forecast, 0 , i, LV_LABEL_ALIGN_RIGHT );
105
- lv_table_set_cell_align (forecast, 1 , i, LV_LABEL_ALIGN_RIGHT );
106
- lv_table_set_cell_align (forecast, 2 , i, LV_LABEL_ALIGN_RIGHT );
107
- lv_table_set_cell_align (forecast, 3 , i, LV_LABEL_ALIGN_RIGHT );
98
+ lv_table_set_cell_align (forecast, 0 , i, LV_LABEL_ALIGN_CENTER );
99
+ lv_table_set_cell_align (forecast, 1 , i, LV_LABEL_ALIGN_CENTER );
100
+ lv_table_set_cell_align (forecast, 2 , i, LV_LABEL_ALIGN_CENTER );
101
+ lv_table_set_cell_align (forecast, 3 , i, LV_LABEL_ALIGN_CENTER );
108
102
}
109
103
110
104
taskRefresh = lv_task_create (RefreshTaskCallback, 1000 , LV_TASK_PRIO_MID, this );
@@ -173,8 +167,27 @@ void Weather::Refresh() {
173
167
minTemp = minTemp / 100 + (minTemp % 100 >= 50 ? 1 : 0 );
174
168
lv_table_set_cell_value (forecast, 0 , i, WeekDays[wday]);
175
169
lv_table_set_cell_value (forecast, 1 , i, Symbols::GetSymbol (optCurrentForecast->days [i].iconId ));
176
- lv_table_set_cell_value_fmt (forecast, 2 , i, " %d" , maxTemp);
177
- lv_table_set_cell_value_fmt (forecast, 3 , i, " %d" , minTemp);
170
+ // Pad cells based on the largest number of digits on each column
171
+ std::string maxPadding = " " ;
172
+ std::string minPadding = " " ;
173
+ int maxSize = snprintf (nullptr , 0 , " %d" , maxTemp);
174
+ int minSize = snprintf (nullptr , 0 , " %d" , minTemp);
175
+ switch (maxSize - minSize) {
176
+ case -2 :
177
+ maxPadding = " " ;
178
+ break ;
179
+ case -1 :
180
+ maxPadding = " " ;
181
+ break ;
182
+ case 1 :
183
+ minPadding = " " ;
184
+ break ;
185
+ case 2 :
186
+ minPadding = " " ;
187
+ break ;
188
+ }
189
+ lv_table_set_cell_value_fmt (forecast, 2 , i, " %s%d" , maxPadding.data (), maxTemp);
190
+ lv_table_set_cell_value_fmt (forecast, 3 , i, " %s%d" , minPadding.data (), minTemp);
178
191
}
179
192
} else {
180
193
for (int i = 0 ; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
0 commit comments