LVGL 滚筒图片菜单
时间: 2023-10-06 16:07:03 浏览: 199
LVGL 是一款功能强大的嵌入式图形库,可以实现各种UI界面效果,其中也包括滚筒图片菜单。下面是一个简单的滚筒图片菜单示例:
```c
// 定义一个滚筒菜单的回调函数
void roller_menu_cb(lv_obj_t * roller, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
printf("Selected item: %s\n", lv_roller_get_selected_str(roller));
}
}
// 创建一个滚筒菜单
lv_obj_t * roller_menu = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller_menu, "Apple\nBanana\nCherry\nDate\nElderberry\nFig\nGrapes\nHoneydew\n");
lv_roller_set_visible_row_count(roller_menu, 3); // 设置可见行数
lv_obj_set_width(roller_menu, 120); // 设置宽度
lv_obj_set_height(roller_menu, 100); // 设置高度
lv_obj_align(roller_menu, NULL, LV_ALIGN_CENTER, 0, 0); // 居中对齐
lv_obj_set_event_cb(roller_menu, roller_menu_cb); // 设置回调函数
// 设置滚筒菜单的样式
lv_obj_set_style_local_bg_color(roller_menu, LV_ROLLER_PART_BG, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_bg_color(roller_menu, LV_ROLLER_PART_SELECTED, LV_STATE_DEFAULT, LV_COLOR_RED);
lv_obj_set_style_local_text_color(roller_menu, LV_ROLLER_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_color(roller_menu, LV_ROLLER_PART_SELECTED, LV_STATE_DEFAULT, LV_COLOR_WHITE);
// 添加滚筒图片
lv_obj_t * roller_img = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(roller_img, "path/to/your/image.png");
lv_obj_align(roller_img, roller_menu, LV_ALIGN_OUT_RIGHT_MID, 10, 0); // 右对齐
// 开始运行
while(1) {
lv_task_handler();
usleep(5000);
}
```
注意,上面的示例中需要替换图片路径为你自己的图片路径。此外,你还可以根据需要调整滚筒菜单的样式。
阅读全文
相关推荐













