Line (lv_line)¶
Overview¶
The Line Widget is capable of drawing straight lines between a set of points.
Parts and Styles¶
LV_PART_MAIN
uses the typical background and line style properties.
Usage¶
Set points¶
A Line's 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.
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 Widget. 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 at the bottom of the Widget. y invert is disabled by default.
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.
Keys¶
No Keys are processed by Line Widgets.
Further Reading
Learn more about Keys.
Example¶
Simple Line¶
C 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_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