Skip to content

Commit

Permalink
feature(calendar): Add interface to set a custom year list
Browse files Browse the repository at this point in the history
  • Loading branch information
C47D committed Jan 8, 2024
1 parent e217674 commit 4e631af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/widgets/calendar/lv_calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/widgets/calendar/lv_calendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*====================*/
Expand Down

0 comments on commit 4e631af

Please sign in to comment.