ARC样式修改线条颜色
定义背景样式
static lv_style_t style_bg;
lv_style_reset(&style_bg);
lv_style_init(&style_bg);
lv_style_set_bg_opa(&style_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_border_opa(&style_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_line_color(&style_bg, LV_STATE_DEFAULT, LV_COLOR_MAKE(255, 0, 0));
lv_style_set_line_width(&style_bg, LV_STATE_DEFAULT, 9);
定义线条样式
static lv_style_t style_blue;
lv_style_reset(&style_blue);
lv_style_init(&style_blue);
lv_style_set_line_color(&style_blue, LV_STATE_DEFAULT, LV_COLOR_MAKE(0, 0, 255));
lv_style_set_line_width(&style_blue, LV_STATE_DEFAULT, 9);
绘制并加载黑色屏幕
lv_obj_t* scr = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(scr, 390, 390);
lv_obj_set_style_local_bg_color(scr, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_border_opa(scr, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
绘制ARC
/*Create an Arc_blue*/
lv_obj_t* arc_blue = lv_arc_create(scr, NULL);
lv_obj_add_style(arc_blue, LV_ARC_PART_BG, &style_bg);
lv_arc_set_bg_angles(arc_blue, 228, 312); //clear background arc
lv_obj_set_size(arc_blue, 380, 380); //set size of weight
lv_obj_align(arc_blue, NULL, LV_ALIGN_CENTER, 0, 0);
lv_arc_set_angles(arc_blue, 228, 270);
lv_obj_add_style(arc_blue, LV_ARC_PART_BG, &style_bg);
lv_obj_add_style(arc_blue, LV_ARC_PART_INDIC, &style_blue);
完整的绘制ARC样式函数如下
void arc_test(void)
{
//background style
static lv_style_t style_bg;
lv_style_reset(&style_bg);
lv_style_init(&style_bg);
lv_style_set_bg_opa(&style_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_border_opa(&style_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_line_color(&style_bg, LV_STATE_DEFAULT, LV_COLOR_MAKE(255, 0, 0));
lv_style_set_line_width(&style_bg, LV_STATE_DEFAULT, 9);
//line style_blue
static lv_style_t style_blue;
lv_style_reset(&style_blue);
lv_style_init(&style_blue);
lv_style_set_line_color(&style_blue, LV_STATE_DEFAULT, LV_COLOR_MAKE(0, 0, 255));
lv_style_set_line_width(&style_blue, LV_STATE_DEFAULT, 9);
//draw background
lv_obj_t* scr = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(scr, 390, 390);
lv_obj_set_style_local_bg_color(scr, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_border_opa(scr, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
/*Create an Arc_blue*/
lv_obj_t* arc_blue = lv_arc_create(scr, NULL);
lv_obj_add_style(arc_blue, LV_ARC_PART_BG, &style_bg);
lv_arc_set_bg_angles(arc_blue, 228, 312); //clear background arc
lv_obj_set_size(arc_blue, 380, 380); //set size of weight
lv_obj_align(arc_blue, NULL, LV_ALIGN_CENTER, 0, 0);
lv_arc_set_angles(arc_blue, 228, 270);
lv_obj_add_style(arc_blue, LV_ARC_PART_BG, &style_bg);
lv_obj_add_style(arc_blue, LV_ARC_PART_INDIC, &style_blue);
}
在main函数中调用arc_test()函数,并运行,运行效果图如下