当前位置:网站首页>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;
}
运行效果

边栏推荐
- R语言使用gt包和gtExtras包漂亮地显示表格数据:gt_bar_plot函数和gt_plt_bar_pct函数可视化百分比条形图、原始数据的百分比条形、缩放后的数据的百分比条形、指定数据对齐宽度
- 2w字详解数据湖:概念、特征、架构与案例
- MySQL隐式锁
- MySQL isolation level transactions
- How does win11's own drawing software display the ruler?
- 聊聊如何用 Redis 实现分布式锁?
- 只有1000元能买什么理财产品赚钱?
- MySQL全局锁
- Win11桌面切换快捷键是什么?Win11快速切换桌面的方法
- Shared lock
猜你喜欢

Product dynamics - Android 13 high-efficiency adaptation new upgrade

JWT diagram

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

【图像去噪】基于双立方插值和稀疏表示实现图像去噪matlab源码

哪个led显示屏厂家更好

leetcode:6127. 优质数对的数目【位运算找规律 + 两数之和大于等于k + 二分】
![[image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code](/img/2a/b5214e9fa206f1872293c9b9d7bdb6.png)
[image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code

leetcode:528. 按权重随机选择【普通随机失效 + 要用前缀和二分】

Upgrade esxi6.7.0 to 7.0u3f (updated on July 12, 2022)

食品安全丨无处不在的冷冻食品,你真的了解吗?
随机推荐
MySQL implicit lock
解决Win10磁盘占用100%
一文理解分布式开发中的服务治理
MySQL tutorial 66 data table query statement
PageHelper.startPage没有生效问题
Recommended collection, which is probably the most comprehensive coding method summary of category type features
Talk about how to use redis to realize distributed locks?
今天去 OPPO 面试,被问麻了
MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具
记得那两句话
Permission management - role assignment menu
2W word detailed data Lake: concept, characteristics, architecture and cases
推荐收藏,这或许是最全的类别型特征的编码方法总结
R语言偏相关性计算(Partial Correlation)、使用ggm包的pcor函数计算偏相关性(Partial Correlations)
mysql 表读锁
Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]
Sword finger offer | number of 1 in binary
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
权限管理-删除菜单(递归)
How does win11's own drawing software display the ruler?