当前位置: 首页 > article >正文

使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第十五讲)

这一期讲解lvgl中日历控件的基础使用,Calendar 部件是一个经典日历,它具有以下功能:

• 通过一个7x7矩阵显示任何月份
• 显示日期名称
• 突出显示当前日期(今天)
• 突出显示任何用户定义的日期
日历是一个可编辑的小部件,它允许使用编码器或键盘导航以及指针类型的输入设备来选择和点击日期。为了使日历更具灵活性,默认情况下它不显示当前年份或月份。相反,有一些可选的 “标题” 可以附加到日历上。

日历小部件在底层使用了 Button Matrix 部件来将日期排列成矩阵形式。

• LV_PART_MAIN 日历的背景。使用所有与背景相关的样式属性。
• LV_PART_ITEMS 指日期和日期名称。
设置了按钮矩阵控制标志以区分按钮,并添加了一个自定义绘制事件来按如下方式修改按钮的属性:
o 日期名称没有边框,没有背景,用灰色绘制
o 矩阵中上个月和下个月的天数有 LV_BUTTONMATRIX_CTRL_DISABLED 标志
o 今天(你指定的日期)有较厚的边框(使用主题的主色) - 突出显示的日期具有一定透明度的主题主颜色。
默认主题在工程中的样子具体如下图所示:
在这里插入图片描述
在GUI_Guider平台提供多种模块去设置日历控件,具体如下图所示:
在这里插入图片描述
(1) mian:指的是当前主体的阴影、边框与背景。
(2) header:指的是日历的标题颜色背景以及字体大小颜色设置。
(3) weekday names:是日历中每个周的字体大小和格式
(4) highlight day:是指图中29好的状态就是高亮状态,这里可以修改颜色以及字体大小和格式。
(5) today:指代码设置当天的标识状态,目前是灰色背景,在该界面中可以修改背景颜色以及字体大小和格式。
(6) days in other month:将日历中当前月份的其他日期设置,可以设置背景颜色以及字体的大小颜色和格式。
(7) days in current month:将日历中当前月份的日期设置,可以设置背景颜色以及字体的大小颜色和格式。

以下是具体的代码:
//Write codes screen_1_calendar_1
//在 screen_1 屏幕上创建了一个日历组件 screen_1_calendar_1。
ui->screen_1_calendar_1 = lv_calendar_create(ui->screen_1);
//设置当前日期
screen_1_calendar_1_today.year = 2025;
screen_1_calendar_1_today.month = 5;
screen_1_calendar_1_today.day = 28;
lv_calendar_set_today_date(ui->screen_1_calendar_1, screen_1_calendar_1_today.year, screen_1_calendar_1_today.month, screen_1_calendar_1_today.day);
//显示日期
lv_calendar_set_showed_date(ui->screen_1_calendar_1, screen_1_calendar_1_today.year, screen_1_calendar_1_today.month);
//高亮显示日期
screen_1_calendar_1_highlihted_days[0].year = 2025;
screen_1_calendar_1_highlihted_days[0].month = 5;
screen_1_calendar_1_highlihted_days[0].day = 29;
lv_calendar_set_highlighted_dates(ui->screen_1_calendar_1, screen_1_calendar_1_highlihted_days, 1);
//Write style state: LV_STATE_DEFAULT for &style_screen_1_calendar_1_main_main_default
//设置样式
static lv_style_t style_screen_1_calendar_1_main_main_default;
ui_init_style(&style_screen_1_calendar_1_main_main_default);

