lv_demo_calendar.c 1.5 KB

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