线(lv_line)

概述

Line对象能够在一组点之间绘制直线。

零件和样式

生产线只有一个主要部分,称为 LV_LABEL_PART_MAIN 。它使用所有线型属性。

用法

设置点

这些点必须存储在 lv_point_t 数组中,并通过 lv_line_set_points(lines, point_array, point_cnt) 函数传递给对象。

自动大小

可以根据其点自动设置线对象的大小。可以使用 lv_line_set_auto_size(line, true) 函数启用它。如果启用,则在设置点后,将根据点之间的最大x和y坐标更改对象的宽度和高度。默认情况下,自动尺寸已启用。

倒y

通过默认,y == 0点位于对象的顶部。在某些情况下可能是直觉的,因此可以使用 lv_line_set_y_invert(line, true) 反转y坐标。在这种情况下,y == 0将是对象的底部。默认情况下,禁用y反转。

事件

仅支持 通用事件

了解有关 事件 的更多内容。

按键处理

对象类型不处理任何键。

了解有关 按键 的更多内容。

范例

简单线

http://photos.100ask.net/lvgl/04_widgets/19_line/01_lv_ex_line_1.png

简单线

上述效果的示例代码:

 1    #include "../../../lv_examples.h"
 2    #if LV_USE_LINE
 3
 4    void lv_ex_line_1(void)
 5    {
 6            /*Create an array for the points of the line*/
 7            static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };
 8
 9            /*Create style*/
10            static lv_style_t style_line;
11            lv_style_init(&style_line);
12            lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 8);
13            lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, LV_COLOR_BLUE);
14            lv_style_set_line_rounded(&style_line, LV_STATE_DEFAULT, true);
15
16            /*Create a line and apply the new style*/
17            lv_obj_t * line1;
18            line1 = lv_line_create(lv_scr_act(), NULL);
19            lv_line_set_points(line1, line_points, 5);     /*Set the points*/
20            lv_obj_add_style(line1, LV_LINE_PART_MAIN, &style_line);     /*Set the points*/
21            lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0);
22    }
23
24    #endif

相关API

TODO