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

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

首先在上期讲解代码的文件中添加全局变量以及俩个回调函数,具体代码如下:
lv_calendar_date_t screen_6_calendar_1_today;
lv_calendar_date_t screen_6_calendar_1_highlihted_days[1];

void screen_6_calendar_1_draw_part_begin_event_cb(lv_event_t *e) {
lv_obj_draw_part_dsc_t *dsc = lv_event_get_draw_part_dsc(e);
if (dsc->part == LV_PART_ITEMS) {
// 针对日期格子
lv_calendar_date_t date;
lv_calendar_get_pressed_date(guider_ui.screen_6_calendar_1, &date);
if (date.day == dsc->id && date.month ==date.month) {
// 高亮当天
dsc->rect_dsc->bg_color = lv_color_hex(0xFF0000); }
}
}
void screen_6_calendar_1_event_handler(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_VALUE_CHANGED) {
// 日期被点击
lv_calendar_date_t date;
lv_calendar_get_pressed_date(guider_ui.screen_6_calendar_1, &date);
//设置高亮的日期
screen_6_calendar_1_highlihted_days[0].year = date.year;
screen_6_calendar_1_highlihted_days[0].month = date.month;
screen_6_calendar_1_highlihted_days[0].day = date.day;
lv_calendar_set_highlighted_dates(guider_ui.screen_6_calendar_1, screen_6_calendar_1_highlihted_days, 1);
}
}

以上两个函数的作用是将用户点击的日期高亮的显示出来。

最后在代码中添加回调函数的声明,以及日历大小的设置,具体代码如下图所示:

//设置回调函数
lv_obj_t *screen_6_calendar_1_header = lv_calendar_header_arrow_create(ui->screen_6_calendar_1);
lv_calendar_t *screen_6_calendar_1 = (lv_calendar_t *)ui->screen_6_calendar_1;
lv_obj_add_event_cb(screen_6_calendar_1->btnm, screen_6_calendar_1_draw_part_begin_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
lv_obj_add_event_cb(ui->screen_6_calendar_1, screen_6_calendar_1_event_handler, LV_EVENT_ALL, NULL);
//设置日历大小以及位置
lv_obj_set_pos(ui->screen_6_calendar_1, 100, -280);
lv_obj_set_size(ui->screen_6_calendar_1, 280, 210);

以下是官方手册中提供的用法,这里就不进行一一讲解:
在这里插入图片描述
最后是使用的实例图片:
在这里插入图片描述

http://www.xdnf.cn/news/13414.html

相关文章:

  • DnSpy调试基础
  • gRPC、WebSocket 与 HTTP 的核心区别对比
  • 将两个变量a,b的值进行交换,不使用任何中间变量
  • Cursor 工具项目构建指南:让 AI 审查 AI 生产的内容,确保生产的内容质量和提前发现问题
  • Vim 翻页与滚动命令总览
  • 新能源知识库(35)AutoML在用电负荷预测中如何应用?
  • 【杂谈】-递归进化:人工智能的自我改进与监管挑战
  • Linux基础指令大全
  • SpringCloud微服务入门
  • Day50 Python打卡训练营
  • Vim 修改(change)命令完整学习笔记
  • [原创]X86C++反汇编02.算术指令
  • 闪回还能导致OGG同步失败
  • 生成xcframework
  • 一个获取极简风格动画素材的网站
  • Day11_刷题niuke20250610
  • CppCon 2015 学习:C++ Requests
  • Vim 插件管理:MiniBufExplorer 使用指南
  • 区块链Web3项目的开发
  • Dify 知识库深度剖析:从构建到高效应用
  • 【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型
  • kotlin kmp 副作用函数 effect
  • 使用Ajax从前端向后端发起请求
  • Prometheus基础使用指南
  • 鹰盾加密虚拟机保护技术的深度解析:从指令级虚拟化到动态对抗系统
  • (LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
  • Windows cmd中文乱码解决方法(Windows控制台中文乱码、CMD乱码、控制台乱码、Command Prompt命令提示符cmd.exe乱码)
  • JxBrowser 7.43.2 版本发布啦!
  • 预训练模型 CBAM注意力
  • 【docker n8n】windows环境如何挂载