Line (线条)(lv_line)

Overview(概述)

显示原文

The Line Widget 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_precise_t array and passed to the Widget by the lv_line_set_points(lines, point_array, point_cnt) function.

Their coordinates can either be specified as raw pixel coordinates (e.g. {5, 10}), or as a percentage of the Line's bounding box using lv_pct(x). In the latter case, the Line's width/height may need to be set explicitly using lv_obj_set_width() and lv_obj_set_height(), as percentage values do not automatically expand the bounding box.


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

它们的坐标既可以指定为原始像素坐标(例如 {5, 10}),也可以使用 :cpp:expr:`lv_pct(x)`指定为相对于线条边界框的百分比。在后一种情况下,可能需要使用 :cpp:func:`lv_obj_set_width`和 :cpp:func:`lv_obj_set_height`显式地设置线条的宽度 / 高度,因为百分比值不会自动扩展边界框。

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 counter-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 generic events are sent by Line Widgets.

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events(事件).


线性部件仅发送 generic events

进一步了解所有部件发出的 Base-Widget Events

进一步了解 Events(事件)

Keys(按键)

显示原文

No Keys are processed by Line Widgets.

Learn more about Keys(按键).


线性部件不处理任何*按键*。

了解有关 Keys(按键) 的更多信息。

Example

Simple Line

#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_precise_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_screen_active());
    lv_line_set_points(line1, line_points, 5);     /*Set the points*/
    lv_obj_add_style(line1, &style_line, 0);
    lv_obj_center(line1);
}

#endif

API

lv_line.h

lv_types.h