lv_style_set_border_width(&style_screen_1_calendar_1_main_main_default, 1);
lv_style_set_border_opa(&style_screen_1_calendar_1_main_main_default, 255);
lv_style_set_border_color(&style_screen_1_calendar_1_main_main_default, lv_color_hex(0xc0c0c0));
lv_style_set_border_side(&style_screen_1_calendar_1_main_main_default, LV_BORDER_SIDE_FULL);
lv_style_set_bg_opa(&style_screen_1_calendar_1_main_main_default, 255);
lv_style_set_bg_color(&style_screen_1_calendar_1_main_main_default, lv_color_hex(0xffffff));
lv_style_set_bg_grad_dir(&style_screen_1_calendar_1_main_main_default, LV_GRAD_DIR_NONE);
lv_style_set_shadow_width(&style_screen_1_calendar_1_main_main_default, 0);
lv_style_set_radius(&style_screen_1_calendar_1_main_main_default, 0);
lv_obj_add_style(ui->screen_1_calendar_1, &style_screen_1_calendar_1_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

//Write style state: LV_STATE_DEFAULT for &style_screen_1_calendar_1_extra_header_main_default
// 头部样式
static lv_style_t style_screen_1_calendar_1_extra_header_main_default;
ui_init_style(&style_screen_1_calendar_1_extra_header_main_default);

lv_style_set_text_color(&style_screen_1_calendar_1_extra_header_main_default, lv_color_hex(0xffffff));
lv_style_set_text_font(&style_screen_1_calendar_1_extra_header_main_default, &lv_font_montserratMedium_12);
lv_style_set_text_opa(&style_screen_1_calendar_1_extra_header_main_default, 255);
lv_style_set_bg_opa(&style_screen_1_calendar_1_extra_header_main_default, 255);
lv_style_set_bg_color(&style_screen_1_calendar_1_extra_header_main_default, lv_color_hex(0x2195f6));
lv_style_set_bg_grad_dir(&style_screen_1_calendar_1_extra_header_main_default, LV_GRAD_DIR_NONE);
lv_obj_add_style(screen_1_calendar_1_header, &style_screen_1_calendar_1_extra_header_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

//Write style state: LV_STATE_DEFAULT for &style_screen_1_calendar_1_main_items_default
//日历按钮矩阵项样式
static lv_style_t style_screen_1_calendar_1_main_items_default;
ui_init_style(&style_screen_1_calendar_1_main_items_default);

lv_style_set_bg_opa(&style_screen_1_calendar_1_main_items_default, 0);
lv_style_set_border_width(&style_screen_1_calendar_1_main_items_default, 1);
lv_style_set_border_opa(&style_screen_1_calendar_1_main_items_default, 255);
lv_style_set_border_color(&style_screen_1_calendar_1_main_items_default, lv_color_hex(0xc0c0c0));
lv_style_set_border_side(&style_screen_1_calendar_1_main_items_default, LV_BORDER_SIDE_FULL);
lv_style_set_text_color(&style_screen_1_calendar_1_main_items_default, lv_color_hex(0x0D3055));
lv_style_set_text_font(&style_screen_1_calendar_1_main_items_default, &lv_font_montserratMedium_12);
lv_style_set_text_opa(&style_screen_1_calendar_1_main_items_default, 255);
lv_obj_add_style(lv_calendar_get_btnmatrix(ui->screen_1_calendar_1), &style_screen_1_calendar_1_main_items_default, LV_PART_ITEMS|LV_STATE_DEFAULT);

下一期讲解日历控件如何添加回调。
本文章由威三学社出品
对课程感兴趣可以私信联系

http://www.lryc.cn/news/2402204.html

相关文章:

  • Vue中实现表格吸底滚动条效果,列太多时左右滚动条始终显示在页面中
  • BeeWorks 协同办公能力:局域网内企业级协作的全场景重构
  • Mermaid 绘图--以企业权限视图为例
  • Redis(02)Win系统如何将Redis配置为开机自启的服务
  • C++课设:高效的日程管理系统
  • 功能测试、性能测试、安全测试详解
  • 提示词指南 --- 提示词的基本结构
  • UI学习—cell的复用和自定义cell
  • 20250605使用boot-repair来恢复WIN10和ubuntu22.04.6双系统的启动
  • 网络安全面试题目(无答案)
  • JavaScript性能优化实战
  • 接口安全SOAPOpenAPIRESTful分类特征导入项目联动检测
  • 视频汇聚平台EasyCVR“明厨亮灶”方案筑牢旅游景区餐饮安全品质防线
  • sql server如何创建表导入excel的数据
  • 仓库自动化搬运:自动叉车与AGV选型要点及核心技术解析
  • java UDP 模板
  • 【亲测有效】Mybatis-Plus更新字段为null
  • NLP学习路线图(二十五):注意力机制
  • 05 APP 自动化- Appium 单点触控 多点触控
  • MyBatis-Plus LambdaQuery 高级用法:JSON 路径查询与条件拼接的全场景解析
  • [AI绘画]sd学习记录(一)软件安装以及文生图界面初识、提示词写法
  • SpringBoot(八) --- SpringBoot原理
  • SpringBoot自动化部署全攻略:CI/CD高效实践与避坑指南
  • idea json生成实体类
  • C# 类和继承(抽象成员)
  • gitlab rss订阅失败
  • 鸿蒙仓颉语言开发实战教程:商城登录页
  • JavaScript 数组与流程控制:从基础操作到实战应用
  • STM32中自动生成Flash地址的方法
  • Matlab | MATLAB 中的插值详解