Skip to content

Commit cb4e7d6

Browse files
committed
Fixed positioning
Move from `lv_obj_align` to `lv_obj_set_pos` to avoid weird positioning errors when changing the position more than once.
1 parent 6cd3988 commit cb4e7d6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/displayapp/screens/Weather.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Weather::Weather(Controllers::Settings& settingsController,
4949

5050
lastUpdated = lv_label_create(lv_scr_act(), nullptr);
5151
lv_obj_set_style_local_text_color(lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
52-
lv_label_set_text_fmt(lastUpdated, "");
52+
lv_label_set_text(lastUpdated, "");
5353

5454
minTemperature = lv_label_create(lv_scr_act(), nullptr);
5555
lv_obj_set_style_local_text_color(minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
@@ -150,20 +150,30 @@ void Weather::Refresh() {
150150
int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60;
151151
int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600;
152152

153-
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -31, -1);
154-
if ((secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60) ||
155-
(minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60) || hoursSinceWeatherUpdate > 9) {
156-
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -41, -1);
157-
}
153+
constexpr uint8_t Y_POSITION = 108;
154+
constexpr uint8_t X_SINGLE_DIGIT_POSITION = 90;
155+
constexpr uint8_t X_TWO_DIGIT_POSITION = 78;
156+
constexpr uint8_t X_NOW_POSITION = 102;
157+
158+
lv_obj_set_pos(lastUpdated, X_SINGLE_DIGIT_POSITION, Y_POSITION);
158159

159160
if (hoursSinceWeatherUpdate > 0) {
161+
if (hoursSinceWeatherUpdate > 9) {
162+
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
163+
}
160164
lv_label_set_text_fmt(lastUpdated, "%dh ago", hoursSinceWeatherUpdate);
161165
} else if (minutesSinceWeatherUpdate > 0) {
166+
if (minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60) {
167+
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
168+
}
162169
lv_label_set_text_fmt(lastUpdated, "%dm ago", minutesSinceWeatherUpdate);
163170
} else if (secondsSinceWeatherUpdate > 30) {
171+
if (secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60) {
172+
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
173+
}
164174
lv_label_set_text_fmt(lastUpdated, "%ds ago", secondsSinceWeatherUpdate);
165175
} else if (secondsSinceWeatherUpdate < 31) {
166-
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -18, -1);
176+
lv_obj_set_pos(lastUpdated, X_NOW_POSITION, Y_POSITION);
167177
lv_label_set_text_fmt(lastUpdated, "Now", secondsSinceWeatherUpdate);
168178
}
169179
} else {

0 commit comments

Comments
 (0)