diff --git a/src/widgets/calendar/lv_calendar.c b/src/widgets/calendar/lv_calendar.c index 3439baf15eb1..6aaac69023fd 100644 --- a/src/widgets/calendar/lv_calendar.c +++ b/src/widgets/calendar/lv_calendar.c @@ -83,6 +83,18 @@ void lv_calendar_set_day_names(lv_obj_t * obj, const char * day_names[]) lv_obj_invalidate(obj); } +void lv_calendar_set_year_list(lv_obj_t * obj, const char * years_list) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + + lv_obj_t * calendar_header = lv_obj_get_child(obj, 0); + lv_obj_t * year_dropdown = lv_obj_get_child(calendar_header, 0); + lv_dropdown_clear_options(year_dropdown); + lv_dropdown_set_options(year_dropdown, years_list); + + lv_obj_invalidate(obj); +} + void lv_calendar_set_today_date(lv_obj_t * obj, uint32_t year, uint32_t month, uint32_t day) { LV_ASSERT_OBJ(obj, MY_CLASS); diff --git a/src/widgets/calendar/lv_calendar.h b/src/widgets/calendar/lv_calendar.h index 00e06a4231e1..75293de5419d 100644 --- a/src/widgets/calendar/lv_calendar.h +++ b/src/widgets/calendar/lv_calendar.h @@ -103,6 +103,15 @@ void lv_calendar_set_highlighted_dates(lv_obj_t * obj, lv_calendar_date_t highli */ void lv_calendar_set_day_names(lv_obj_t * obj, const char ** day_names); +/** + * Sets a custom year list + * @param obj pointer to a calendar object + * @param years_list pointer to an const char array with the years list, see lv_dropdown set_options for more information. + * E.g. `const char * years = "2023\n2022\n2021\n2020\n2019" + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_year_list(lv_obj_t * obj, const char * years_list); + /*===================== * Getter functions *====================*/