LVGL学习

注:本文使用的lvgl-release-v8.3版本,其它版本可能稍有不同。

01 快速入门

1.1 LVGL模拟器配置

day01-02_课程介绍_哔哩哔哩_bilibili

LVGL开发教程 (yuque.com)

 如果按照上述视频和文档中配置不成功的话,直接重装VsCode,我的就是重装以后就好了。

LVGL查询手册:

Introduction(介绍) — LVGL 文档 (100ask.net)

Welcome to the documentation of LVGL! — LVGL documentation

1.2 创建第一个对象

1.2.1 创建第一个对象

在main.c里添加一个创建对象的函数。

void demo1()
{// 1.构建一个显示图层(窗口)lv_obj_t* screen = lv_scr_act();// 2.在窗口上创建一个对象lv_obj_t* obj = lv_obj_create(screen); // 3.设置对象的位置lv_obj_set_pos(obj,10,30);// 4.设置对象的宽度和高度lv_obj_set_height(obj,50);lv_obj_set_width(obj,50);// 5.设置对象的对齐lv_obj_center(obj);               //执行这串代码会让这个对象在当前窗口居中lv_obj_align(obj,LV_ALIGN_BOTTOM_MID,0,0);              //底部居中对齐,后面两个参数是x方向和y方向偏移// 6.设置样式static lv_style_t style;lv_style_init(&style);lv_style_set_bg_color(&style,lv_palette_main(LV_PALETTE_RED));// 7.将样式和对象关联起来lv_obj_add_style(obj,&style,0);
}

然后在main函数里调用上述函数就完成了第一个对象的创建。

1.2.2 设置对象样式

void demo2()
{// 1.构建一个显示图层(窗口)lv_obj_t* screen = lv_scr_act();// 2.在窗口上创建一个对象lv_obj_t* obj = lv_obj_create(screen); // 3.设置对象的位置lv_obj_set_pos(obj,10,30);// 4.设置对象的宽度和高度lv_obj_set_height(obj,50);lv_obj_set_width(obj,50);// 5.设置对象的对齐lv_obj_center(obj);               //执行这串代码会让这个对象在当前窗口居中// 6.设置样式static lv_style_t style;lv_style_init(&style);lv_style_set_bg_color(&style,lv_palette_main(LV_PALETTE_BLUE));lv_style_set_radius(&style,20);         // 设置圆角// 7.将样式和对象关联起来lv_obj_add_style(obj,&style,0);
}

然后再main函数里调用。

1.3 控件

1.3.1 label文本

1.3.1.1 创建label标签
/*显示文本*/
void demo_label()
{// 1.得到当前活跃的屏幕lv_obj_t* screen = lv_scr_act();// 2.创建文本对象lv_obj_t* label = lv_label_create(screen);// 3.设置文本对象内容,位置,颜色等等lv_label_set_text(label,"Hello ICK");// lv_obj_set_pos(label,100,100);            //设置标签在屏幕上的位置lv_obj_set_align(label,LV_ALIGN_CENTER);  //设置标签位置在屏幕正中央// llv_obj_set_style_text_color(label,lv_color_hex(0x123456),0);   //设置标签中字体颜色lv_obj_set_style_text_color(label,lv_color_make(255,0,0),0);   //设置标签中字体颜色
}

1.3.1.2 不同设备上颜色设置 

1.3.1.3 改变label字体大小和颜色

注意看左下角和右下角会显示内存使用率和帧率,如果不像是要进行设置。

左下角和右下角没有了。 

配置了各种字体大小,写1是可用的。 

void demo_label()
{// 1.得到当前活跃的屏幕lv_obj_t* screen = lv_scr_act();// 2.创建文本对象lv_obj_t* label = lv_label_create(screen);// 3.设置文本对象内容,位置,颜色等等lv_label_set_text(label,"Hello ICK");// lv_obj_set_pos(label,100,100);            //设置标签在屏幕上的位置lv_obj_set_align(label,LV_ALIGN_CENTER);  //设置标签位置在屏幕正中央// llv_obj_set_style_text_color(label,lv_color_hex(0x123456),0);   //设置标签中字体颜色lv_obj_set_style_text_color(label,lv_color_make(255,0,0),0);   //设置标签中字体颜色,最后一个参数默认是0// 4.定义一个样式显示标签字体static lv_style_t style;lv_style_init(&style);         //初始化样式结构体lv_style_set_text_font(&style,&lv_font_montserrat_48);       //设置字体大小// 5.将样式和字体关联起来lv_obj_add_style(label,&style,0);  //最后一个参数默认是0
}

1.3.1.4 显示中文

 字体库转换(对中文进行编码):

Font Converter — LVGL

字体库下载:

iconfont-阿里巴巴矢量图标库

下面这个c代码就是转换出来的字体。 

/******************************************************************************** Size: 38 px* Bpp: 1* Opts: --bpp 1 --size 38 --no-compress --font AlimamaShuHeiTi-Bold.ttf --symbols 学习嵌入式的过程是漫长的! --format lvgl -o alimama.c******************************************************************************/#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif#ifndef ALIMAMA
#define ALIMAMA 1
#endif#if ALIMAMA/*-----------------*    BITMAPS*----------------*//*Store the image of the glyphs*/
static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {/* U+0021 "!" */0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xfc, 0x0, 0x0, 0x3,0xff, 0xff, 0xff, 0xff, 0xc0,/* U+4E60 "习" */0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xe0, 0x0, 0x0, 0x7, 0xc0,0x0, 0x0, 0xf, 0x80, 0xfc, 0x0, 0x1f, 0x1,0xf8, 0x0, 0x3e, 0x1, 0xf0, 0x0, 0x7c, 0x3,0xf0, 0x0, 0xf8, 0x3, 0xe0, 0x1, 0xf0, 0x7,0xe0, 0x3, 0xe0, 0xf, 0xc0, 0x7, 0xc0, 0xf,0x80, 0xf, 0x80, 0x1f, 0x80, 0x1f, 0x0, 0x1f,0x0, 0x3e, 0x0, 0x0, 0x8, 0x7c, 0x0, 0x0,0x70, 0xf8, 0x0, 0x7, 0xe1, 0xf0, 0x0, 0x3f,0xc3, 0xe0, 0x3, 0xff, 0x87, 0xc0, 0x1f, 0xff,0xf, 0x81, 0xff, 0xf8, 0x1f, 0xf, 0xff, 0xc0,0x3e, 0x7f, 0xfc, 0x0, 0x7d, 0xff, 0xe0, 0x0,0xfb, 0xfe, 0x0, 0x1, 0xf7, 0xf0, 0x0, 0xff,0xef, 0x0, 0x1, 0xff, 0xd8, 0x0, 0x3, 0xff,0x80, 0x0, 0x7, 0xff, 0x0, 0x0, 0xf, 0xfe,/* U+5165 "入" */0x0, 0xff, 0xf0, 0x0, 0x0, 0x1f, 0xfe, 0x0,0x0, 0x3, 0xff, 0xc0, 0x0, 0x0, 0x7f, 0x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0x0, 0x1,0xc0, 0xf, 0xc0, 0x1, 0xf8, 0x1, 0xf8, 0x1,0xff, 0x0, 0x3f, 0x1, 0xff, 0xe0, 0x7, 0xe3,0xff, 0xfc, 0x0, 0xfc, 0xff, 0xfc, 0x0, 0x1f,0x9f, 0xfc, 0x0, 0x3, 0xf3, 0xfc, 0x0, 0x0,0x7e, 0x7c, 0x0, 0x0, 0xf, 0xc8, 0x0, 0x0,0x1, 0xf8, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0,0x1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf,0xc3, 0xe0, 0x0, 0x1, 0xf8, 0x3e, 0x0, 0x0,0x3f, 0x7, 0xc0, 0x0, 0x7, 0xe0, 0xfc, 0x0,0x0, 0xfc, 0xf, 0x80, 0x0, 0x1f, 0x81, 0xf8,0x0, 0x3, 0xf0, 0x1f, 0x80, 0x0, 0x7e, 0x3,0xf8, 0x0, 0xf, 0xc0, 0x3f, 0x80, 0x1, 0xf8,0x3, 0xfc, 0x0, 0x3f, 0x0, 0x3f, 0xe0, 0x7,0xe0, 0x3, 0xff, 0x80, 0xff, 0xc0, 0x3f, 0xf8,0x1f, 0xf8, 0x3, 0xff, 0x3, 0xff, 0x0, 0x1f,0xe0, 0x7f, 0xe0, 0x0, 0xfc, 0xf, 0xfc, 0x0,0x3, 0x80
};/*---------------------*  GLYPH DESCRIPTION*--------------------*/static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {{.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,{.bitmap_index = 0, .adv_w = 226, .box_w = 6, .box_h = 27, .ofs_x = 4, .ofs_y = 0},{.bitmap_index = 21, .adv_w = 608, .box_w = 31, .box_h = 33, .ofs_x = 3, .ofs_y = -4},{.bitmap_index = 149, .adv_w = 608, .box_w = 35, .box_h = 34, .ofs_x = 1, .ofs_y = -5},{.bitmap_index = 298, .adv_w = 608, .box_w = 34, .box_h = 35, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 447, .adv_w = 608, .box_w = 35, .box_h = 35, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 601, .adv_w = 608, .box_w = 35, .box_h = 35, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 755, .adv_w = 608, .box_w = 34, .box_h = 34, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 900, .adv_w = 608, .box_w = 34, .box_h = 34, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 1045, .adv_w = 608, .box_w = 33, .box_h = 35, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 1190, .adv_w = 608, .box_w = 35, .box_h = 35, .ofs_x = 2, .ofs_y = -4},{.bitmap_index = 1344, .adv_w = 608, .box_w = 35, .box_h = 36, .ofs_x = 1, .ofs_y = -4},{.bitmap_index = 1502, .adv_w = 608, .box_w = 35, .box_h = 35, .ofs_x = 1, .ofs_y = -4}
};/*---------------------*  CHARACTER MAPPING*--------------------*/static const uint16_t unicode_list_0[] = {0x0, 0x4e3f, 0x5144, 0x5b45, 0x5d2b, 0x5eee, 0x660e, 0x6f0a,0x7663, 0x79ea, 0x8fa6, 0x955e
};/*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] =
{{.range_start = 33, .range_length = 38239, .glyph_id_start = 1,.unicode_list = unicode_list_0, .glyph_id_ofs_list = NULL, .list_length = 12, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY}
};/*--------------------*  ALL CUSTOM DATA*--------------------*/#if LVGL_VERSION_MAJOR == 8
/*Store all the custom data of the font*/
static  lv_font_fmt_txt_glyph_cache_t cache;
#endif#if LVGL_VERSION_MAJOR >= 8
static const lv_font_fmt_txt_dsc_t font_dsc = {
#else
static lv_font_fmt_txt_dsc_t font_dsc = {
#endif.glyph_bitmap = glyph_bitmap,.glyph_dsc = glyph_dsc,.cmaps = cmaps,.kern_dsc = NULL,.kern_scale = 0,.cmap_num = 1,.bpp = 1,.kern_classes = 0,.bitmap_format = 0,
#if LVGL_VERSION_MAJOR == 8.cache = &cache
#endif
};/*-----------------*  PUBLIC FONT*----------------*//*Initialize a public general font descriptor*/
#if LVGL_VERSION_MAJOR >= 8
const lv_font_t alimama = {
#else
lv_font_t alimama = {
#endif.get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt,    /*Function pointer to get glyph's data*/.get_glyph_bitmap = lv_font_get_bitmap_fmt_txt,    /*Function pointer to get glyph's bitmap*/.line_height = 37,          /*The maximum line height required by the font*/.base_line = 5,             /*Baseline measured from the bottom of the line*/
#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0).subpx = LV_FONT_SUBPX_NONE,
#endif
#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8.underline_position = -4,.underline_thickness = 2,
#endif.dsc = &font_dsc,          /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
#if LV_VERSION_CHECK(8, 2, 0) || LVGL_VERSION_MAJOR >= 9.fallback = NULL,
#endif.user_data = NULL,
};#endif /*#if ALIMAMA*/

将我们的文字c文件放到工程目录下: 

 在CMakeLists.txtx文件中添加上我们的汉字文件。

1.3.1.5 让文字滚动起来

/*显示中文*/
void demo_Chinese()
{// 0.声明字体LV_FONT_DECLARE(alimama);// 1.得到当前活跃的屏幕lv_obj_t* screen = lv_scr_act();// 2.创建文本对象lv_obj_t* label = lv_label_create(screen);// 3.设置文本对象内容,位置,颜色等等lv_label_set_text(label,"学习嵌入式的过程是漫长的!");// 让文字滚动起来lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);      /*Circular scroll*/lv_obj_set_width(label, 150);      // 设置文字宽度超过多少时候就滚动起来// lv_obj_set_pos(label,100,100);            //设置标签在屏幕上的位置lv_obj_set_align(label,LV_ALIGN_CENTER);  //设置标签位置在屏幕正中央// llv_obj_set_style_text_color(label,lv_color_hex(0x123456),0);   //设置标签中字体颜色lv_obj_set_style_text_color(label,lv_color_make(255,0,0),0);   //设置标签中字体颜色,最后一个参数默认是0// 4.定义一个样式显示标签字体static lv_style_t style;lv_style_init(&style);         //初始化样式结构体lv_style_set_text_font(&style,&alimama);       //设置字体样式// 5.将样式和字体关联起来lv_obj_add_style(label,&style,0);  //最后一个参数默认是0
}

1.3.2 button按钮 

1.3.2.1 button按钮的创建
/*显示按钮*/
void demo_btn()
{// 1.创建一个窗口(屏幕)lv_obj_t* screen = lv_scr_act();// 2.创建按钮对象lv_obj_t* btn = lv_btn_create(screen);// 3.创建样式static lv_style_t style;       // 使用static防止样式被回收lv_style_init(&style);lv_style_set_width(&style,100);lv_style_set_height(&style,60);// 4.将样式和按钮绑定在一起lv_obj_add_style(btn,&style,0);// 5.设置按钮文本lv_obj_t* label = lv_label_create(btn);lv_label_set_text(label,"Button");lv_obj_center(label);            // 让label标签居于btn的中心lv_obj_center(btn);              // 让按钮居于屏幕的中心
}

1.3.2.2 按钮单击事件 
/*按钮单击触发事件*/
void event_handler(lv_event_t* e)
{printf("event_handler\r\n");// 获取事件内容int code = lv_event_get_code(e);   //获取当前事件的编码printf("code:%d clicked:%d\r\n",code,LV_EVENT_CLICKED);// 获取当前事件触发的对象lv_obj_t* obj = lv_event_get_target(e);printf("obj:%d\r\n",obj);// 改变按钮上面的内容if(code == LV_EVENT_CLICKED)        // 如果btn按下{lv_obj_t* label = lv_event_get_user_data(e);lv_label_set_text(label,"handler");}
}/*按钮单击事件*/
void demo_btn_click()
{// 1.创建一个窗口(屏幕)lv_obj_t* screen = lv_scr_act();// 2.创建按钮对象lv_obj_t* btn = lv_btn_create(screen);// 3.创建样式static lv_style_t style;       // 使用static防止样式被回收lv_style_init(&style);lv_style_set_width(&style,100);lv_style_set_height(&style,60);// 4.将样式和按钮绑定在一起lv_obj_add_style(btn,&style,0);// 5.设置按钮文本lv_obj_t* label = lv_label_create(btn);lv_label_set_text(label,"Button");lv_obj_center(label);            // 让label标签居于btn的中心lv_obj_center(btn);              // 让按钮居于屏幕的中心// 6.给按钮添加事件printf("btn:%d\r\n",btn);lv_obj_add_event_cb(btn,event_handler,LV_EVENT_CLICKED,label);   //这里设置了btn按钮单击后触发event_handler事件,并且返回label的地址
}

1.3.2.3  按钮状态可选

/*按钮单击触发事件*/
void event_handler(lv_event_t* e)
{printf("event_handler\r\n");// 获取事件内容int code = lv_event_get_code(e);   //获取当前事件的编码printf("code:%d clicked:%d\r\n",code,LV_EVENT_CLICKED);// 获取当前事件触发的对象lv_obj_t* obj = lv_event_get_target(e);printf("obj:%d\r\n",obj);// 改变按钮上面的内容if(code == LV_EVENT_CLICKED)        // 如果btn按下{lv_obj_t* label = lv_event_get_user_data(e);lv_label_set_text(label,"handler");}else if (code == LV_EVENT_VALUE_CHANGED){lv_obj_t* label = lv_event_get_user_data(e);lv_label_set_text(label,"toggle1");}}/*按钮单击事件*/
void demo_btn_click()
{// 1.创建一个窗口(屏幕)lv_obj_t* screen = lv_scr_act();// 2.创建按钮对象lv_obj_t* btn = lv_btn_create(screen);// 3.创建样式static lv_style_t style;       // 使用static防止样式被回收lv_style_init(&style);lv_style_set_width(&style,100);lv_style_set_height(&style,60);// 4.将样式和按钮绑定在一起lv_obj_add_style(btn,&style,0);// 5.设置按钮文本lv_obj_t* label = lv_label_create(btn);lv_label_set_text(label,"Button");lv_obj_center(label);            // 让label标签居于btn的中心lv_obj_center(btn);              // 让按钮居于屏幕的中心// 6.给按钮添加事件printf("btn:%d\r\n",btn);lv_obj_add_event_cb(btn,event_handler,LV_EVENT_CLICKED,label);   //这里设置了btn按钮单击后触发event_handler事件,并且返回label的地址/*可选中的按钮*/lv_obj_t * btn2 = lv_btn_create(lv_scr_act());lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 80);lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);lv_obj_set_height(btn2, LV_SIZE_CONTENT);lv_obj_add_style(btn2,&style,0);label = lv_label_create(btn2);lv_label_set_text(label, "Toggle");lv_obj_center(label);lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_VALUE_CHANGED, label);
}

1.3.3 Button Matrix按钮矩阵 

1.3.3.1 创建Button Matrix
/*构建按钮矩阵*/
void demo_btn_marix()
{// 1.得到屏幕lv_obj_t* screen = lv_scr_act();// 2.创建按钮矩阵lv_obj_t* btn_matrix = lv_btnmatrix_create(screen); // 3.设置static const char* map[] = {"1","2","3","\n","4","5","6","\n","7","8","9","\n","BACK","0","ENTER",""};// 这里需要使用申请一个static空间,否则会闪退,末尾加一个空字符表示结束lv_btnmatrix_set_map(btn_matrix,map);   // 设置按钮内容// lv_obj_set_width(btn_matrix,200);
}

1.3.3.2 按钮矩阵事件处理
/*按钮矩阵事件*/
void btn_matrix_callback(lv_event_t* e)
{// 获取当前触发的事件编码int code = lv_event_get_code(e);// 获取当前btnmatrixlv_obj_t* btnmatrix = lv_event_get_target(e);if(code == LV_EVENT_VALUE_CHANGED){// 获取当前点击的是哪个按钮uint8_t selected_index = lv_btnmatrix_get_selected_btn(btnmatrix);// 获取按钮对应的文本信息char* text = lv_btnmatrix_get_btn_text(btnmatrix,selected_index);printf("value:%s\r\n",text);}
}/*构建按钮矩阵*/
void demo_btn_marix()
{// 1.得到屏幕lv_obj_t* screen = lv_scr_act();// 2.创建按钮矩阵lv_obj_t* btn_matrix = lv_btnmatrix_create(screen); // 3.设置static const char* map[] = {"1","2","3","\n","4","5","6","\n","7","8","9","\n","BACK","0","ENTER",""};// 这里需要使用申请一个static空间,否则会闪退,末尾加一个空字符表示结束lv_btnmatrix_set_map(btn_matrix,map);   // 设置按钮内容// lv_obj_set_width(btn_matrix,200);lv_obj_center(btn_matrix);             // 居中显示// 4.添加事件lv_obj_add_event_cb(btn_matrix,btn_matrix_callback,LV_EVENT_VALUE_CHANGED,NULL);
}

1.3.4 Text aera文本框 

/*文本输入框事件*/
static void textarea_event_handler(lv_event_t * e)
{lv_obj_t * ta = lv_event_get_target(e);LV_UNUSED(ta);LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta));
}static void btnm_event_handler(lv_event_t * e)
{lv_obj_t * obj = lv_event_get_target(e);lv_obj_t * ta = lv_event_get_user_data(e);const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta);else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_event_send(ta, LV_EVENT_READY, NULL);else lv_textarea_add_text(ta, txt);}/*构建文本输入框*/
void demo_textaera()
{// 1.显示对象lv_obj_t* screen = lv_scr_act();// 2.创建要显示的对象lv_obj_t * ta = lv_textarea_create(screen);// 3.对显示的对象进行测试lv_textarea_set_one_line(ta, true);    // 设置只显示一行lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);lv_obj_add_event_cb(ta, textarea_event_handler, LV_EVENT_READY, ta);lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/static const char * btnm_map[] = {"1", "2", "3", "\n","4", "5", "6", "\n","7", "8", "9", "\n",LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""};lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());lv_obj_set_size(btnm, 200, 150);lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);lv_obj_add_event_cb(btnm, btnm_event_handler, LV_EVENT_VALUE_CHANGED, ta);lv_obj_clear_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/lv_btnmatrix_set_map(btnm, btnm_map);
}

1.3.5 显示Image 

对图片对象进行编码:

Image Converter — LVGL

将转换好的c文件添加进CMakeLists.txt中。 

图片转码之后的信息: 

/*显示图片*/
void dmeo_img()
{// 1.显示对象lv_obj_t* screen = lv_scr_act();// 2.创建图片对象lv_obj_t* img = lv_img_create(screen);// 3.给图片对象设置图片LV_IMG_DECLARE(J20);    // 声明图片lv_img_set_src(img,&J20);lv_obj_align(img,LV_ALIGN_CENTER,0,0);       // 图片居中显示
}

1.3.6 显示gif

将转换好的c文件添加进CMakeLists.txt中。

  不显示gif的解决办法:

【LVGL】LVGL8.1 使用GIF库_单片机_mainy4210-GitCode 开源社区 (csdn.net)

/*显示gif*/
void demo_gif()
{LV_IMG_DECLARE(astro);    // 声明图片// 1.显示对象lv_obj_t* screen = lv_scr_act();// 2.创建图片对象lv_obj_t* gif = lv_gif_create(screen);// 3.给图片对象设置图片 lv_gif_set_src(gif,&astro);lv_obj_align(gif,LV_ALIGN_CENTER,0,0);       // 图片居中显示
}

1.4 布局 

1.4.1  Flex弹性布局

/*弹性布局*/
void flex_1(void)
{/*Create a container with ROW flex direction*/lv_obj_t * cont_row = lv_obj_create(lv_scr_act());lv_obj_set_size(cont_row, 240, 75);lv_obj_align(cont_row, LV_ALIGN_TOP_MID, 0, 5);lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);/*Create a container with COLUMN flex direction*/lv_obj_t * cont_col = lv_obj_create(lv_scr_act());lv_obj_set_size(cont_col, 200, 200);lv_obj_align_to(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);lv_obj_set_flex_flow(cont_col, LV_FLEX_FLOW_COLUMN);uint32_t i;for(i = 0; i < 10; i++) {lv_obj_t * obj;lv_obj_t * label;/*Add items to the row*/obj= lv_btn_create(cont_row);lv_obj_set_size(obj, 100, LV_PCT(100));label = lv_label_create(obj);lv_label_set_text_fmt(label, "Item: %u", i);lv_obj_center(label);/*Add items to the column*/obj = lv_btn_create(cont_col);lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);label = lv_label_create(obj);lv_label_set_text_fmt(label, "Item: %"LV_PRIu32, i);lv_obj_center(label);}
}

1.4.2 Grid网格布局 

void grid_1(void)
{static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};static lv_coord_t row_dsc[] = {50, 50, 50, LV_GRID_TEMPLATE_LAST};/**60	60	60505050*//*Create a container with grid*/lv_obj_t * cont = lv_obj_create(lv_scr_act());lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);lv_obj_set_size(cont, 220, 280);lv_obj_center(cont);lv_obj_set_layout(cont, LV_LAYOUT_GRID);lv_obj_t * label;lv_obj_t * obj;uint32_t i;for(i = 0; i < 9; i++) {uint8_t col = i % 3;uint8_t row = i / 3;obj = lv_btn_create(cont);/*Stretch the cell horizontally and vertically too*Set span to 1 to make the cell 1 column/row sized*/lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1,LV_GRID_ALIGN_STRETCH, row, 1);label = lv_label_create(obj);lv_label_set_text_fmt(label, "c%d, r%d", col, row);lv_obj_center(label);}
}

1.5 界面切换

/*页面切换*/
lv_obj_t* page1;
lv_obj_t* page2;void enent_handler_page(lv_event_t* e)
{int code = lv_event_get_code(e);if(code == LV_EVENT_CLICKED){//获取用户传递的数据uint8_t index = lv_event_get_user_data(e);switch (index){case 1:lv_disp_load_scr(page2);         //跳转到page2break;case 2:lv_disp_load_scr(page1);         //跳转到page1break;}}
}void create_page1()
{//创建一个页面page1 = lv_obj_create(NULL);lv_obj_t* obj = lv_obj_create(page1);   //在page1上创建一个对象//显示一些内容static lv_style_t style;lv_style_init(&style);lv_style_set_width(&style,100);lv_style_set_height(&style,100);lv_style_set_bg_color(&style,lv_palette_main(LV_PALETTE_RED));lv_obj_add_style(obj,&style,0);//添加显示文本lv_obj_t* label1 = lv_label_create(obj);lv_label_set_text(label1,"PAGE111");lv_obj_set_align(label1,LV_ALIGN_CENTER);//添加单击事件实现page1上点击按钮跳转到page2lv_obj_add_event_cb(obj,enent_handler_page,LV_EVENT_CLICKED,1);
}void create_page2()
{//创建一个页面page2 = lv_obj_create(NULL);lv_obj_t* obj = lv_obj_create(page2);   //在page1上创建一个对象//显示一些内容static lv_style_t style;lv_style_init(&style);lv_style_set_width(&style,100);lv_style_set_height(&style,100);lv_style_set_bg_color(&style,lv_palette_main(LV_PALETTE_BLUE));lv_obj_add_style(obj,&style,0);//添加显示文本lv_obj_t* label2 = lv_label_create(obj);lv_label_set_text(label2,"PAGE222");lv_obj_set_align(label2,LV_ALIGN_CENTER);lv_obj_add_event_cb(obj,enent_handler_page,LV_EVENT_CLICKED,2);
}

在main函数里要先加载一个默认页面:

 create_page1();create_page2();lv_disp_load_scr(page1);        //默认程序执行显示page1

1.6 Tabview

void demo_tabivew()
{lv_obj_t * tabview;tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50);/*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/lv_obj_t * tab1 = lv_tabview_add_tab(tabview, "Tab 1");lv_obj_t * tab2 = lv_tabview_add_tab(tabview, "Tab 2");lv_obj_t * tab3 = lv_tabview_add_tab(tabview, "Tab 3");/*Add content to the tabs*/lv_obj_t * label = lv_label_create(tab1);lv_label_set_text(label, "This the first tab\n\n""If the content\n""of a tab\n""becomes too\n""longer\n""than the\n""container\n""then it\n""automatically\n""becomes\n""scrollable.\n""\n""\n""\n""Can you see it?");label = lv_label_create(tab2);lv_label_set_text(label, "Second tab");label = lv_label_create(tab3);lv_label_set_text(label, "Third tab");lv_obj_scroll_to_view_recursive(label, LV_ANIM_ON);
}

1.7 如何学习官网案例

对于条件编译的案例:

在"lv_conf.h"里找到对应部分置1,就可以使用了。 

1.8 修改屏幕大小

1.9 动态的显示表格数据

lv_obj_t * chart;
lv_chart_series_t * ser1;
void demo_chart()
{/*Create a chart*/chart = lv_chart_create(lv_scr_act());lv_obj_set_size(chart, 200, 150);lv_obj_center(chart);lv_chart_set_type(chart, LV_CHART_TYPE_LINE);   /*Show lines and points too*//*Add two data series*/ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_SECONDARY_Y);/*Set the next points on 'ser1'*/lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 10);lv_chart_set_next_value(chart, ser1, 30);lv_chart_set_next_value(chart, ser1, 70);lv_chart_set_next_value(chart, ser1, 90);lv_chart_refresh(chart); /*Required after direct set*/
}

count += 5;if(count/1000 == 0){lv_chart_set_next_value(chart,ser1,lv_rand(50,100));lv_chart_refresh(chart);count = 0;}

02 SquareLine Studio

2.1 SquareLine Studio创建UI

注:SquareLine Studio里设置角度的时候需要在常规认知度数上乘以10倍,比如我想旋转某个图片30°,在设置的时候写300。

 这里显示了这个项目中使用的资源,直接使用文件查找工具找到这些资源拷贝下来自己使用。

参照案例创作好我们的表盘后,导出成为LVGL工程:

将我们导出的UI复制进LVGL工程里:

 2.2 将UI配置进LVGL工程中

#  define SDL_HOR_RES     392
#  define SDL_VER_RES     392

#define LV_COLOR_DEPTH 16           #define LV_COLOR_16_SWAP 1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/425154.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java实现系统文件管理

java实现系统文件管理 环境&#xff1a;jdk17springbootVueElementUI 背景&#xff1a;公司所做的项目需要别的系统向我们服务器上传文件&#xff0c;当我们需要查看这些文件什么时候上传的、文件数据是怎样的&#xff0c;只能去机房&#xff0c;排查问题效率较低&#xff0c;…

【VitualBox】VitualBox的网络模式+网络配置

VirtualBox 1. 简介 VirtualBox 是一款开源虚拟机软件&#xff0c;使用者可以在VirtualBox上安装并且执行Solaris、Windows、DOS、Linux、OS/2 Warp、BSD等系统作为客户端操作系统。 2. 六种网络接入模式 VirtualBox提供了多种网络接入模式&#xff0c;他们各有优缺点&#xf…

Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取相机当前数据吞吐量(Python)

Baumer工业相机堡盟工业相机如何通过NEOAPI SDK里函数来获取相机当前数据吞吐量&#xff08;Python&#xff09; Baumer工业相机Baumer工业相机的数据吞吐量的技术背景CameraExplorer如何查看相机吞吐量信息在NEOAPI SDK里通过函数获取相机接口吞吐量 Baumer工业相机通过NEOAPI…

移情别恋c++ ദ്ദി˶ー̀֊ー́ ) ——13.mapset

1. 关联式容器 在初阶阶段&#xff0c;我们已经接触过STL中的部分容器&#xff0c;比如&#xff1a;vector、list、deque、 forward_list(C11)等&#xff0c;这些容器统称为序列式容器&#xff0c;因为其底层为线性序列的数据结构&#xff0c;里面 存储的是元素本身。那什么是关…

【与C++的邂逅】--- 类和对象(上)

Welcome to 9ilks Code World (๑•́ ₃ •̀๑) 个人主页: 9ilk (๑•́ ₃ •̀๑) 文章专栏&#xff1a; 与C的邂逅 本篇博客将讲解C中的类和对象&#xff0c;C是面向对象的语言&#xff0c;面向对象三大特性是封装,继承,多态。学习类和对象&#xff0c;我们可…

【C语言】深入讲解指针(中)

文章目录 前言函数指针函数指针变量的创建函数指针变量的使用两段有趣的代码typedef 关键字 函数指针数组函数指针的使用最后 前言 上一章深入讲解指针&#xff08;上&#xff09;我们对字符指针、数组指针、指针和数组传参进行了讲解&#xff0c;本章将对函数指针进行讲解&am…

【Python】标准库的使用

文章目录 标准库日期计算字符串操作剑指offer 58&#xff0c;翻转单词顺序思路 leetcode 796&#xff0c;旋转字符串思路 leetcode 2255&#xff0c;统计是给定字符串前缀的字符串数目思路 文件查找工具 Python 通过模块来体现“库” 降低了程序猿的学习成本提高了程序的开发效…

【C语言篇】编译和链接以及预处理介绍(下篇)

文章目录 前言#和###运算符##运算符 命名约定#undef命令⾏定义条件编译#if和#endif多个分支的条件编译判断是否被定义嵌套指令 头文件被包含头文件被包含的方式本地文件包含库文件的包含 嵌套文件包含 其他预处理指令 写在最后 前言 本篇接前一篇【C语言篇】编译和链接以及预处…

【LeetCode】每日一题 2024_9_16 公交站间的距离(模拟)

前言 每天和你一起刷 LeetCode 每日一题~ LeetCode 启动&#xff01; 题目&#xff1a;公交站间的距离 代码与解题思路 func distanceBetweenBusStops(distance []int, start int, destination int) int {// 首先让 start > destination, 这两个谁大对结果没有影响&#…

免费爬虫软件“HyperlinkCollector超链采集器v0.1”

HyperlinkCollector超链采集器单机版v0.1 软件采用python的pyside2和selenium开发,暂时只支持window环境&#xff0c;抓取方式支持普通程序抓取和selenium模拟浏览器抓取。软件遵守robots协议。 首先下载后解压缩&#xff0c;然后运行app目录下的HyperlinkCollector.exe 运行…

C语言——rand函数

一、rand函数 这是一个在 C 标准库 <stdlib.h> 中定义的函数&#xff0c;用于生成伪随机数&#xff0c;默认情况下&#xff0c;它生成从 0 到 RAND_MAX 的伪随机数&#xff0c;其中 RAND_MAX 是一个常数&#xff0c;通常是 32767。 1、函数原型&#xff1a; 2、函数返回…

【数据结构】排序算法---直接插入排序

文章目录 1. 定义2. 算法步骤3. 动图演示4. 性质5. 算法分析6. 代码实现C语言PythonJavaCGo 7. 折半插入排序代码实现——C 结语 1. 定义 直接插入排序是一种简单直观的排序算法。它的工作原理为将待排列元素划分为「已排序」和「未排序」两部分&#xff0c;每次从「未排序的」…

C++ char*和char[] 可能指向的内存区域详解(附实验)

C char* 指向的内存区域详解 写在前面c内存结构简介指针常量和常量指针简介情况一&#xff1a;char* 指向栈区内容情况二&#xff1a;char* 指向堆区内容情况三&#xff1a;char* 指向常量区内容情况四&#xff1a;char* 指向静态区内容情况五&#xff1a;char* 指向全局区内容…

SQL题目分析:打折日期交叉问题--计算品牌总优惠天数

在电商平台的数据分析中&#xff0c;处理品牌促销活动的日期交叉问题是一个挑战。本文将介绍几种高级SQL技巧&#xff0c;用于准确计算每个品牌的总优惠天数&#xff0c;即使在存在日期交叉的情况下。 问题背景 我们有一个促销活动表 shop_discount&#xff0c;记录了不同品牌…

docker-compose 部署 flink

下载 flink 镜像 [rootlocalhost ~]# docker pull flink Using default tag: latest latest: Pulling from library/flink 762bedf4b1b7: Pull complete 95f9bd9906fa: Pull complete a880dee0d8e9: Pull complete 8c5deab9cbd6: Pull complete 56c142282fae: Pull comple…

【二叉树进阶】二叉搜索树

目录 1. 二叉搜索树概念 2. 二叉搜索树的实现 2.1 创建二叉搜索树节点 2.2 创建实现二叉搜索树 2.3 二叉搜索树的查找 2.4 二叉搜索树的插入 2.5 二叉搜索树的删除 2.6 中序遍历 2.7 完整代码加测试 3. 二叉搜索树的应用 3.1 K模型&#xff1a; 3.2 KV模型&#xf…

【C++11】可变参数模板

【C11】可变参数模板 一、可变参数模板概念以及定义方式 ​ 在C11之前&#xff0c;类模板和函数模板只能含有固定数量的模板参数&#xff0c;c11增加了可变模板参数特性&#xff1a;允许模板定义中包含0到任意个模板参数。声明可变参数模板时&#xff0c;需要在typename或cla…

数据在内存中的存储方式

前言&#xff1a;已经好久没更新了&#xff0c;开学之后学习编程的时间少了很多。因此&#xff0c;已经好几个礼拜都没有写文章了。 在讲解操作符的时候&#xff0c;我们就已经学习过了整数在内存中的存储方式。若有不懂的伙伴可以前往操作符详解进行学习。今天我们主要来学习…

[数据集][目标检测]智慧交通铁路人员危险行为躺站坐检测数据集VOC+YOLO格式3766张4类别

图片数量(jpg文件个数)&#xff1a;3766 标注数量(xml文件个数)&#xff1a;3766 标注数量(txt文件个数)&#xff1a;3766 标注类别数&#xff1a;4 标注类别名称:["sitting","sleeping","standing","track"] 每个类别标注的框数&…

NC 矩阵最长递增路径

系列文章目录 文章目录 系列文章目录前言 前言 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站&#xff0c;这篇文章男女通用&#xff0c;看懂了就去分享给你的码吧。 描述 给定一个 n 行…