Skip to content

Commit

Permalink
fix(calendar) fix incorrect highlight of today
Browse files Browse the repository at this point in the history
fixes #2446
  • Loading branch information
kisvegabor committed Aug 10, 2021
1 parent 0f14f49 commit adbac52
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/extra/widgets/calendar/lv_calendar.c
Expand Up @@ -135,6 +135,12 @@ void lv_calendar_set_showed_date(lv_obj_t * obj, uint32_t year, uint32_t month)
}

highlight_update(obj);

/*Reset the focused button if the days changes*/
if(lv_btnmatrix_get_selected_btn(obj) != LV_BTNMATRIX_BTN_NONE) {
lv_btnmatrix_set_selected_btn(obj, day_first + 7);
}

lv_obj_invalidate(obj);
}

Expand Down Expand Up @@ -339,7 +345,7 @@ static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day)
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + b + (b / 4) - (b / 100) + (b / 400)) % 7;
#endif

return day_of_week;
return day_of_week ;
}

static void highlight_update(lv_obj_t * obj)
Expand All @@ -360,7 +366,9 @@ static void highlight_update(lv_obj_t * obj)

if(calendar->showed_date.year == calendar->today.year && calendar->showed_date.month == calendar->today.month) {
uint8_t day_first = get_day_of_week(calendar->today.year, calendar->today.month, 0);
lv_btnmatrix_set_btn_ctrl(obj, calendar->today.day + day_first + 7, LV_CALENDAR_CTRL_TODAY);
uint8_t tmp = calendar->today.day + day_first;
if(tmp >= 7) tmp -= 7; /*Do not leave an empty line*/
lv_btnmatrix_set_btn_ctrl(obj, tmp + 7, LV_CALENDAR_CTRL_TODAY);
}
}

Expand Down

0 comments on commit adbac52

Please sign in to comment.