Line (lv_line)¶
Overview¶
The Line object is capable of drawing straight lines between a set of points.
Parts and Styles¶
LV_PART_MAIN
uses all the typical background properties and line style properties.
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.
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.
Invert 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.
Example¶
C¶
Simple Line¶
code view on 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¶
No examples yet.
API¶
Functions
-
lv_obj_t *lv_line_create(lv_obj_t *parent)¶
Create a line objects
- Parameters
par -- pointer to an object, it will be the parent of the new line
- Returns
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.
- Parameters
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.
- Parameters
obj -- pointer to a line object
en -- true: enable the y inversion, false:disable the y inversion
Variables
-
const lv_obj_class_t lv_line_class¶
-
struct lv_line_t¶