创建style
- 初时化style
static lv_style_t style;
lv_style_init(&style);
- 设置线的颜色为灰色
lv_style_set_line_color(&style, lv_palette_main(LV_PALETTE_GREY));
- 设置线宽为8
lv_style_set_line_width(&style, 8);
- 设置线端倒圆角
lv_style_set_line_rounded(&style, true);
- 创建obj对象
lv_obj_t* obj = lv_line_create(lv_scr_act());
- obj对象加入style
lv_obj_add_style(obj, &style, 0);
- 定义3个坐标点
static lv_point_t p[] = { {10, 30}, {30, 50}, {100, 0} };
- obj对角上绘制线条
lv_line_set_points(obj, p, 3);
- 居中显示
lv_obj_center(obj);
完整代码,仅供参考
static void lv_example_style_9(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_line_color(&style, lv_palette_main(LV_PALETTE_GREY));
lv_style_set_line_width(&style, 8);
lv_style_set_line_rounded(&style, true);
/*Create an object with the new style*/
lv_obj_t* obj = lv_line_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
static lv_point_t p[] = { {10, 30}, {30, 50}, {100, 0} };
lv_line_set_points(obj, p, 3);
lv_obj_center(obj);
}
调用lv_example_style_9运行效果
- 修改线条style颜色为红色
lv_style_set_line_color(&style, lv_palette_main(LV_PALETTE_RED));
- 效果图
- 修改线端不导圆角
lv_style_set_line_rounded(&style, false);
- 效果图