C¶
Calendar with day select¶
code
#include "lvgl/lvgl.h"
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
lv_calendar_date_t * date = lv_calendar_get_pressed_date(obj);
if(date) {
lv_calendar_set_today_date(obj, date);
}
}
}
void lv_ex_calendar_1(void)
{
lv_obj_t * calendar = lv_calendar_create(lv_scr_act(), NULL);
lv_obj_set_size(calendar, 230, 230);
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(calendar, event_handler);
/*Set the today*/
lv_calendar_date_t today;
today.year = 2018;
today.month = 10;
today.day = 23;
lv_calendar_set_today_date(calendar, &today);
lv_calendar_set_showed_date(calendar, &today);
/*Highlight some days*/
static lv_calendar_date_t highlihted_days[3]; /*Only it's pointer will be saved so should be static*/
highlihted_days[0].year = 2018;
highlihted_days[0].month = 10;
highlihted_days[0].day = 6;
highlihted_days[1].year = 2018;
highlihted_days[1].month = 10;
highlihted_days[1].day = 11;
highlihted_days[2].year = 2018;
highlihted_days[2].month = 11;
highlihted_days[2].day = 22;
lv_calendar_set_highlighted_dates(calendar, highlihted_days, 3);
}
MicroPython¶
Calendar with day select¶
code
def event_handler(obj, event):
if event == lv.EVENT.CLICKED:
date = obj.get_pressed_date()
if date is not None:
obj.set_today_date(date)
calendar = lv.calendar(lv.scr_act())
calendar.set_size(230, 230)
calendar.align(None, lv.ALIGN.CENTER, 0, 0)
calendar.set_event_cb(event_handler)
# Set the today
today = lv.calendar_date_t()
today.year = 2018
today.month = 10
today.day = 23
calendar.set_today_date(today)
calendar.set_showed_date(today)
highlihted_days = [
lv.calendar_date_t({'year':2018, 'month':10, 'day':6}),
lv.calendar_date_t({'year':2018, 'month':10, 'day':11}),
lv.calendar_date_t({'year':2018, 'month':11, 'day':22})
]
calendar.set_highlighted_dates(highlihted_days, len(highlihted_days))