Core Types

The three types every LVGL Safe program uses - the widget header every widget embeds, the display that owns the framebuffer, and the screen that owns the widget list.

Common base type - ls_widget_common_t

ls_widget.hSource header · lvgl/lvgl_safe

Always the first member of every widget, named common.

FieldTypeDescription
typeconst char *Widget type string, e.g. "ls_button"
widget_nextvoid *Next widget on the screen - owned by the library
render_cbls_render_cb_tRender callback; set by *_create, overwrite it to draw the widget yourself
indev_event_cbls_indev_event_cb_tInput event callback (if LS_USE_INDEV)
indev_click_test_cbls_indev_click_test_cb_tHit-test callback; defaults to the bounding box (if LS_USE_INDEV)
hiddenboolIf true, the widget is not rendered and ignores input
pressedboolTrue while the widget is being pressed - read, don't write

Display - ls_display_t

ls_display.hSource header · lvgl/lvgl_safe
 
ls_error_code_t ls_display_init(ls_display_t * display);

init sets no geometry - fill these in yourself afterwards:

FieldTypeDescription
hor_resuint32_tWidth in pixels
ver_resint32_tHeight in pixels
strideint32_tBytes per line, i.e. hor_res * LS_BYTE_PER_PIXEL
frame_bufferls_frame_buffer_color_t *The RGB565 buffer you own and the renderer writes into
screen_activels_screen_t *The one screen that gets rendered

Switching screens is a single assignment to screen_active.

 
static ls_frame_buffer_color_t fb[320 * 240];   /*the buffer is yours, not the library's*/
static ls_display_t display;

if(ls_display_init(&display) != LS_ERROR_CODE_OK) return 1;
display.hor_res = 320;
display.ver_res = 240;
display.stride = 320 * LS_BYTE_PER_PIXEL;
display.frame_buffer = fb;
display.screen_active = &screen;

/*In your main loop: */
if(ls_render(&display) != LS_ERROR_CODE_OK) return 1;
flush_to_panel(fb);                             /*your own display driver*/

Screen - ls_screen_t

ls_screen.hSource header · lvgl/lvgl_safe
 
ls_error_code_t ls_screen_init(ls_screen_t * screen);
FieldTypeDescription
bg_colorls_color_tBackground color; defaults to white
active_focus_indexuint32_tThe focus_index that currently counts as focused
render_cbls_render_cb_tScreen render hook; init installs the default flat bg_color fill, and overwriting it replaces that fill

widget_head, widget_tail and screen_next are the library's bookkeeping - don't change them.

 
static ls_screen_t screen;

if(ls_screen_init(&screen) != LS_ERROR_CODE_OK) return 1;
screen.bg_color = LS_COLOR_HEX(0x14181d);

/*Widgets are created onto a screen, and a screen is shown by pointing a display at it.*/
display.screen_active = &screen;

Last updated on

On this page