[English]

Calendar(日历) (lv_calendar)

Overview(概述)

显示原文

The Calendar object is a classic calendar which can: - show the days of any month in a 7x7 matrix - Show the name of the days - highlight the current day (today) - highlight any user-defined dates

The Calendar is added to the default group (if it is set). Calendar is an editable object which allow selecting and clicking the dates with encoder navigation too.

To make the Calendar flexible, by default it doesn't show the current year or month. Instead, there are optional "headers" that can be attached to the calendar.


Calendar 对象是一个经典日历,它可以:- 显示 7x7 矩阵中的任何月份 - 显示日期名称 - 突出显示当前日期(今天)- 突出显示任何用户定义的日期

日历将添加到默认组(如果已设置)。日历是一个可编辑的对象,允许选择和单击日期编码器导航也是如此。

为了使日历灵活,默认情况下它不显示当前的年或月。相反,有可选的“标头”可以是附加到日历。

Parts and Styles(零件和样式)

显示原文

The calendar object uses the Button matrix object under the hood to arrange the days into a matrix.

  • LV_PART_MAIN The background of the calendar. Uses all the background related style properties.

  • LV_PART_ITEMS Refers to the dates and day names. Button matrix control flags are set to differentiate the buttons and a custom drawer event is added modify the properties of the buttons as follows:

    • day names have no border, no background and drawn with a gray color

    • days of the previous and next month have LV_BUTTONMATRIX_CTRL_DISABLED flag

    • today has a thicker border with the theme's primary color - highlighted days have some opacity with the theme's primary color.


calendar 对象使用后台下的按钮矩阵对象将日期排列到矩阵中。

  • LV_PART_MAIN 日历的背景。使用所有与背景相关的样式属性。

  • LV_PART_ITEMS 指日期和日期名称。设置按钮矩阵控制标志以区分 按钮,并添加自定义抽屉事件,按如下方式修改按钮的属性:

    • 日期名称没有边框,没有背景,用灰色绘制

    • 上个月和下个月的天数有 LV_BUTTONMATRIX_CTRL_DISABLED 标志

    • 今天与主题的原色有较厚的边框 - 突出显示的日子与主题的原色有一些不透明。

日期名称没有边框,没有背景,用灰色绘制

上个月和下个月的天数有标志

今天主题的原色有较厚的边框 - 突出显示的日子与主题的原色有一些不透明。

Usage(用法)

显示原文

Some functions use the lv_calendar_date_t type which is a structure with year, month and day fields.


某些函数使用 lv_calendar_date_t 结构类型,这是一种结构带有 , 字段。

Current date(当前日期)

显示原文

To set the current date (today), use the lv_calendar_set_today_date(calendar, year, month, day) function. month needs to be in 1..12 range and day in 1..31 range.


要设置当前日期(今天),请使用 lv_calendar_set_today_date(calendar, year, month, day) 功能。 需要在 1..12 范围并且 在 1..31 范围内。

Shown date(显示日期)

显示原文

To set the shown date, use lv_calendar_set_shown_date(calendar, year, month)


要设置显示的日期,请使用 lv_calendar_set_shown_date(calendar, year, month)

Highlighted days(重要日子)

显示原文

The list of highlighted dates should be stored in a lv_calendar_date_t array loaded by lv_calendar_set_highlighted_dates(calendar, highlighted_dates, date_num). Only the array's pointer will be saved so the array should be a static or global variable.


突出显示的日期列表应存储在 lv_calendar_date_t 数组,通过 lv_calendar_set_highlighted_dates(calendar, highlighted_dates, date_num) 加载。 只有数组的指针将被保存,因此数组应该是静态的或全局变量。

Name of the days(日期名称)

显示原文

The name of the days can be adjusted with lv_calendar_set_day_names(calendar, day_names) where day_names looks like const char * day_names[7] = {"Su", "Mo", ...}; Only the pointer of the day names is saved so the elements should be static, global or constant variables.


可以使用 lv_calendar_set_day_names(calendar, day_names) 调整日期的名称,其中 day_names 看起来像 const char * day_names[7] = {"Su", "Mo", ...}; 只有保存日期名称的指针,因此元素应该是静态的, 全局变量或常量变量。

Custom year list(自定义年份列表)

显示原文

