lv_demo_calendar.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <lvgl.h>
  2. #include <drv_lcd.h>
  3. static void event_handler(lv_event_t * e)
  4. {
  5. lv_event_code_t code = lv_event_get_code(e);
  6. lv_obj_t * obj = lv_event_get_current_target(e);
  7. if(code == LV_EVENT_VALUE_CHANGED) {
  8. lv_calendar_date_t date;
  9. if(lv_calendar_get_pressed_date(obj, &date)) {
  10. LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
  11. }
  12. }
  13. }
  14. void lv_demo_calendar(void)
  15. {
  16. lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
  17. lv_obj_set_size(calendar, LCD_W, LCD_H);
  18. lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 0);
  19. lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);
  20. lv_calendar_set_today_date(calendar, 2021, 02, 23);
  21. lv_calendar_set_showed_date(calendar, 2021, 02);
  22. /*Highlight a few days*/
  23. static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
  24. highlighted_days[0].year = 2021;
  25. highlighted_days[0].month = 02;
  26. highlighted_days[0].day = 6;
  27. highlighted_days[1].year = 2021;
  28. highlighted_days[1].month = 02;
  29. highlighted_days[1].day = 11;
  30. highlighted_days[2].year = 2022;
  31. highlighted_days[2].month = 02;
  32. highlighted_days[2].day = 22;
  33. lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
  34. #if LV_USE_CALENDAR_HEADER_DROPDOWN
  35. lv_calendar_header_dropdown_create(calendar);
  36. #elif LV_USE_CALENDAR_HEADER_ARROW
  37. lv_calendar_header_arrow_create(calendar);
  38. #endif
  39. lv_calendar_set_showed_date(calendar, 2021, 10);
  40. }