Line(线条) (lv_line)

Overview(概述)

查看原文

The Line object is capable of drawing straight lines between a set of points.

线条(Line)组件能在给出的一组点之间绘制出相连的直线。

Parts and Styles(零件和样式)

查看原文

  • LV_PART_MAIN uses all the typical background properties and line style properties.

  • LV_PART_MAIN 使用所有典型的背景属性和线条样式属性。

Usage(用法)

Set points(设置点)

查看原文

The points have to be stored in an lv_point_t array and passed to the object by the lv_line_set_points(lines, point_array, point_cnt) function.

点必须存储在 lv_point_t 类型的数组中,并通过 lv_line_set_points(lines, point_array, point_cnt) 函数将数组传递给line对象。

Auto-size(自动调整大小)

查看原文

By default the Line's width and height are set to LV_SIZE_CONTENT. This means it will automatically set its size to fit all the points. If the size is set explicitly, parts on the line may not be visible.

默认情况下,线条的宽度和高度被设置为 LV_SIZE_CONTENT 。也就是它会根据给出的点自动调整其大小来适应所有点的分布。如果你设置了宽、高,那么线条上的有些部分可能会不可见。

Invert y(反转 y轴)

查看原文

By default, the y == 0 point is in the top of the object. It might be conter-intuitive in some cases so the y coordinates can be inverted with lv_line_set_y_invert(line, true). In this case, y == 0 will be the bottom of the object. y invert is disabled by default.

默认情况下,y == 0 点是在line对象的顶部最左侧。这在某些情况下可能是不直观的(LCD坐标系),这时候可以使用 lv_line_set_y_invert(line, true) 函数来反转 y 坐标。在这种情况下,y == 0 将是物体的底部最左侧(直角坐标系)。

默认不反转y轴。

Events(事件)

查看原文

Only the Generic events are sent by the object type.

See the events of the Base object too.

Learn more about Events.

线条对象仅发送 通用事件

参见 Base object 的事件。

详细了解 事件

Keys(按键)

查看原文

No Keys are processed by the object type.

Learn more about Keys.

线条对象不响应处理按键(以及触摸)。

了解有关 的更多信息。

Example

Simple Line

C code  

 GitHub
#include "../../lv_examples.h"
#if LV_USE_LINE && LV_BUILD_EXAMPLES

void lv_example_line_1(void)
{
    /*Create an array for the points of the line*/
    static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };

    /*Create style*/
    static lv_style_t style_line;
    lv_style_init(&style_line);
    lv_style_set_line_width(&style_line, 8);
    lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));
    lv_style_set_line_rounded(&style_line, true);

    /*Create a line and apply the new style*/
    lv_obj_t * line1;
    line1 = lv_line_create(lv_scr_act());
    lv_line_set_points(line1, line_points, 5);     /*Set the points*/
    lv_obj_add_style(line1, &style_line, 0);
    lv_obj_center(line1);
}

#endif

MicroPython code  

 GitHub Simulator
# Create an array for the points of the line
line_points = [ {"x":5, "y":5}, 
                {"x":70, "y":70}, 
                {"x":120, "y":10}, 
                {"x":180, "y":60}, 
                {"x":240, "y":10}]

# Create style
style_line = lv.style_t()
style_line.init()
style_line.set_line_width(8)
style_line.set_line_color(lv.palette_main(lv.PALETTE.BLUE))
style_line.set_line_rounded(True)

# Create a line and apply the new style
line1 = lv.line(lv.scr_act())
line1.set_points(line_points, 5)     # Set the points
line1.add_style(style_line, 0)
line1.center()


API

Functions

lv_obj_t *lv_line_create(lv_obj_t *parent)

Create a line object

参数

parent -- pointer to an object, it will be the parent of the new line

返回

pointer to the created line

void lv_line_set_points(lv_obj_t *obj, const lv_point_t points[], uint16_t point_num)

Set an array of points. The line object will connect these points.

参数
  • obj -- pointer to a line object

  • points -- an array of points. Only the address is saved, so the array needs to be alive while the line exists

  • point_num -- number of points in 'point_a'

void lv_line_set_y_invert(lv_obj_t *obj, bool en)

Enable (or disable) the y coordinate inversion. If enabled then y will be subtracted from the height of the object, therefore the y = 0 coordinate will be on the bottom.

参数
  • obj -- pointer to a line object

  • en -- true: enable the y inversion, false:disable the y inversion

bool lv_line_get_y_invert(const lv_obj_t *obj)

Get the y inversion attribute

参数

obj -- pointer to a line object

返回

true: y inversion is enabled, false: disabled

Variables

const lv_obj_class_t lv_line_class
struct lv_line_t

Public Members

lv_obj_t obj
const lv_point_t *point_array

Pointer to an array with the points of the line

uint16_t point_num

Number of points in 'point_array'

uint8_t y_inv

1: y == 0 will be on the bottom