[LVGL] 使用lvgl自带的链表函数
#include "lvgl.h"
//学生信息类型
typedef struct StudentInfo StudentInfo_t;
struct StudentInfo
{
char name[15]; //姓名
int height;//身高
int score;//成绩
};
//学生信息表
StudentInfo_t std_table[] = {
{"ZhangSan", 175, 90},
{"LiSi", 178, 100},
{"WangWu", 180, 85},
{"CheLiu", 190, 92},
{"FengQi", 190, 100},
};
void lv_ll_test()
{
StudentInfo_t* std;
lv_ll_t std_ll;
_lv_ll_init(&std_ll, sizeof(StudentInfo_t)); // 初始化std_ll链表
/* 遍历学生信息表,将学生信息添加到std_ll中 */
for (int i = 0; i < (sizeof(std_table) / sizeof(std_table[0])); i++)
{
std = (StudentInfo_t*)_lv_ll_ins_tail(&std_ll);
lv_snprintf(std->name, sizeof(std->name), std_table[i].name);
std->height = std_table[i].height;
std->score = std_table[i].score;
}
/* 遍历std_ll,删除WangWu的信息,并显示其他学生的信息*/
std = (StudentInfo_t*)_lv_ll_get_head(&std_ll);
while (std)
{
if ( strcmp(std->name,"WangWu") == 0)
{
_lv_ll_remove(&std_ll, std);//删除:王五
}
else
{
//显示其他学生的信息
printf("# Name:%-10s Height:%d\tScore:%d\n", std->name, std->height, std->score);
}
std = (StudentInfo_t*)_lv_ll_get_next(&std_ll, std);
}
}
运行的效果如下: