这一期讲解的控件是进度条文本控件,textprogress是 LVGL 库中的一个组件,用于显示进度文本的控件。
如上图所示,在GUI_guider中进度文本控件的使用,将控件拖拽到画布中,然后在右侧的属性列表中更改配置,进度文本的数值范围、数值的步数以及进度文本的初始值和位数显示。
下图是根据右侧属性列表配置得到的。
以下是代码的实例解析:
//Write codes screen_1_textprogress_1
//创建控件
ui->screen_1_textprogress_1 = lv_textprogress_create(ui->screen_1);
//设置进度文本的数值范围
lv_textprogress_set_range_value(ui->screen_1_textprogress_1, 0, 100, 0, 0);
//设置两位有效数字显示
lv_textprogress_set_decimal(ui->screen_1_textprogress_1, 2);
//设置初始值为0
lv_textprogress_set_value(ui->screen_1_textprogress_1, 0);
//设置位置以及大小
lv_obj_set_pos(ui->screen_1_textprogress_1, 185, 209);
lv_obj_set_size(ui->screen_1_textprogress_1, 100, 32);
//Write style for screen_1_textprogress_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT. //设置边框半径:0(直角矩形)lv_obj_set_style_radius(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
//文本颜色:黑色(#000000)
lv_obj_set_style_text_color(ui->screen_1_textprogress_1, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
//字体:Alatsi Regular ,大小22
lv_obj_set_style_text_font(ui->screen_1_textprogress_1, &lv_font_Alatsi_Regular_22, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui->screen_1_textprogress_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
//字母间距:2px
lv_obj_set_style_text_letter_space(ui->screen_1_textprogress_1, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
//文本对齐:居中
lv_obj_set_style_text_align(ui->screen_1_textprogress_1, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(ui->screen_1_textprogress_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
//背景颜色:白色(#FFFFFF)
lv_obj_set_style_bg_color(ui->screen_1_textprogress_1, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_bg_grad_dir(ui->screen_1_textprogress_1, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);
//顶部内边距:8px 其他三边内边距:0
lv_obj_set_style_pad_top(ui->screen_1_textprogress_1, 8, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_pad_right(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_pad_bottom(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_pad_left(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
//阴影宽度:1px
lv_obj_set_style_shadow_width(ui->screen_1_textprogress_1, 1, LV_PART_MAIN|LV_STATE_DEFAULT);
//阴影颜色:黑色
lv_obj_set_style_shadow_color(ui->screen_1_textprogress_1, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_shadow_opa(ui->screen_1_textprogress_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
//阴影扩散:2px
lv_obj_set_style_shadow_spread(ui->screen_1_textprogress_1, 2, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_shadow_ofs_x(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_shadow_ofs_y(ui->screen_1_textprogress_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
本文章由威三学社出品
对课程感兴趣可以私信联系