Line (lv_line)

Overview

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

Set points

The points has 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

It is possible to automatically set the size of the line object according to its points. You can enable it with the lv_line_set_auto_size(line, true) function. If enabled then when the points are set the object’s width and height will be changed according to the maximal x and y coordinates among the points. The auto size is enabled by default.

Invert y

By deafult, the y == 0 point is in the top of the object but you can invert the y coordinates with lv_line_set_y_invert(line, true). The y invert is disabled by default.

Styles

The Line uses one style which can be set by lv_line_set_style(led, LV_LINE_STYLE_MAIN, &style) and it uses all style.line properties.

Events

Only the Generic events are sent by the object type.

Learn more about Events.

Keys

No Keys are processed by the object type.

Learn more about Keys.

Example

C

Simple Line

Line example in LittlevGL

code

#include "lvgl/lvgl.h"

void lv_ex_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 new style (thick dark blue)*/
    static lv_style_t style_line;
    lv_style_copy(&style_line, &lv_style_plain);
    style_line.line.color = LV_COLOR_MAKE(0x00, 0x3b, 0x75);
    style_line.line.width = 3;
    style_line.line.rounded = 1;

    /*Copy the previous line and apply the new style*/
    lv_obj_t * line1;
    line1 = lv_line_create(lv_scr_act(), NULL);
    lv_line_set_points(line1, line_points, 5);     /*Set the points*/
    lv_line_set_style(line1, LV_LINE_STYLE_MAIN, &style_line);
    lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0);
}

MicroPython

Simple Line

Line example in LittlevGL with MicroPython

code

# 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 new style (thick dark blue)
style_line = lv.style_t()
lv.style_copy(style_line, lv.style_plain)
style_line.line.color = lv.color_make(0x00, 0x3b, 0x75)
style_line.line.width = 3
style_line.line.rounded = 1

# Copy the previous line and apply the new style
line1 = lv.line(lv.scr_act())
line1.set_points(line_points, len(line_points))      # Set the points
line1.set_style(lv.line.STYLE.MAIN, style_line)
line1.align(None, lv.ALIGN.CENTER, 0, 0)

API

Typedefs

typedef uint8_t lv_line_style_t

Enums

enum [anonymous]

Values:

LV_LINE_STYLE_MAIN

Functions

lv_obj_t *lv_line_create(lv_obj_t *par, const lv_obj_t *copy)

Create a line objects

Return

pointer to the created line

Parameters
  • par: pointer to an object, it will be the parent of the new line

void lv_line_set_points(lv_obj_t *line, const lv_point_t point_a[], uint16_t point_num)

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

Parameters
  • line: pointer to a line object

  • point_a: an array of points. Only the address is saved, so the array can NOT be a local variable which will be destroyed

  • point_num: number of points in ‘point_a’

void lv_line_set_auto_size(lv_obj_t *line, bool en)

Enable (or disable) the auto-size option. The size of the object will fit to its points. (set width to x max and height to y max)

Parameters
  • line: pointer to a line object

  • en: true: auto size is enabled, false: auto size is disabled

void lv_line_set_y_invert(lv_obj_t *line, 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
  • line: pointer to a line object

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

static void lv_line_set_style(lv_obj_t *line, lv_line_style_t type, const lv_style_t *style)

Set the style of a line

Parameters
  • line: pointer to a line object

  • type: which style should be set (can be only LV_LINE_STYLE_MAIN)

  • style: pointer to a style

bool lv_line_get_auto_size(const lv_obj_t *line)

Get the auto size attribute

Return

true: auto size is enabled, false: disabled

Parameters
  • line: pointer to a line object

bool lv_line_get_y_invert(const lv_obj_t *line)

Get the y inversion attribute

Return

true: y inversion is enabled, false: disabled

Parameters
  • line: pointer to a line object

static const lv_style_t *lv_line_get_style(const lv_obj_t *line, lv_line_style_t type)

Get the style of an line object

Return

pointer to the line’s style

Parameters
  • line: pointer to an line object

  • type: which style should be get (can be only LV_LINE_STYLE_MAIN)

struct lv_line_ext_t

Public Members

const lv_point_t *point_array
uint16_t point_num
uint8_t auto_size
uint8_t y_inv