Code optimizations in SettingSetDate and SettingSetTime
Instead of calling lv_obj_align after each button click, the labels have their auto_realign property set.
This commit is contained in:
parent
da36d4a5a1
commit
ffa51612fc
|
@ -40,24 +40,26 @@ SettingSetDate::SettingSetDate(
|
|||
|
||||
dayValue = static_cast<int>(dateTimeController.Day());
|
||||
lblDay = lv_label_create(lv_scr_act(), NULL);
|
||||
//lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblDay, true);
|
||||
|
||||
monthValue = static_cast<int>(dateTimeController.Month());
|
||||
lblMonth = lv_label_create(lv_scr_act(), NULL);
|
||||
//lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
UpdateMonthLabel();
|
||||
lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblMonth, true);
|
||||
|
||||
yearValue = static_cast<int>(dateTimeController.Year());
|
||||
if (yearValue < 2021)
|
||||
yearValue = 2021;
|
||||
lblYear = lv_label_create(lv_scr_act(), NULL);
|
||||
//lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblYear, true);
|
||||
|
||||
btnDayPlus = lv_btn_create(lv_scr_act(), NULL);
|
||||
btnDayPlus->user_data = this;
|
||||
|
@ -128,7 +130,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (dayValue > MaximumDayOfMonth())
|
||||
dayValue = 1;
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnDayMinus) {
|
||||
|
@ -136,7 +137,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (dayValue < 1)
|
||||
dayValue = MaximumDayOfMonth();
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnMonthPlus) {
|
||||
|
@ -158,14 +158,12 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
else if (object == btnYearPlus) {
|
||||
yearValue++;
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
}
|
||||
else if (object == btnYearMinus) {
|
||||
yearValue--;
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
}
|
||||
|
@ -211,7 +209,5 @@ void SettingSetDate::CheckDay() {
|
|||
void SettingSetDate::UpdateMonthLabel() {
|
||||
lv_label_set_text_static(lblMonth,
|
||||
Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast<Pinetime::Controllers::DateTime::Months>(monthValue)));
|
||||
lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ SettingSetTime::SettingSetTime(
|
|||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblHours, true);
|
||||
|
||||
lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
|
@ -58,6 +59,7 @@ SettingSetTime::SettingSetTime(
|
|||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblMinutes, true);
|
||||
|
||||
lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
|
@ -126,7 +128,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (hoursValue > 23)
|
||||
hoursValue = 0;
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnHoursMinus) {
|
||||
|
@ -134,7 +135,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (hoursValue < 0)
|
||||
hoursValue = 23;
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnMinutesPlus) {
|
||||
|
@ -142,7 +142,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (minutesValue > 59)
|
||||
minutesValue = 0;
|
||||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnMinutesMinus) {
|
||||
|
@ -150,7 +149,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
if (minutesValue < 0)
|
||||
minutesValue = 59;
|
||||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
else if (object == btnSetTime) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user