当前位置:网站首页>LVGL 7.11 tileview界面循环切换
LVGL 7.11 tileview界面循环切换
2022-07-25 16:16:00 【仙剑情缘】
定义变量
static const lv_point_t valid_pos2[] = {
{
0, 0}, {
0, 1} ,{
0,2},{
0,3},{
0,4}, {
1,2} ,{
2,2},{
3,2} };
static int delay_cnt;
static int last_hor_pos;
#define VALID_POS_LEN sizeof(valid_pos2)/sizeof(valid_pos2[0])
typedef lv_obj_t* (*tileview_elem)(lv_obj_t* scr);
lv_obj_t* create_tileview_elem_00_03(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 0_3");
return btn;
}
lv_obj_t* create_tileview_elem_0_1(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 0_1");
return btn;
}
lv_obj_t* create_tileview_elem_0_2(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 0_2");
return btn;
}
lv_obj_t* create_tileview_elem_0_3(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 0_3");
return btn;
}
lv_obj_t* create_tileview_elem_04_01(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 0_1");
return btn;
}
lv_obj_t* create_tileview_elem_1_2(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 1_2");
return btn;
}
lv_obj_t* create_tileview_elem_2_2(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 2_2");
return btn;
}
lv_obj_t* create_tileview_elem_3_2(lv_obj_t* scr)
{
lv_obj_t* btn = lv_btn_create(scr, NULL);
lv_obj_align(btn, scr, LV_ALIGN_CENTER, 0, 0);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text_fmt(label, "Button 3_2");
return btn;
}
const tileview_elem s_tileview[VALID_POS_LEN] = {
create_tileview_elem_00_03,
create_tileview_elem_0_1,
create_tileview_elem_0_2,
create_tileview_elem_0_3,
create_tileview_elem_04_01,
create_tileview_elem_1_2,
create_tileview_elem_2_2,
create_tileview_elem_3_2,
};
定时器回调函数
tatic void page_task(struct _lv_task_t* task)
{
if (lv_anim_count_running())
return;
lv_obj_t *obj = task->user_data;
if (delay_cnt)
{
if (--delay_cnt == 0) {
lv_coord_t x, y;
lv_tileview_get_tile_act(obj, &x, &y);
if (x == 0 && y == 0) {
lv_tileview_set_tile_act(obj, 0, 3, LV_ANIM_OFF);
}
else
if (x == 0 && y == last_hor_pos) {
lv_tileview_set_tile_act(obj, 0, 1, LV_ANIM_OFF);
}
}
}
}
事件处理回调函数
void btn_handler(struct _lv_obj_t* obj, lv_event_t event)
{
LV_LOG_USER("--event %d", event);
if (event == LV_EVENT_PRESSING)
{
delay_cnt = 10;
}
}
创建tileview
lv_obj_t * init_main_tileview(void)
{
lv_obj_t* tv = lv_tileview_create(lv_scr_act(), NULL);
lv_obj_set_style_local_bg_opa(tv, LV_TILEVIEW_PART_SCROLLBAR, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_bg_opa(tv, LV_TILEVIEW_PART_BG, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_tileview_set_valid_positions(tv, valid_pos2, VALID_POS_LEN);
lv_tileview_set_edge_flash(tv, true);
lv_obj_set_size(tv, LV_HOR_RES, LV_VER_RES);
lv_obj_set_pos(tv, 0, 0);
last_hor_pos = 0;
for (int i = 0; i < VALID_POS_LEN; i++)
{
if (valid_pos2[i].x == 0)
{
if (valid_pos2[i].y > last_hor_pos)
last_hor_pos = valid_pos2[i].y;
}
}
LV_LOG_USER("--last_hor_pos %d", last_hor_pos);
for (int i = 0; i < VALID_POS_LEN; i++) {
lv_obj_t* cont = s_tileview[i](tv);
lv_obj_set_size(cont, LV_HOR_RES, LV_HOR_RES);
lv_obj_set_pos(cont, valid_pos2[i].x* LV_HOR_RES, valid_pos2[i].y* LV_HOR_RES);
lv_tileview_add_element(tv, cont);
if (i == 1 || i == last_hor_pos-1)
{
lv_obj_set_event_cb(cont, btn_handler);
lv_obj_set_user_data(cont, tv);
}
}
lv_task_create(page_task, 10, LV_TASK_PRIO_LOW, tv);
lv_tileview_set_tile_act(tv, 0, 2, LV_ANIM_OFF);
return tv;
}
运行效果

边栏推荐
- 权限管理-删除菜单(递归)
- Sum arrays with recursion
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- 微信小程序不使用插件,渲染富文本中的视频,图片自适应,plus版本
- 只有1000元能买什么理财产品赚钱?
- 墨天轮高分技术文档分享——数据库安全篇(共48个)
- Recursive menu query (recursion: check yourself)
- Food safety - do you really understand the ubiquitous frozen food?
- MySQL tutorial 67- filter duplicate data using distinct
- 百奥赛图与LiberoThera共同开发全人GPCR抗体药物取得里程碑式进展
猜你喜欢

Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network

使用 Terraform 在 AWS 上快速部署 MQTT 集群

【图像隐藏】基于混合 DWT-HD-SVD 的数字图像水印方法技术附matlab代码

EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心

The second revolution of reporting tools

What is the shortcut key for win11 Desktop Switching? Win11 fast desktop switching method

Differences between cookies, cookies and sessions

Food safety - do you really understand the ubiquitous frozen food?

伦敦银K线图的各种有用形态

Analysis and solution of data and clock mismatch delay in SPI transmission
随机推荐
0x80131500 solution for not opening Microsoft Store
MySQL tutorial 67- filter duplicate data using distinct
面试8家公司,1周拿了5个offer,分享一下自己的心得
Lazy loading of pictures
食品安全丨无处不在的冷冻食品,你真的了解吗?
How does win11's own drawing software display the ruler?
【图像去噪】基于双立方插值和稀疏表示实现图像去噪matlab源码
MyBaits
[image denoising] image denoising based on bicube interpolation and sparse representation matlab source code
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
Visual studio 2022 view class diagram
从业务需求出发,开启IDC高效运维之路
终极套娃 2.0 | 云原生交付的封装
权限管理-删除菜单(递归)
[Shakespeare: keep the fun of being a man]
记得那两句话
Equivalent change of resistance circuit (Ⅱ)
Talk about how to use redis to realize distributed locks?
阿唐的小帮手
R语言ggplot2可视化线图(line)、自定义配置标题文本相关内容颜色和图例(legend)颜色相匹配(和分组线图的颜色相匹配、match colors of groups)