LittleVGL之日历控件

对于日历控件,顾名思义。和日历样式一样,我们先看效果图;
在这里插入图片描述
对于图中所示的样式一样,我们可以通过程序可以任意设置其样式和跳转到固定日期。

static void calender_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 calendar_test(void)
{
    
    
    lv_obj_t  * calendar = lv_calendar_create(lv_scr_act(), NULL);//获取一个屏幕对象,并且创建一个日历对象
    lv_obj_set_size(calendar, 460, 460);                            //设置日历大小
    lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);            //设置对齐方式
    lv_obj_set_event_cb(calendar, calender_event_handler);          //设置事件回调函数

    /*Set the today*/
    lv_calendar_date_t today;   //设置今天所在的日期
    today.year = 2021;
    today.month = 4;
    today.day = 13; 
        
    lv_calendar_set_today_date(calendar, &today);   //设定日历控件的日期
    lv_calendar_set_showed_date(calendar, &today);  //将今日日期进行显示

    /*Highlight some days*/
    static lv_calendar_date_t highlihted_days[1];       /*Only it's pointer will be saved so should be static*/
    highlihted_days[0].year = 2021;
    highlihted_days[0].month = 4;
    highlihted_days[0].day = 13;

    lv_calendar_set_highlighted_dates(calendar, highlihted_days, 1);
}

这个控件一般不会独立使用,用到的场景也很少,一般情况下,会结合滚轮控件使用。其实一般也是用这个控件进行一些显示效果。了解这个控件即可。

おすすめ

転載: blog.csdn.net/weixin_43352501/article/details/115669427