Sets a custom year list with lv_calendar_header_dropdown_set_year_list(calendar, years_list) where years_list is a pointer to the custom years list. It can be a constant string like static const char * years = "2023\n2022\n2021\n2020\n2019";, or can be generated dynamically into a buffer as well.


使用 lv_calendar_header_dropdown_set_year_list(calendar, years_list) 设置自定义年份列表,其中 years_list 是指向自定义年份列表的指针。它可以是一个常量字符串像 static const char * years = "2023\n2022\n2021\n2020\n2019";,或者也可以动态生成到缓冲区中。

Chinese calendar(中国日历)

显示原文

The Chinese calendar is a traditional cultural tool that integrates elements such as the lunar calendar, solar terms, and traditional festivals. It is widely used in Chinese social life, helping people understand the dates of the lunar calendar, arrange festival activities, and inherit the excellent traditional culture of the Chinese nation. Whether in families, businesses, or education, the Chinese calendar plays an irreplaceable role, enabling people to better understand and appreciate the charm of Chinese traditional culture.

If you want to use the Chinese calendar, please use lv_calendar_set_chinese_mode(calendar, true) to enable it.


中国历法是一种融合元素的传统文化工具 如农历、节气和传统节日。是的 广泛应用于中国社会生活,帮助人们了解日期 农历,安排节日活动,传承优秀 中华民族传统文化。无论是在家庭、企业、 或教育,中国历法起着不可替代的作用,使 人们更好地理解和欣赏中国传统的魅力 文化。

如果您想使用中国日历,请使用 lv_calendar_set_chinese_mode(calendar, true) 启用它。

Events(事件)

显示原文

Learn more about Events(事件).


详细了解更多 Events(事件)

Keys(按键)

显示原文
  • LV_KEY_RIGHT/UP/LEFT/RIGHT To navigate among the buttons to dates

  • LV_KEY_ENTER To press/release the selected date

Learn more about Keys(按键).


  • LV_KEY_RIGHT/UP/LEFT/RIGHT 在按钮之间导航到日期

  • LV_KEY_ENTER 按下/松开所选日期

详细了解更多 Keys(按键)

Headers(头部)

显示原文

From v8.1 the header is added directly into the Calendar widget and the API of the headers has been changed.


从 v8.1 开始,标题直接添加到日历小部件中,并且 标头的 API 已更改。

Arrow buttons(箭头按钮)

显示原文

lv_calendar_header_arrow_create(calendar) creates a header that contains a left and right arrow on the sides and a text with the current year and month between them.


lv_calendar_header_arrow_create(calendar) 创建一个标头,该标头两侧包含一个左右箭头和一个带有当前他们之间的年和月

Example

[English]

Calendar with header

#include "../../lv_examples.h"
#if LV_USE_CALENDAR && LV_BUILD_EXAMPLES

static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_current_target(e);

    if(code == LV_EVENT_VALUE_CHANGED) {
        lv_calendar_date_t date;
        if(lv_calendar_get_pressed_date(obj, &date)) {
            LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
        }
    }
}

void lv_example_calendar_1(void)
{
    lv_obj_t  * calendar = lv_calendar_create(lv_screen_active());
    lv_obj_set_size(calendar, 185, 230);
    lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 27);
    lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);

    lv_calendar_set_today_date(calendar, 2021, 02, 23);
    lv_calendar_set_showed_date(calendar, 2021, 02);

    /*Highlight a few days*/
    static lv_calendar_date_t highlighted_days[3];       /*Only its pointer will be saved so should be static*/
    highlighted_days[0].year = 2021;
    highlighted_days[0].month = 02;
    highlighted_days[0].day = 6;

    highlighted_days[1].year = 2021;
    highlighted_days[1].month = 02;
    highlighted_days[1].day = 11;

    highlighted_days[2].year = 2022;
    highlighted_days[2].month = 02;
    highlighted_days[2].day = 22;

    lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);

#if LV_USE_CALENDAR_HEADER_DROPDOWN
    lv_calendar_header_dropdown_create(calendar);
#elif LV_USE_CALENDAR_HEADER_ARROW
    lv_calendar_header_arrow_create(calendar);
#endif
}

#endif

API

lv_calendar_header_dropdown.h

lv_calendar_header_arrow.h

lv_calendar.h