LVGL Documentation V7.8.0-Dev
LVGL Documentation V7.8.0-Dev
0-dev
Contributors of LVGL
i
LVGL Documentation v7.8.0-dev
CONTENTS 1
CHAPTER
ONE
INTRODUCTION
LVGL (Light and Versatile Graphics Library) is a free and open-source graphics library providing everything
you need to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low
memory footprint.
• Powerful building blocks such as buttons, charts, lists, sliders, images etc.
• Advanced graphics with animations, anti-aliasing, opacity, smooth scrolling
• Various input devices such as touchpad, mouse, keyboard, encoder etc.
• Multi-language support with UTF-8 encoding
• Multi-display support, i.e. use more TFT, monochrome displays simultaneously
• Fully customizable graphic elements
• Hardware independent to use with any microcontroller or display
• Scalable to operate with little memory (64 kB Flash, 16 kB RAM)
• OS, External memory and GPU supported but not required
• Single frame buffer operation even with advanced graphical effects
• Written in C for maximal compatibility (C++ compatible)
• Simulator to start embedded GUI design on a PC without embedded hardware
• Binding to MicroPython
• Tutorials, examples, themes for rapid GUI design
• Documentation is available as online and offline
• Free and open-source under MIT license
2
LVGL Documentation v7.8.0-dev
1.2 Requirements
Basically, every modern controller (which is able to drive a display( is suitable to run LVGL. The minimal
requirements are:
1.3 License
The LVGL project (including all repositories) is licensed under MIT license. It means you can use it even in
commercial projects.
It’s not mandatory but we highly appreciate it if you write a few words about your project in the My projects
category of the Forum or a private message from lvgl.io.
Although you can get LVGL for free there is a huge work behind it. It’s created by a group of volunteers
who made it available for you in their free time.
To make the LVGL project sustainable, please consider Contributing to the project. You can choose from
many ways of contributions such as simply writing a tweet about you are using LVGL, fixing bugs, translating
the documentation, or even becoming a maintainer.
1.2. Requirements 3
LVGL Documentation v7.8.0-dev
1.5.1 Branches
LVGL has 2 weeks release cycle. On every first and third Tuesday of a month:
1. A major, minor or bug fix release is created (based on the new features) from the master branch
2. master is merged into release/vX
3. Immediately after the release dev is merged into master
4. In the upcoming 2 weeks the new features in master can be tested
5. Bug fixes are merged directly into master
6. After 2 weeks start again from the first point
1.5.3 Tags
1.5.4 Changelog
The docs is rebuilt on every release. By default, the latest documentation is displayed which is for the
current master branch of lvgl. The documentation of earlier versions is available from the menu on the left.
The simulator, porting, and other projects are updated with best effort. Pull requests are welcome if you
updated one of them.
In the core repositories each major version has a branch (e.g. release/v6). All the minor and patch
releases of that major version are merged there.
It makes possible to add fixed older versions without bothering the newer ones.
All major versions are officially supported for 1 year.
1.6 FAQ
Every MCU which is capable of driving a display via Parallel port, SPI, RGB interface or anything else and
fulfills the Requirements is supported by LLVGL.
It includes:
• ”Common” MCUs like STM32F, STM32H, NXP Kinetis, LPC, iMX, dsPIC33, PIC32 etc.
• Bluetooth, GSM, WiFi modules like Nordic NRF and Espressif ESP32
• Linux frame buffer like /dev/fb0 which includes Single-board computers too like Raspberry Pi
• And anything else with a strong enough MCU and a periphery to drive a display
LVGL needs just one simple driver function to copy an array of pixels into a given area of the display. If you
can do this with your display then you can use that display with LVGL.
Some examples of the supported display types:
• TFTs with 16 or 24 bit color depth
• Monitors with HDMI port
• Small monochrome displays
• Gray-scale displays
• even LED matrices
• or any other display where you can control the color/state of the pixels
See the Porting section to learn more.
1.6. FAQ 5
LVGL Documentation v7.8.0-dev
1.6.4 Nothing happens, my display driver is not called. What have I missed?
Be sure you are calling lv_tick_inc(x) in an interrupt and lv_task_handler() in your main
while(1).
Learn more in the Tick and Task handler section.
1.6.5 Why the display driver is called only once? Only the upper part of the display is
refreshed.
Be sure you are calling lv_disp_flush_ready(drv) at the end of your ”display flush callback”.
Probably there a bug in your display driver. Try the following code without using LVGL. You should see a
square with red-blue gradient
#define BUF_W 20
#define BUF_H 10
lv_area_t a;
a.x1 = 10;
a.y1 = 40;
a.x2 = a.x1 + BUF_W - 1;
a.y2 = a.y1 + BUF_H - 1;
my_flush_cb(NULL, &a, buf);
Probably LVGL’s color format is not compatible with your displays color format. Check LV_COLOR_DEPTH
in lv_conf.h.
If you are using 16 bit colors with SPI (or other byte-oriented interface) probably you need to set
LV_COLOR_16_SWAP 1 in lv_conf.h. It swaps the upper and lower bytes of the pixels.
1.6. FAQ 6
LVGL Documentation v7.8.0-dev
You can disable all the unused features (such as animations, file system, GPU etc.) and object types in
lv_conf.h.
If you are using GCC you can add
• -fdata-sections -ffunction-sections compiler flags
• --gc-sections linker flag
to remove unused functions and variables from the final binary
To work with an operating system where tasks can interrupt each other (preemptive) you should protect
LVGL related function calls with a mutex. See the Operating system and interrupts section to learn more.
1.6. FAQ 7
CHAPTER
TWO
GET STARTED
There are several ways to get your feet wet with LVGL. This list shows the recommended way of learning
the library:
1. Check the Online demos to see LVGL in action (3 minutes)
2. Read the Introduction page of the documentation (5 minutes)
3. Read the Quick overview page of the documentation (15 minutes)
4. Set up a Simulator (10 minutes)
5. Try out some Examples
6. Port LVGL to a board. See the Porting guide or check the ready to use Projects
7. Read the Overview page to get a better understanding of the library. (2-3 hours)
8. Check the documentation of the Widgets to see their features and usage
9. If you have questions got to the Forum
10. Read the Contributing guide to see how you can help to improve LVGL (15 minutes)
Here you can learn the most important things about LVGL. You should read it first to get a general impression
and read the detailed Porting and Overview sections after that.
Instead of porting LVGL to an embedded hardware, it’s highly recommended to get started in a simulator
first.
LVGL is ported to many IDEs to be sure you will find your faviourite one. Go to Simulators to get ready-
to-use projects which can be run on your PC. This way you can save the porting for now and make some
experience with LVGL immediately.
8
LVGL Documentation v7.8.0-dev
The following steps show how to setup LVGL on an embedded system with a display and a touchpad.
• Download or Clone the library from GitHub with git clone https://github.com/lvgl/
lvgl.git
• Copy the lvgl folder into your project
• Copy lvgl/lv_conf_templ.h as lv_conf.h next to the lvgl folder, change the first #if
0 to 1 to enable the file’s content and set at least LV_HOR_RES_MAX, LV_VER_RES_MAX and
LV_COLOR_DEPTH defines.
• Include lvgl/lvgl.h where you need to use LVGL related functions.
• Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10).
It is required for the internal timing of LVGL.
• Call lv_init()
• Create a display buffer for LVGL. LVGL will render the graphics here first, and seed the rendered
image to the display. The buffer size can be set freely but 1/10 screen size is a good starting point.
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * LV_VER_RES_MAX / 10]; /
,→*Declare a buffer for 1/10 screen size*/
• Implement and register a function which can copy the rendered image to an area of your display:
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.flush_cb = my_disp_flush; /*Set your driver function*/
disp_drv.buffer = &disp_buf; /*Assign the buffer to the display*/
lv_disp_drv_register(&disp_drv); /*Finally register the driver*/
• Implement and register a function which can read an input device. E.g. for a touch pad:
lv_indev_drv_t indev_drv; /*Descriptor of a input device driver*/
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
return false; /*Return `false` because we are not buffering and no more data to␣
,→ read*/
}
• Call lv_task_handler() periodically every few milliseconds in the main while(1) loop, in Timer
interrupt or in an Operation system task. It will redraw the screen if required, handle input devices
etc.
For a more detailed guide go to the Porting section.
Widgets
The graphical elements like Buttons, Labels, Sliders, Charts etc are called objects or widgets in LVGL. Go
to Widgets to see the full list of available widgets.
Every object has a parent object where it is create. For example if a label is created on a button, the button
is the parent of label. The child object moves with the parent and if the parent is deleted the children will
be deleted too.
Children can be visible only on their parent. It other words, the parts of the children out of the parent are
clipped.
A screen is the ”root” parent. You can have any number of screens. To get the current screen call
lv_scr_act(), and to load a screen use lv_scr_load(scr1).
You can create a new object with lv_<type>_create(parent, obj_to_copy). It will return an
lv_obj_t * variable which should be used as a reference to the object to set its parameters. The first
parameter is the desired parent, the second parameters can be an object to copy (NULL if unused). For
example:
lv_obj_set_x(btn1, 30);
lv_obj_set_y(btn1, 10);
lv_obj_set_size(btn1, 200, 50);
The objects has type specific parameters too which can be set by
lv_<type>_set_<paramters_name>(obj, <value>) functions. For example:
To see the full API visit the documentation of the widgets or the related header file (e.g.
lvgl/src/lv_widgets/lv_slider.h).
Events
Events are used to inform the user if something has happened with an object. You can assign a callback to
an object which will be called if the object is clicked, released, dragged, being deleted etc. It should look
like this:
...
Parts
Widgets might be built from one or more parts. For example a button has only one part
called LV_BTN_PART_MAIN. However, a Page has LV_PAGE_PART_BG, LV_PAGE_PART_SCROLLABLE,
LV_PAGE_PART_SCROLLBAR and LV_PAGE_PART_EDGE_FLASG.
Some parts are virtual (they are not real object, just drawn on the fly, such as the scrollbar of a page) but
other parts are real (they are real object, such as the scrollable part of the page).
Parts come into play when you want to set the styles and states of a given part of an object. (See below)
States
Styles
Styles can be assigned to the parts objects to changed their appearance. A style can describe for example
the background color, border width, text font and so on. See the full list here.
The styles can be cascaded (similarly to CSS). It means you can add more styles to a part of an object.
For example style_btn can set a default button appearance, and style_btn_red can overwrite some
properties to make the button red-
Every style property you set is specific to a state. For example is you can set different background color for
LV_STATE_DEFAULT and LV_STATE_PRESSED. The library finds the best match between the state of the
given part and the available style properties. For example if the object is in pressed state and the border
width is specified for pressed state, then it will be used. However, if it’s not specified for pressed state, the
LV_STATE_DEFAULT’s border width will be used. If the border width not defined for LV_STATE_DEFAULT
either, a default value will be used.
Some properties (typically the text-related ones) can be inherited. It means if a property is not set in an
object it will be searched in its parents too. For example you can set the font once in the screen’s style and
every text will inherit it by default.
Local style properties also can be added to the objects.
Themes
Themes are the default styles of the objects. The styles from the themes are applied automatically when the
objects are created.
You can select the theme to use in lv_conf.h.
2.1.4 Examples
#include "../../lv_examples.h"
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, NULL);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
/**
* Create a button with a label and react on Click event.
*/
void lv_ex_get_started_1(void)
{
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the␣
,→current screen*/
Styling buttons
#include "../../lv_examples.h"
/**
* Create styles from scratch for buttons.
*/
void lv_ex_get_started_2(void)
{
static lv_style_t style_btn;
static lv_style_t style_btn_red;
/*Add a border*/
lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70);
lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2);
#include "../../lv_examples.h"
/**
* Create a slider and write its value on a label.
*/
void lv_ex_get_started_3(void)
{
/* Create a slider in the center of the display */
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
lv_obj_set_width(slider, 200); /*Set the width*/
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the center of␣
,→the parent (screen)*/
}
(continues on next page)
2.1.5 Micropython
2.2 Simulator on PC
You can try out the LVGL using only your PC (i.e. without any development boards). The LVGL will run
on a simulator environment on the PC where anyone can write and experiment the real LVGL applications.
Simulator on the PC have the following advantages:
• Hardware independent - Write a code, run it on the PC and see the result on the PC monitor.
• Cross-platform - Any Windows, Linux or OSX PC can run the PC simulator.
• Portability - the written code is portable, which means you can simply copy it when using an embedded
hardware.
• Easy Validation - The simulator is also very useful to report bugs because it means common platform
for every user. So it’s a good idea to reproduce a bug in simulator and use the code snippet in the
Forum.
The simulator is ported to various IDEs (Integrated Development Environments). Choose your favorite IDE,
read its README on GitHub, download the project, and load it to the IDE.
You can use any IDEs for the development but, for simplicity, the configuration for Eclipse CDT is focused
in this tutorial. The following section describes the set-up guide of Eclipse CDT in more details.
Note: If you are on Windows, it’s usually better to use the Visual Studio or CodeBlocks
projects instead. They work out of the box without requiring extra steps.
2.2. Simulator on PC 17
LVGL Documentation v7.8.0-dev
Install SDL 2
The PC simulator uses the SDL 2 cross platform library to simulate a TFT display and a touch pad.
Linux
Windows
If you are using Windows firstly you need to install MinGW (64 bit version). After installing MinGW, do
the following steps to add SDL2:
1. Download the development libraries of SDL.Go to https://www.libsdl.org/download-2.0.php and down-
load Development Libraries: SDL2-devel-2.0.5-mingw.tar.gz
2. Decompress the file and go to x86_64-w64-mingw32 directory (for 64 bit MinGW) or to i686-w64-
mingw32 (for 32 bit MinGW)
3. Copy _...mingw32/include/SDL2 folder to C:/MinGW/.../x86_64-w64-mingw32/include
4. Copy _...mingw32/lib/ content to C:/MinGW/.../x86_64-w64-mingw32/lib
5. Copy _...mingw32/bin/SDL2.dll to {eclipse_worksapce}/pc_simulator/Debug/. Do it later when
Eclipse is installed.
Note: If you are using Microsoft Visual Studio instead of Eclipse then you don’t have to install MinGW.
2.2. Simulator on PC 18
LVGL Documentation v7.8.0-dev
OSX
On OSX you can easily install SDL2 with brew: brew install sdl2
If something is not working, then please refer this tutorial to get started with SDL.
Pre-configured project
A pre-configured graphics library project (based on the latest release) is always available to get started easily.
You can find the latest one on GitHub. (Please note that, the project is configured for Eclipse CDT).
Run Eclipse CDT. It will show a dialogue about the workspace path. Before accepting the path, check
that path and copy (and unzip) the downloaded pre-configured project there. After that, you can accept the
workspace path. Of course you can modify this path but, in that case copy the project to the corresponding
location.
Close the start up window and go to File->Import and choose General->Existing project into
Workspace. Browse the root directory of the project and click Finish
On Windows you have to do two additional things:
• Copy the SDL2.dll into the project’s Debug folder
• Right click on the project -> Project properties -> C/C++ Build -> Settings -> Libraries -> Add ...
and add mingw32 above SDLmain and SDL. (The order is important: mingw32, SDLmain, SDL)
Now you are ready to run the LVGL Graphics Library on your PC. Click on the Hammer Icon on the top
menu bar to Build the project. If you have done everything right, then you will not get any errors. Note
that on some systems additional steps might be required to ”see” SDL 2 from Eclipse but, in most of cases
the configurations in the downloaded project is enough.
After a success build, click on the Play button on the top menu bar to run the project. Now a window should
appear in the middle of your screen.
Now everything is ready to use the LVGL in the practice or begin the development on your PC.
2.3 STM32
TODO
2.3. STM32 19
LVGL Documentation v7.8.0-dev
2.4 NXP
NXP has integrated LVGL into the MCUXpresso SDK packages for several of their general purpose and
crossover microcontrollers, allowing easy evaluation and migration into your product design. Download an
SDK for a supported board today and get started with your next GUI application.
Downloading the MCU SDK example project is recommended as a starting point. It comes fully configured
with LVGL (and with PXP support if module is present), no additional integration work is required.
2.4.2 Adding HW acceleration for NXP iMX RT platforms using PXP (PiXel Pipeline)
engine for existing projects
Several drawing features in LVGL can be offloaded to PXP engine. In order to use CPU time while PXP is
running, RTOS is required to block the LVGL drawing thread and switch to another task, or simply to idle
task, where CPU could be suspended to save power.
Features supported:
Basic configuration:
2.4. NXP 20
LVGL Documentation v7.8.0-dev
Basic initialization:
#if LV_USE_GPU_NXP_PXP
#include "lv_gpu/lv_gpu_nxp_pxp.h"
#include "lv_gpu/lv_gpu_nxp_pxp_osa.h"
#endif
. . .
#if LV_USE_GPU_NXP_PXP
if (lv_gpu_nxp_pxp_init(&pxp_default_cfg) != LV_RES_OK) {
PRINTF("PXP init error. STOP.\n");
for ( ; ; ) ;
}
#endif
Project setup:
Advanced configuration:
2.4. NXP 21
LVGL Documentation v7.8.0-dev
– GPU_NXP_PXP_BLIT_OPA_SIZE_LIMIT: size threshold for image BLIT and BLIT with color
keying with transparency (OPA < LV_OPA_MAX)
– GPU_NXP_PXP_FILL_SIZE_LIMIT: size threshold for fill operation (OPA > LV_OPA_MAX)
– GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT: size threshold for fill operation with transparency
(OPA < LV_OPA_MAX)
2.6 Arduino
TODO
2.7 Micropython
Micropython is Python for microcontrollers.Using Micropython, you can write Python3 code and run it even
on a bare metal architecture with limited resources.
Highlights of Micropython
• Compact - Fits and runs within just 256k of code space and 16k of RAM. No OS is needed, although
you can also run it with an OS, if you want.
• Compatible - Strives to be as compatible as possible with normal Python (known as CPython).
• Versatile - Supports many architectures (x86, x86-64, ARM, ARM Thumb, Xtensa).
• Interactive - No need for the compile-flash-boot cycle. With the REPL (interactive prompt) you can
type commands and execute them immediately, run scripts etc.
• Popular - Many platforms are supported. The user base is growing bigger. Notable forks: MicroPy-
thon, CircuitPython, MicroPython_ESP32_psRAM_LoBo
• Embedded Oriented - Comes with modules specifically for embedded systems, such as the machine
module for accessing low-level hardware (I/O pins, ADC, UART, SPI, I2C, RTC, Timers etc.)
Currently, Micropython does not have a good high-level GUI library by default. LVGL is an Object Oriented
Component Based high-level GUI library, which seems to be a natural candidate to map into a higher level
language, such as Python. LVGL is implemented in C and its APIs are in C.
• Develop GUI in Python, a very popular high level language. Use paradigms such as Object Oriented
Programming.
• Usually, GUI development requires multiple iterations to get things right. With C, each iteration
consists of Change code > Build > Flash > Run.In Micropython it’s just Change code >
Run ! You can even run commands interactively using the REPL (the interactive prompt)
TL;DR: It’s very much like the C API, but Object Oriented for LVGL components.
Let’s dive right into an example!
A simple example
import lvgl as lv
lv.init()
scr = lv.obj()
btn = lv.btn(scr)
btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text("Button")
lv.scr_load(scr)
Online Simulator
If you want to experiment with LVGL + Micropython without downloading anything - you can use our
online simulator!It’s a fully functional LVGL + Micropython that runs entirely in the browser and allows
you to edit a python script and run it.
Click here to experiment on the online simulator
2.7. Micropython 23
LVGL Documentation v7.8.0-dev
Hello World
Note: the online simulator is available for lvgl v6 and v7.
PC Simulator
Micropython is ported to many platforms. One notable port is ”unix”, which allows you to build and run
Micropython (+LVGL) on a Linux machine. (On a Windows machine you might need Virtual Box or WSL
or MinGW or Cygwin etc.)
Click here to know more information about building and running the unix port
Embedded platform
At the end, the goal is to run it all on an embedded platform.Both Micropython and LVGL can be used
on many embedded architectures, such as stm32, ESP32 etc.You would also need display and input drivers.
We have some sample drivers (ESP32+ILI9341, as well as some other examples), but most chances are you
would want to create your own input/display drivers for your specific purposes.Drivers can be implemented
either in C as Micropython module, or in pure Micropython!
NuttX is a mature and secure real-time operating system (RTOS) with an emphasis on technical standards
compliance and small size. It is scalable from 8-bit to 64-bit microcontroller and microprocessors. Complaint
with the Portable Operating System Interface (POSIX) and the American National Standards Institute
(ANSI) standards and with many Linux-like subsystems. The best way to think about NuttX is thinking
about a small Unix/Linux for microcontrollers.
Highlights of NuttX
• Small - Fits and runs within small microcontroller as small was 32KB Flash and 8KB of RAM.
• Compliant - Strives to be as compatible as possible with POSIX and Linux.
• Versatile - Supports many architectures (ARM, ARM Thumb, AVR, MIPS, OpenRISC, RISC-V
32-bit and 64-bit, RX65N, x86-64, Xtensa, Z80/Z180, etc).
• Modular - Its modular design allow developers to select only what really matters and use modules to
include new features.
• Popular - NuttX is used by many companies around the world. Probably you already used a product
with NuttX without knowing it was running NuttX.
• Predictable - NuttX is a preemptible Realtime kernel, then you can use it to create predictable
applications for realtime control.
Although NuttX has its own graphic library called NX, LVGL is a good alternative because users could
find more eyes-candy demos and reuse it from previous projects. LVGL is an Object Oriented Component
Based high-level GUI library, that could fit very well for a RTOS with advanced features like NuttX. LVGL
is implemented in C and its APIs are in C.
• Develop GUI in Linux first and when it is done just compile it for NuttX, nothing more, no wasting of
time.
• Usually, GUI development for low level RTOS requires multiple iterations to get things right. Where
each iteration consists of Change code > Build > Flash > Run. Using LVGL, Linux and NuttX
you can reduce this process and just test everything on your computer and when it is done, compile it
on NuttX and that is it.
There are many boards in the NuttX mainline (https://github.com/apache/incubator-nuttx) with support
for LVGL. Let’s to use the STM32F429IDISCOVERY as example because it is a very popular board.
,→frontends openocd
$ mkdir ~/nuttxspace
$ cd ~/nuttxspace
Configure NuttX to use the stm32f429i-disco board and the LVGL Demo
$ ./tools/configure.sh stm32f429i-disco:lvgl
$ make
If everything went fine you should have now the file nuttx.bin to flash on your board:
$ ls -l nuttx.bin
-rwxrwxr-x 1 alan alan 287144 Jun 27 09:26 nuttx.bin
Reset the board and using the ’NSH>’ terminal start the LVGL demo:
nsh> lvgldemo
THREE
PORTING
Application Your application which creates the GUI and handles the specific tasks.
LVGL The graphics library itself. Your application can communicate with the library to create a GUI. It
contains a HAL (Hardware Abstraction Layer) interface to register your display and input device drivers.
Driver Besides your specific drivers, it contains functions to drive your display, optionally to a GPU and to
read the touchpad or buttons.
Depending on the MCU, there are two typical hardware set-ups. One with built-in LCD/TFT driver pe-
riphery and another without it. In both cases, a frame buffer will be required to store the current image of
the screen.
1. MCU with TFT/LCD driver If your MCU has a TFT/LCD driver periphery then you can connect
a display directly via RGB interface. In this case, the frame buffer can be in the internal RAM (if the
MCU has enough RAM) or in the external RAM (if the MCU has a memory interface).
2. External display controller If the MCU doesn’t have TFT/LCD driver interface then an external
display controller (E.g. SSD1963, SSD1306, ILI9341) has to be used. In this case, the MCU can
communicate with the display controller via Parallel port, SPI or sometimes I2C. The frame buffer is
usually located in the display controller which saves a lot of RAM for the MCU.
27
LVGL Documentation v7.8.0-dev
There is a configuration header file for LVGL called lv_conf.h. It sets the library’s basic behaviour, disables
unused modules and features, adjusts the size of memory buffers in compile-time, etc.
Copy lvgl/lv_conf_template.h next to the lvgl directory and rename it to lv_conf.h. Open the file and
change the #if 0 at the beginning to #if 1 to enable its content.
lv_conf.h can be copied other places as well but then you should add LV_CONF_INCLUDE_SIMPLE define
to your compiler options (e.g. -DLV_CONF_INCLUDE_SIMPLE for gcc compiler) and set the include path
manually.
In the config file comments explain the meaning of the options. Check at least these three configuration
options and modify them according to your hardware:
1. LV_HOR_RES_MAX Your display’s horizontal resolution.
2. LV_VER_RES_MAX Your display’s vertical resolution.
3. LV_COLOR_DEPTH 8 for (RG332), 16 for (RGB565) or 32 for (RGB888 and ARGB8888).
3.2.3 Initialization
To use the graphics library you have to initialize it and the other components too. The order of the
initialization is:
1. Call lv_init().
2. Initialize your drivers.
3. Register the display and input devices drivers in LVGL. More about Display and Input device registra-
tion.
4. Call lv_tick_inc(x) in every x milliseconds in an interrupt to tell the elapsed time. Learn more.
5. Call lv_task_handler() periodically in every few milliseconds to handle LVGL related tasks. Learn
more.
Once the buffer initialization is ready the display drivers need to be initialized. In the most simple case only
the following two fields of lv_disp_drv_t needs to be set:
• buffer pointer to an initialized lv_disp_buf_t variable.
• flush_cb a callback function to copy a buffer’s content to a specific area of the display.
There are some optional data fields:
• hor_res horizontal resolution of the display. (LV_HOR_RES_MAX by default from lv_conf.h).
• ver_res vertical resolution of the display. (LV_VER_RES_MAX by default from lv_conf.h).
• color_chroma_key a color which will be drawn as transparent on chrome keyed images.
LV_COLOR_TRANSP by default from lv_conf.h).
• user_data custom user data for the driver. Its type can be modified in lv_conf.h.
• anti-aliasing use anti-aliasing (edge smoothing). LV_ANTIALIAS by default from lv_conf.h.
• rotated if 1 swap hor_res and ver_res. LVGL draws in the same direction in both cases (in lines
from top to bottom) so the driver also needs to be reconfigured to change the display’s fill direction.
• screen_transp if 1 the screen can have transparent or opaque style. LV_COLOR_SCREEN_TRANSP
needs to enabled in lv_conf.h.
To use a GPU the following callbacks can be used:
• gpu_fill_cb fill an area in memory with colors.
• gpu_blend_cb blend two memory buffers using opacity.
• gpu_wait_cb if any GPU function return while the GPU is still working LVGL will use this function
when required the be sure GPU rendereing is ready.
Note that, these functions need to draw to the memory (RAM) and not your display directly.
Some other optional callbacks to make easier and more optimal to work with monochrome, grayscale or other
non-standard RGB displays:
• rounder_cb round the coordinates of areas to redraw. E.g. a 2x2 px can be converted to 2x8. It
can be used if the display controller can refresh only areas with specific height or width (usually 8 px
height with monochrome displays).
• set_px_cb a custom function to write the display buffer. It can be used to store the pixels more
compactly if the display has a special color format. (e.g. 1-bit monochrome, 2-bit grayscale etc.) This
way the buffers used in lv_disp_buf_t can be smaller to hold only the required number of bits for
the given area size. set_px_cb is not working with Two screen-sized buffers display buffer
configuration.
• monitor_cb a callback function tells how many pixels were refreshed in how much time.
• clean_dcache_cb a callback for cleaning any caches related to the display
To set the fields of lv_disp_drv_t variable it needs to be initialized with
lv_disp_drv_init(&disp_drv). And finally to register a display for LVGL
lv_disp_drv_register(&disp_drv) needs to be called.
All together it looks like this:
lv_disp_t * disp;
disp = lv_disp_drv_register(&disp_drv); /*Register the driver and save the␣
,→created display objects*/
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-
,→by-one*/
int32_t x, y;
(continues on next page)
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp);
}
{
/*It's an example code which should be done by your GPU*/
uint32_t x, y;
dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
{
/*It's an example code which should be done by your GPU*/
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = lv_color_mix(dest[i], src[i], opa);
}
}
{
/* Write to the buffer as required for the display.
* Write only 1-bit for monochrome displays mapped vertically:*/
buf += buf_w * (y >> 3) + x;
if(lv_color_brightness(color) > 128) (*buf) |= (1 << (y % 8));
else (*buf) &= ~(1 << (y % 8));
}
3.3.3 API
Typedefs
Enums
enum lv_disp_size_t
Values:
enumerator LV_DISP_SIZE_SMALL
enumerator LV_DISP_SIZE_MEDIUM
enumerator LV_DISP_SIZE_LARGE
enumerator LV_DISP_SIZE_EXTRA_LARGE
Functions
• buf1: A buffer to be used by LVGL to draw the image. Always has to specified and
can’t be NULL. Can be an array allocated by the user. E.g. static lv_color_t
disp_buf1[1024 * 10] Or a memory address e.g. in external SRAM
• buf2: Optionally specify a second buffer to make image rendering and image flushing (sending
to the display) parallel. In the disp_drv->flush you should use DMA or similar hardware
to send the image to the display in the background. It lets LVGL to render next frame into
the other buffer while previous is being sent. Set to NULL if unused.
• size_in_px_cnt: size of the buf1 and buf2 in pixel count.
lv_disp_t *lv_disp_drv_register(lv_disp_drv_t *driver)
Register an initialized display driver. Automatically set the first display as active.
Return pointer to the new display or NULL on error
Parameters
• driver: pointer to an initialized ’lv_disp_drv_t’ variable (can be local variable)
void lv_disp_drv_update(lv_disp_t *disp, lv_disp_drv_t *new_drv)
Update the driver in run time.
Parameters
• disp: pointer to a display. (return value of lv_disp_drv_register)
• new_drv: pointer to the new driver
void lv_disp_remove(lv_disp_t *disp)
Remove a display
Parameters
• disp: pointer to display
void lv_disp_set_default(lv_disp_t *disp)
Set a default screen. The new screens will be created on it by default.
Parameters
• disp: pointer to a display
lv_disp_t *lv_disp_get_default(void)
Get the default display
Return pointer to the default display
lv_coord_t lv_disp_get_hor_res(lv_disp_t *disp)
Get the horizontal resolution of a display
Return the horizontal resolution of the display
Parameters
• disp: pointer to a display (NULL to use the default display)
lv_coord_t lv_disp_get_ver_res(lv_disp_t *disp)
Get the vertical resolution of a display
Return the vertical resolution of the display
Parameters
• disp: pointer to a display (NULL to use the default display)
Public Members
void *buf1
First display buffer.
void *buf2
Second display buffer.
void *buf_act
uint32_t size
lv_area_t area
int flushing
int flushing_last
uint32_t last_area
uint32_t last_part
struct _disp_drv_t
#include <lv_hal_disp.h> Display Driver structure to be registered by HAL
Public Members
lv_coord_t hor_res
Horizontal resolution.
lv_coord_t ver_res
Vertical resolution.
lv_disp_buf_t *buffer
Pointer to a buffer initialized with lv_disp_buf_init(). LVGL will use this buffer(s) to draw
the screens contents
uint32_t antialiasing
1: antialiasing is enabled on this display.
uint32_t rotated
1: turn the display by 90 degree.
Warning Does not update coordinates for you!
uint32_t screen_transp
Handle if the the screen doesn’t have a solid (opa == LV_OPA_COVER) background. Use only
if required because it’s slower.
uint32_t dpi
DPI (dot per inch) of the display. Set to LV_DPI from lv_Conf.h by default.
void (*flush_cb)(struct _disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t
*color_p)
MANDATORY: Write the internal buffer (VDB) to the display. ’lv_disp_flush_ready()’ has to
be called when finished
void (*rounder_cb)(struct _disp_drv_t *disp_drv, lv_area_t *area)
OPTIONAL: Extend the invalidated areas to match with the display drivers requirements E.g.
round y to, 8, 16 ..) on a monochrome display
void (*set_px_cb)(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w,
lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
OPTIONAL: Set a pixel in a buffer according to the special requirements of the display Can be
used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales
Note Much slower then drawing with supported color formats.
void (*monitor_cb)(struct _disp_drv_t *disp_drv, uint32_t time, uint32_t px)
OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the number
of flushed pixels
void (*wait_cb)(struct _disp_drv_t *disp_drv)
OPTIONAL: Called periodically while lvgl waits for operation to be completed. For example
flushing or GPU User can execute very simple tasks here or yield the task
void (*clean_dcache_cb)(struct _disp_drv_t *disp_drv)
OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned
void (*gpu_wait_cb)(struct _disp_drv_t *disp_drv)
OPTIONAL: called to wait while the gpu is working
void (*gpu_blend_cb)(struct _disp_drv_t *disp_drv, lv_color_t *dest, const lv_color_t
*src, uint32_t length, lv_opa_t opa)
OPTIONAL: Blend two memories using opacity (GPU only)
void (*gpu_fill_cb)(struct _disp_drv_t *disp_drv, lv_color_t *dest_buf, lv_coord_t
dest_width, const lv_area_t *fill_area, lv_color_t color)
OPTIONAL: Fill a memory with a color (GPU only)
lv_color_t color_chroma_key
On CHROMA_KEYED images this color will be transparent. LV_COLOR_TRANSP by default.
(lv_conf.h)
lv_disp_drv_user_data_t user_data
Custom display driver user data
struct _disp_t
#include <lv_hal_disp.h> Display structure.
Note lv_disp_drv_t should be the first member of the structure.
Public Members
lv_disp_drv_t driver
< Driver to the display A task which periodically checks the dirty areas and refreshes them
lv_task_t *refr_task
lv_ll_t scr_ll
Screens of the display
struct _lv_obj_t *act_scr
Currently active screen on this display
struct _lv_obj_t *prev_scr
Previous screen. Used during screen animations
struct _lv_obj_t *top_layer
See lv_disp_get_layer_top
struct _lv_obj_t *sys_layer
See lv_disp_get_layer_sys
uint8_t del_prev
1: Automatically delete the previous screen when the screen load animation is ready
lv_color_t bg_color
Default display color when screens are transparent
const void *bg_img
An image source to display as wallpaper
lv_opa_t bg_opa
Opacity of the background color or wallpaper
lv_area_t inv_areas[LV_INV_BUF_SIZE]
Invalidated (marked to redraw) areas
uint8_t inv_area_joined[LV_INV_BUF_SIZE]
uint32_t inv_p
uint32_t last_activity_time
Last time there was activity on this display
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type =... /*See below.*/
indev_drv.read_cb =... /*See below.*/
/*Register the driver in LVGL and save the created input device object*/
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
type can be
Input devices which can click points of the screen belong to this category.
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_input_read;
...
Important: Touchpad drivers must return the last X/Y coordinates even when the state is
LV_INDEV_STATE_REL.
Keypad or keyboard
Full keyboards with all the letters or simple keypads with a few navigation buttons belong here.
To use a keyboard/keypad:
• Register a read_cb function with LV_INDEV_TYPE_KEYPAD type.
• Enable LV_USE_GROUP in lv_conf.h
• An object group has to be created: lv_group_t * g = lv_group_create() and objects have
to be added to it with lv_group_add_obj(g, obj)
• The created group has to be assigned to an input device: lv_indev_set_group(my_indev, g)
(my_indev is the return value of lv_indev_drv_register)
• Use LV_KEY_... to navigate among the objects in the group. See lv_core/lv_group.h for the
available keys.
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read_cb = keyboard_read;
...
Encoder
indev_drv.type = LV_INDEV_TYPE_ENCODER;
indev_drv.read_cb = encoder_read;
...
In addition to standard encoder behavior, you can also utilise its logic to navigate(focus) and edit widgets
using buttons. This is especially handy if you have only few buttons avalible, or you want to use other
buttons in addition to encoder wheel.
You need to have 3 buttons avalible:
• LV_KEY_ENTER will simulate press or pushing of the encoder button
• LV_KEY_LEFT will simulate turnuing encoder left
• LV_KEY_RIGHT will simulate turnuing encoder right
• other keys will be passed to the focused widget
If you hold the keys it will simulate encoder click with period specified in indev_drv.
long_press_rep_time.
indev_drv.type = LV_INDEV_TYPE_ENCODER;
indev_drv.read_cb = encoder_with_keys_read;
...
Button
Buttons mean external ”hardware” buttons next to the screen which are assigned to specific coordinates of
the screen. If a button is pressed it will simulate the pressing on the assigned coordinate. (Similarly to a
touchpad)
To assign buttons to coordinates use lv_indev_set_button_points(my_indev,
points_array).points_array should look like const lv_point_t points_array[] = {
{12,30},{60,90}, ...}
Important: The points_array can’t go out of scope. Either declare it as a global variable or as a static
variable inside a function.
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
...
3.4.3 API
Typedefs
Enums
enum [anonymous]
Possible input device types
Values:
enumerator LV_INDEV_TYPE_NONE
Uninitialized state
enumerator LV_INDEV_TYPE_POINTER
Touch pad, mouse, external button
enumerator LV_INDEV_TYPE_KEYPAD
Keypad or keyboard
enumerator LV_INDEV_TYPE_BUTTON
External (hardware button) which is assigned to a specific point of the screen
enumerator LV_INDEV_TYPE_ENCODER
Encoder with only Left, Right turn and a Button
enum [anonymous]
States for input devices
Values:
enumerator LV_INDEV_STATE_REL = 0
enumerator LV_INDEV_STATE_PR
enum [anonymous]
Values:
enumerator LV_DRAG_DIR_HOR = 0x1
Object can be dragged horizontally.
enumerator LV_DRAG_DIR_VER = 0x2
Object can be dragged vertically.
enumerator LV_DRAG_DIR_BOTH = 0x3
Object can be dragged in all directions.
enumerator LV_DRAG_DIR_ONE = 0x4
Object can be dragged only one direction (the first move).
enum [anonymous]
Values:
enumerator LV_GESTURE_DIR_TOP
Gesture dir up.
enumerator LV_GESTURE_DIR_BOTTOM
Gesture dir down.
enumerator LV_GESTURE_DIR_LEFT
Gesture dir left.
enumerator LV_GESTURE_DIR_RIGHT
Gesture dir right.
Functions
Public Members
lv_point_t point
For LV_INDEV_TYPE_POINTER the currently pressed point
uint32_t key
For LV_INDEV_TYPE_KEYPAD the currently pressed key
uint32_t btn_id
For LV_INDEV_TYPE_BUTTON the currently pressed button
int16_t enc_diff
For LV_INDEV_TYPE_ENCODER number of steps since the previous read
lv_indev_state_t state
LV_INDEV_STATE_REL or LV_INDEV_STATE_PR
struct _lv_indev_drv_t
#include <lv_hal_indev.h> Initialized by the user and registered by ’lv_indev_add()’
Public Members
lv_indev_type_t type
< Input device type Function pointer to read input device data. Return ’true’ if there is more
data to be read (buffered). Most drivers can safely return ’false’
bool (*read_cb)(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
void (*feedback_cb)(struct _lv_indev_drv_t*, uint8_t)
Called when an action happened on the input device. The second parameter is the event from
lv_event_t
lv_indev_drv_user_data_t user_data
struct _disp_t *disp
< Pointer to the assigned display Task to read the periodically read the input device
lv_task_t *read_task
Number of pixels to slide before actually drag the object
uint8_t drag_limit
Drag throw slow-down in [%]. Greater value means faster slow-down
uint8_t drag_throw
At least this difference should between two points to evaluate as gesture
uint8_t gesture_min_velocity
At least this difference should be to send a gesture
uint8_t gesture_limit
Long press time in milliseconds
uint16_t long_press_time
Repeated trigger period in long press [ms]
uint16_t long_press_rep_time
struct _lv_indev_proc_t
#include <lv_hal_indev.h> Run time data of input devices Internally used by the library, you should
not need to touch it.
Public Members
lv_indev_state_t state
Current state of the input device.
lv_point_t act_point
Current point of input device.
lv_point_t last_point
Last point of input device.
lv_point_t vect
Difference between act_point and last_point.
lv_point_t drag_sum
lv_point_t drag_throw_vect
struct _lv_obj_t *act_obj
struct _lv_obj_t *last_obj
struct _lv_obj_t *last_pressed
lv_gesture_dir_t gesture_dir
lv_point_t gesture_sum
uint8_t drag_limit_out
uint8_t drag_in_prog
lv_drag_dir_t drag_dir
uint8_t gesture_sent
struct _lv_indev_proc_t::[anonymous]::[anonymous] pointer
lv_indev_state_t last_state
uint32_t last_key
struct _lv_indev_proc_t::[anonymous]::[anonymous] keypad
union _lv_indev_proc_t::[anonymous] types
uint32_t pr_timestamp
Pressed time stamp
uint32_t longpr_rep_timestamp
Long press repeat time stamp
uint8_t long_pr_sent
uint8_t reset_query
uint8_t disabled
uint8_t wait_until_release
struct _lv_indev_t
#include <lv_hal_indev.h> The main input device descriptor with driver, runtime data (’proc’) and
some additional information
Public Members
lv_indev_drv_t driver
lv_indev_proc_t proc
struct _lv_obj_t *cursor
Cursor for LV_INPUT_TYPE_POINTER
struct _lv_group_t *group
Keypad destination group
const lv_point_t *btn_points
Array points assigned to the button ()screen will be pressed here by the buttons
The LVGL needs a system tick to know the elapsed time for animation and other tasks.
You need to call the lv_tick_inc(tick_period) function periodically and tell the call period in mil-
liseconds. For example, lv_tick_inc(1) for calling in every millisecond.
lv_tick_inc should be called in a higher priority routine than lv_task_handler() (e.g. in an inter-
rupt) to precisely know the elapsed milliseconds even if the execution of lv_task_handler takes longer
time.
With FreeRTOS lv_tick_inc can be called in vApplicationTickHook.
On Linux based operating system (e.g. on Raspberry Pi) lv_tick_inc can be called in a thread as below:
3.5.1 API
Functions
uint32_t lv_tick_get(void)
Get the elapsed milliseconds since start up
Return the elapsed milliseconds
uint32_t lv_tick_elaps(uint32_t prev_tick)
Get the elapsed milliseconds since a previous time stamp
Return the elapsed milliseconds since ’prev_tick’
Parameters
• prev_tick: a previous time stamp (return value of systick_get() )
To handle the tasks of LVGL you need to call lv_task_handler() periodically in one of the followings:
• while(1) of main() function
• timer interrupt periodically (low priority then lv_tick_inc())
• an OS task periodically
The timing is not critical but it should be about 5 milliseconds to keep the system responsive.
Example:
while(1) {
lv_task_handler();
my_delay_ms(5);
}
The MCU can go to sleep when no user input happens. In this case, the main while(1) should look like
this:
while(1) {
/*Normal operation (no sleep) in < 1 sec inactivity*/
if(lv_disp_get_inactive_time(NULL) < 1000) {
lv_task_handler();
}
/*Sleep after 1 sec inactivity*/
else {
timer_stop(); /*Stop the timer where lv_tick_inc() is called*/
sleep(); /*Sleep the MCU*/
}
my_delay_ms(5);
}
You should also add below lines to your input device read function if a wake-up (press, touch or click etc.)
happens:
If you need to use real tasks or threads, you need a mutex which should be invoked before the call of
lv_task_handler and released after it. Also, you have to use the same mutex in other tasks and threads
around every LVGL (lv_...) related function calls and codes. This way you can use LVGL in a real
multitasking environment. Just make use of a mutex to avoid the concurrent calling of LVGL functions.
3.8.2 Interrupts
Try to avoid calling LVGL functions from the interrupts (except lv_tick_inc() and
lv_disp_flush_ready()). But, if you need to do this you have to disable the interrupt which
uses LVGL functions while lv_task_handler is running. It’s a better approach to set a flag or some
value and periodically check it in an lv_task.
3.9 Logging
LVGL has built-in log module to inform the user about what is happening in the library.
To enable logging, set LV_USE_LOG 1 in lv_conf.h and set LV_LOG_LEVEL to one of the following values:
• LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
• LV_LOG_LEVEL_INFO Log important events
• LV_LOG_LEVEL_WARN Log if something unwanted happened but didn’t cause a problem
• LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
• LV_LOG_LEVEL_NONE Do not log anything
The events which have a higher level than the set log level will be logged too. E.g. if you
LV_LOG_LEVEL_WARN, errors will be also logged.
If your system supports printf, you just need to enable LV_LOG_PRINTF in lv_conf.h to send the logs
with printf.
If you can’t use printf or want to use a custom function to log, you can register a ”logger” callback with
lv_log_register_print_cb().
For example:
void my_log_cb(lv_log_level_t level, const char * file, int line, const char * fn_
,→name, const char * dsc)
{
/*Send the logs via serial port*/
if(level == LV_LOG_LEVEL_ERROR) serial_send("ERROR: ");
if(level == LV_LOG_LEVEL_WARN) serial_send("WARNING: ");
if(level == LV_LOG_LEVEL_INFO) serial_send("INFO: ");
if(level == LV_LOG_LEVEL_TRACE) serial_send("TRACE: ");
serial_send("File: ");
serial_send(file);
char line_str[8];
sprintf(line_str,"%d", line);
serial_send("#");
serial_send(line_str);
serial_send(": ");
serial_send(fn_name);
serial_send(": ");
serial_send(dsc);
serial_send("\n");
}
...
lv_log_register_print_cb(my_log_cb);
You can also use the log module via the LV_LOG_TRACE/INFO/WARN/ERROR(description) functions.
3.9. Logging 49
CHAPTER
FOUR
OVERVIEW
4.1 Objects
In the LVGL the basic building blocks of a user interface are the objects, also called Widgets. For example
a Button, Label, Image, List, Chart or Text area.
Check all the Object types here.
4.1.1 Attributes
Basic attributes
To see all the available functions visit the Base object’s documentation.
Specific attributes
The object types have special attributes too. For example, a slider has
• Min. max. values
• Current value
• Custom styles
For these attributes, every object type have unique API functions. For example for a slider:
50
LVGL Documentation v7.8.0-dev
The API of the object types are described in their Documentation but you can also check the respective
header files (e.g. lv_objx/lv_slider.h)
Parent-child structure
A parent object can be considered as the container of its children. Every object has exactly one parent
object (except screens), but a parent can have an unlimited number of children. There is no limitation for
the type of the parent but, there are typical parent (e.g. button) and typical child (e.g. label) objects.
Moving together
If the position of the parent is changed the children will move with the parent. Therefore all positions are
relative to the parent.
The (0;0) coordinates mean the objects will remain in the top left-hand corner of the parent independently
from the position of the parent.
4.1. Objects 51
LVGL Documentation v7.8.0-dev
lv_obj_set_pos(par, 50, 50); /*Move the parent. The child will move with it.*/
(For simplicity the adjusting of colors of the objects is not shown in the example.)
If a child is partially or fully out of its parent then the parts outside will not be visible.
4.1. Objects 52
LVGL Documentation v7.8.0-dev
In LVGL objects can be created and deleted dynamically in run-time. It means only the currently created
objects consume RAM. For example, if you need a chart, you can create it when required and delete it when
it is not visible or necessary.
Every object type has its own create function with a unified prototype. It needs two parameters:
• A pointer to the parent object. To create a screen give NULL as parent.
• Optionally, a pointer to copy object with the same type to copy it. This copy object can be NULL to
avoid the copy operation.
All objects are referenced in C code using an lv_obj_t pointer as a handle. This pointer can later be used
to set or get the attributes of the object.
The create functions look like this:
There is a common delete function for all object types. It deletes the object and all of its children.
lv_obj_del will delete the object immediately. If for any reason you can’t delete the object immediately
you can use lv_obj_del_async(obj). It is useful e.g. if you want to delete the parent of an object in
the child’s LV_EVENT_DELETE signal.
You can remove all the children of an object (but not the object itself) using lv_obj_clean:
4.1. Objects 53
LVGL Documentation v7.8.0-dev
4.1.3 Screens
Create screens
The screens are special objects which have no parent object. So they can be created like:
Screens can be created with any object type. For example, a Base object or an image to make a wallpaper.
There is always an active screen on each display. By default, the library creates and loads a ”Base object”
as a screen for each display.
To get the currently active screen use the lv_scr_act() function.
Load screens
A new screen can be loaded with animation too using lv_scr_load_anim(scr, transition_type,
time, delay, auto_del). The following transition types exist:
• LV_SCR_LOAD_ANIM_NONE: switch immediately after delay ms
• LV_SCR_LOAD_ANIM_OVER_LEFT/RIGHT/TOP/BOTTOM move the new screen over the other to-
wards the given direction
• LV_SCR_LOAD_ANIM_MOVE_LEFT/RIGHT/TOP/BOTTOM move both the old and new screens towards
the given direction
• LV_SCR_LOAD_ANIM_FADE_ON fade the new screen over the old screen
Setting auto_del to true will automatically delete the old screen when the animation is finished.
The new screen will become active (returned by lv_scr_act()) when the animations starts after delay
time.
Screens are created on the currently selected default display. The default display is the last regis-
tered display with lv_disp_drv_register or you can explicitly select a new default display using
lv_disp_set_default(disp).
lv_scr_act(), lv_scr_load() and lv_scr_load_anim() operate on the default screen.
Visit Multi-display support to learn more.
4.1. Objects 54
LVGL Documentation v7.8.0-dev
4.1.4 Parts
The widgets can have multiple parts. For example a Button has only a main part but a Slider is built from
a background, an indicator and a knob.
The name of the parts is constructed like LV_ + <TYPE> _PART_ <NAME>. For example
LV_BTN_PART_MAIN or LV_SLIDER_PART_KNOB. The parts are usually used when styles are add to
the objects. Using parts different styles can be assigned to the different parts of the objects.
To learn more about the parts read the related section of the Style overview.
4.1.5 States
4.2 Layers
By default, LVGL draws old objects on the background and new objects on the foreground.
For example, assume we added a button to a parent object named button1 and then another button named
button2. Then button1 (with its child object(s)) will be in the background and can be covered by button2
and its children.
4.2. Layers 55
LVGL Documentation v7.8.0-dev
/*Create a screen*/
lv_obj_t * scr = lv_obj_create(NULL, NULL);
lv_scr_load(scr); /*Load the screen*/
/*Create 2 buttons*/
lv_obj_t * btn1 = lv_btn_create(scr, NULL); /*Create a button on the screen*/
lv_btn_set_fit(btn1, true, true); /*Enable to automatically set the␣
,→size according to the content*/
4.2. Layers 56
LVGL Documentation v7.8.0-dev
LVGL uses two special layers named as layer_top and layer_sys. Both are visible and common
on all screens of a display. They are not, however, shared among multiple physical displays.
The layer_top is always on top of the default screen (lv_scr_act()), and layer_sys is on top of
layer_top.
The layer_top can be used by the user to create some content visible everywhere. For example, a menu
bar, a pop-up, etc. If the click attribute is enabled, then layer_top will absorb all user click and acts
as a modal.
lv_obj_set_click(lv_layer_top(), true);
The layer_sys is also using for similar purpose on LVGL. For example, it places the mouse cursor there
to be sure it’s always visible.
4.3 Events
Events are triggered in LVGL when something happens which might be interesting to the user, e.g. if an
object:
• is clicked
• is dragged
• its value has changed, etc.
The user can assign a callback function to an object to see these events. In practice, it looks like this:
...
case LV_EVENT_SHORT_CLICKED:
(continues on next page)
4.3. Events 57
LVGL Documentation v7.8.0-dev
case LV_EVENT_CLICKED:
printf("Clicked\n");
break;
case LV_EVENT_LONG_PRESSED:
printf("Long press\n");
break;
case LV_EVENT_LONG_PRESSED_REPEAT:
printf("Long press repeat\n");
break;
case LV_EVENT_RELEASED:
printf("Released\n");
break;
}
/*Etc.*/
}
Generic events
All objects (such as Buttons/Labels/Sliders etc.) receive these generic events regardless of their type.
These are sent when an object is pressed/released etc. by the user. They are used not only for Pointers but
can used for Keypad, Encoder and Button input devices as well. Visit the Overview of input devices section
to learn more about them.
• LV_EVENT_PRESSED The object has been pressed
• LV_EVENT_PRESSING The object is being pressed (sent continuously while pressing)
• LV_EVENT_PRESS_LOST The input device is still being pressed but is no longer on the object
• LV_EVENT_SHORT_CLICKED Released before LV_INDEV_LONG_PRESS_TIME time. Not
called if dragged.
• LV_EVENT_LONG_PRESSED Pressing for LV_INDEV_LONG_PRESS_TIME time. Not called
if dragged.
• LV_EVENT_LONG_PRESSED_REPEAT Called after LV_INDEV_LONG_PRESS_TIME in
every LV_INDEV_LONG_PRESS_REP_TIME ms. Not called if dragged.
• LV_EVENT_CLICKED Called on release if not dragged (regardless to long press)
4.3. Events 58
LVGL Documentation v7.8.0-dev
• LV_EVENT_RELEASED Called in every case when the object has been released even if it was
dragged. Not called if slid from the object while pressing and released outside of the object. In this
case, LV_EVENT_PRESS_LOST is sent.
Related to pointer
These events are sent only by pointer-like input devices (E.g. mouse or touchpad)
• LV_EVENT_DRAG_BEGIN Dragging of the object has started
• LV_EVENT_DRAG_END Dragging finished (including drag throw)
• LV_EVENT_DRAG_THROW_BEGIN Drag throw started (released after drag with ”momen-
tum”)
These events are sent by keypad and encoder input devices. Learn more about Groups in
[overview/indev](Input devices) section.
• LV_EVENT_KEY A Key is sent to the object. Typically when it was pressed or repeated after a
long press. The key can be retrived by uint32_t * key = lv_event_get_data()
• LV_EVENT_FOCUSED The object is focused in its group
• LV_EVENT_DEFOCUSED The object is defocused in its group
General events
Special events
4.3. Events 59
LVGL Documentation v7.8.0-dev
Some events might contain custom data. For example, LV_EVENT_VALUE_CHANGED in some cases tells the
new value. For more information, see the particular Object type’s documentation. To get the custom data
in the event callback use lv_event_get_data().
The type of the custom data depends on the sending object but if it’s a
• single number then it’s uint32_t * or int32_t *
• text then char * or const char *
Arbitrary events
/*Simulate the press of the first button (indexes start from zero)*/
uint32_t btn_id = 0;
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
Refresh event
LV_EVENT_REFRESH is special event because it’s designed to be used by the user to notify an object to
refresh itself. Some examples:
• notify a label to refresh its text according to one or more variables (e.g. current time)
• refresh a label when the language changes
• enable a button if some conditions are met (e.g. the correct PIN is entered)
• add/remove styles to/from an object if a limit is exceeded, etc
To simplest way to handle similar cases is utilizing the following functions.
lv_event_send_refresh(obj) is just a wrapper to lv_event_send(obj, LV_EVENT_REFRESH,
NULL). So it simply sends an LV_EVENT_REFRESH to an object.
lv_event_send_refresh_recursive(obj) sends LV_EVENT_REFRESH event to an object and all of
its children. If NULL is passed as parameter all objects of all displays will be refreshed.
4.4 Styles
Styles are used to set the appearance of the objects. Styles in lvgl are heavily inspired by CSS. The concept
in nutshell is the following:
• A style is an lv_style_t variable which can hold properties, for example border width, text color
and so on. It’s similar to class in CSS.
• Not all properties have to be specified. Unspecified properties will use a default value.
• Styles can be assigned to objects to change their appearance.
4.4. Styles 60
LVGL Documentation v7.8.0-dev
4.4.1 States
4.4. Styles 61
LVGL Documentation v7.8.0-dev
5. It’s possible to set e.g rose color for LV_STATE_PRESSED | LV_STATE_FOCUSED. In this case, this
combined state has 0x02 + 0x10 = 0x12 precedence, which higher than the pressed states precedence
so rose color would be used.
6. When the object is checked there is no property to set the background color for this state. So in lack
of a better option, the object remains white from the default state’s property.
Some practical notes:
• If you want to set a property for all state (e.g. red background color) just set it for the default state.
If the object can’t find a property for its current state it will fall back to the default state’s property.
• Use ORed states to describe the properties for complex cases. (E.g. pressed + checked + focused)
• It might be a good idea to use different style elements for different states. For example, finding
background colors for released, pressed, checked + pressed, focused, focused + pressed, focused +
pressed + checked, etc states is quite difficult. Instead, for example, use the background color for
pressed and checked states and indicate the focused state with a different border color.
It’s not required to set all the properties in one style. It’s possible to add more styles to an object and let
the later added style to modify or extend the properties in the other styles. For example, create a general
gray button style and create a new for red buttons where only the new background color is set.
It’s the same concept when in CSS all the used classes are listed like <div class=".btn .btn-red">.
The later added styles have higher precedence over the earlier ones. So in the gray/red button example
above, the normal button style should be added first and the red style second. However, the precedence
coming from states are still taken into account. So let’s examine the following case:
• the basic button style defines dark-gray color for default state and light-gray color pressed state
• the red button style defines the background color as red only in the default state
In this case, when the button is released (it’s in default state) it will be red because a perfect match is
found in the lastly added style (red style). When the button is pressed the light-gray color is a better match
because it describes the current state perfectly, so the button will be light-gray.
4.4.3 Inheritance
Some properties (typically that are related to texts) can be inherited from the parent object’s styles. Inher-
itance is applied only if the given property is not set in the object’s styles (even in default state). In this
case, if the property is inheritable, the property’s value will be searched in the parent too until a part can
tell a value for the property. The parents will use their own state to tell the value. So is button is pressed,
and text color comes from here, the pressed text color will be used.
4.4. Styles 62
LVGL Documentation v7.8.0-dev
4.4.4 Parts
Objects can have parts which can have their own style. For example a page has four parts:
• Background
• Scrollable
• Scrollbar
• Edge flash
There is three types of object parts main, virtual and real.
The main part is usually the background and largest part of the object. Some object has only a main part.
For example, a button has only a background.
The virtual parts are additional parts just drawn on the fly to the main part. There is no ”real” object behind
them. For example, the page’s scrollbar is not a real object, it’s just drawn when the page’s background is
drawn. The virtual parts always have the same state as the main part. If the property can be inherited, the
main part will be also considered before going to the parent.
The real parts are real objects created and managed by the main object. For example, the page’s scrollable
part is real object. Real parts can be in different state than the main part.
To see which parts an object has visit their documentation page.
Styles are stored in lv_style_t variables. Style variables should be static, global or dynamically
allocated. In other words they can not be local variables in functions which are destroyed when the
function exists. Before using a style it should be initialized with lv_style_init(&my_style). Af-
ter initializing the style properties can be set added to it. Property set functions looks like this:
lv_style_set_<property_name>(&style, <state>, <value>); For example the above men-
tioned example looks like this:
To get the value from style in a given state functions with the following prototype are available:
_lv_style_get_color/int/opa/ptr(&style, <prop>, <result buf>);. The best matching
property will be selected and it’s precedence will be returned. -1 will be returned if the property is not
found.
The form of the function (...color/int/opa/ptr) should beused according to the type of <prop>.
For example:
4.4. Styles 63
LVGL Documentation v7.8.0-dev
lv_color_t color;
int16_t res;
res = _lv_style_get_color(&style1, LV_STYLE_BG_COLOR | (LV_STATE_PRESSED << LV_STYLE_
,→STATE_POS), &color);
if(res >= 0) {
//the bg_color is loaded into `color`
}
lv_style_reset(&style);
A style on its own not that useful. It should be assigned to an object to take its effect. Every part of the
objects stores a style list which is the list of assigned styles.
To add a style to an object use lv_obj_add_style(obj, <part>, &style) For example:
In the object’s style lists, so-called local properties can be stored as well. It’s the same concept than
CSS’s <div style="color:red">. The local style is the same as a normal style, but it belongs only
to a given object and can not be shared with other objects. To set a local property use functions like
lv_obj_set_style_local_<property_name>(obj, <part>, <state>, <value>); For ex-
ample:
4.4. Styles 64
LVGL Documentation v7.8.0-dev
4.4.8 Transitions
By default, when an object changes state (e.g. it’s pressed) the new properties from the new state are set
immediately. However, with transitions it’s possible to play an animation on state change. For example, on
pressing a button its background color can be animated to the pressed color over 300 ms.
The parameters of the transitions are stored in the styles. It’s possible to set
• the time of the transition
• the delay before starting the transition
• the animation path (also known as timing function)
• the properties to animate
The transition properties can be defined for each state. For example, setting 500 ms transition time in
default state will mean that when the object goes to default state 500 ms transition time will be applied.
Setting 100 ms transition time in the pressed state will mean a 100 ms transition time when going to presses
state. So this example configuration will result in fast going to presses state and slow going back to default.
4.4.9 Properties
Mixed properties
4.4. Styles 65
LVGL Documentation v7.8.0-dev
Padding sets the space on the inner sides of the edges. It means ”I don’t want my children too close to my
sides, so keep this space”.Padding inner set the ”gap” between the children. Margin sets the space on the
outer side of the edges. It means ”I want this space around me”.
These properties are typically used by Container object if layout or auto fit is enabled. However other
widgets also use them to set spacing. See the documentation of the widgets for the details.
• pad_top (lv_style_int_t): Set the padding on the top. Default value: 0.
• pad_bottom (lv_style_int_t): Set the padding on the bottom. Default value: 0.
• pad_left (lv_style_int_t): Set the padding on the left. Default value: 0.
• pad_right (lv_style_int_t): Set the padding on the right. Default value: 0.
• pad_inner (lv_style_int_t): Set the padding inside the object between children. Default value:
0.
• margin_top (lv_style_int_t): Set the margin on the top. Default value: 0.
• margin_bottom (lv_style_int_t): Set the margin on the bottom. Default value: 0.
• margin_left (lv_style_int_t): Set the margin on the left. Default value: 0.
• margin_right (lv_style_int_t): Set the margin on the right. Default value: 0.
Background properties
The background is a simple rectangle which can have gradient and radius rounding.
• bg_color (lv_color_t) Specifies the color of the background. Default value: LV_COLOR_WHITE.
• bg_opa (lv_opa_t) Specifies opacity of the background. Default value: LV_OPA_TRANSP.
• bg_grad_color (lv_color_t) Specifies the color of the background’s gradient. The color on the
right or bottom is bg_grad_dir != LV_GRAD_DIR_NONE. Default value: LV_COLOR_WHITE.
• bg_main_stop (uint8_t): Specifies where should the gradient start. 0: at left/top most position,
255: at right/bottom most position. Default value: 0.
• bg_grad_stop (uint8_t): Specifies where should the gradient stop. 0: at left/top most position,
255: at right/bottom most position. Default value: 255.
• bg_grad_dir (lv_grad_dir_t) Specifies the direction of the gradient. Can be
LV_GRAD_DIR_NONE/HOR/VER. Default value: LV_GRAD_DIR_NONE.
• bg_blend_mode (lv_blend_mode_t): Set the blend mode the background. Can be
LV_BLEND_MODE_NORMAL/ADDITIVE/SUBTRACTIVE). Default value: LV_BLEND_MODE_NORMAL.
4.4. Styles 66
LVGL Documentation v7.8.0-dev
#include "../../lv_examples.h"
/**
* Using the background style properties
*/
void lv_ex_style_1(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
/*Make a gradient*/
lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER);
lv_style_set_bg_grad_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_style_set_bg_grad_dir(&style, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);
4.4. Styles 67
LVGL Documentation v7.8.0-dev
Border properties
#include "../../lv_examples.h"
/**
* Using the border style properties
*/
void lv_ex_style_2(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 68
LVGL Documentation v7.8.0-dev
Outline properties
#include "../../lv_examples.h"
/**
* Using the outline style properties
*/
void lv_ex_style_3(void)
(continues on next page)
4.4. Styles 69
LVGL Documentation v7.8.0-dev
/*Add outline*/
lv_style_set_outline_width(&style, LV_STATE_DEFAULT, 2);
lv_style_set_outline_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_style_set_outline_pad(&style, LV_STATE_DEFAULT, 8);
Shadow properties
4.4. Styles 70
LVGL Documentation v7.8.0-dev
#include "../../lv_examples.h"
/**
* Using the Shadow style properties
*/
void lv_ex_style_4(void)
{
static lv_style_t style;
lv_style_init(&style);
/*Add a shadow*/
lv_style_set_shadow_width(&style, LV_STATE_DEFAULT, 8);
lv_style_set_shadow_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE);
lv_style_set_shadow_ofs_x(&style, LV_STATE_DEFAULT, 10);
lv_style_set_shadow_ofs_y(&style, LV_STATE_DEFAULT, 20);
4.4. Styles 71
LVGL Documentation v7.8.0-dev
Pattern properties
The pattern is an image (or symbol) drawn in the middle of the background or repeated to fill the whole
background.
• pattern_image (const void *): Pointer to an lv_img_dsc_t variable, a path to an image file
or a symbol. Default value: NULL.
• pattern_opa (lv_opa_t): Specifies opacity of the pattern. Default value: LV_OPA_COVER.
• pattern_recolor (lv_color_t): Mix this color to the pattern image. In case of symbols (texts) it
will be the text color. Default value: LV_COLOR_BLACK.
• pattern_recolor_opa (lv_opa_t): Intensity of recoloring. Default value: LV_OPA_TRANSP (no
recoloring).
• pattern_repeat (bool): true: the pattern will be repeated as a mosaic. false: place the pattern
in the middle of the background. Default value: false.
• pattern_blend_mode (lv_blend_mode_t): Set the blend mode of the pattern. Can be
LV_BLEND_MODE_NORMAL/ADDITIVE/SUBTRACTIVE). Default value: LV_BLEND_MODE_NORMAL.
#include "../../lv_examples.h"
/**
* Using the pattern style properties
*/
void lv_ex_style_5(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 72
LVGL Documentation v7.8.0-dev
Value properties
Value is an arbitrary text drawn to the background. It can be a lightweighted replacement of creating label
objects.
• value_str (const char *): Pointer to text to display. Only the pointer is saved! (Don’t use
local variable with lv_style_set_value_str, instead use static, global or dynamically allocated data).
Default value: NULL.
• value_color (lv_color_t): Color of the text. Default value: LV_COLOR_BLACK.
• value_opa (lv_opa_t): Opacity of the text. Default value: LV_OPA_COVER.
• value_font (const lv_font_t *): Pointer to font of the text. Default value: NULL.
• value_letter_space (lv_style_int_t): Letter space of the text. Default value: 0.
• value_line_space (lv_style_int_t): Line space of the text. Default value: 0.
• value_align (lv_align_t): Alignment of the text. Can be LV_ALIGN_.... Default value:
LV_ALIGN_CENTER.
• value_ofs_x (lv_style_int_t): X offset from the original position of the alignment. Default
value: 0.
• value_ofs_y (lv_style_int_t): Y offset from the original position of the alignment. Default
value: 0.
• value_blend_mode (lv_blend_mode_t): Set the blend mode of the text. Can be
LV_BLEND_MODE_NORMAL/ADDITIVE/SUBTRACTIVE). Default value: LV_BLEND_MODE_NORMAL.
4.4. Styles 73
LVGL Documentation v7.8.0-dev
#include "../../lv_examples.h"
/**
* Using the value style properties
*/
void lv_ex_style_6(void)
{
static lv_style_t style;
lv_style_init(&style);
/*Add a value text to the local style. This way every object can have different␣
,→ text*/
lv_obj_set_style_local_value_str(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, "Text");
}
4.4. Styles 74
LVGL Documentation v7.8.0-dev
Text properties
#include "../../lv_examples.h"
/**
* Using the text style properties
*/
void lv_ex_style_7(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 75
LVGL Documentation v7.8.0-dev
Line properties
Properties of lines.
• line_color (lv_color_t): Color of the line. Default value: LV_COLOR_BLACK
• line_opa (lv_opa_t): Opacity of the line. Default value: LV_OPA_COVER
• line_width (lv_style_int_t): Width of the line. Default value: 0.
• line_dash_width (lv_style_int_t): Width of dash. Dashing is drawn only for horizontal or
vertical lines. 0: disable dash. Default value: 0.
• line_dash_gap (lv_style_int_t): Gap between two dash line. Dashing is drawn only for hori-
zontal or vertical lines. 0: disable dash. Default value: 0.
• line_rounded (bool): true: draw rounded line endings. Default value: false.
• line_blend_mode (lv_blend_mode_t): Set the blend mode of the line. Can be
LV_BLEND_MODE_NORMAL/ADDITIVE/SUBTRACTIVE). Default value: LV_BLEND_MODE_NORMAL.
4.4. Styles 76
LVGL Documentation v7.8.0-dev
#include "../../lv_examples.h"
/**
* Using the line style properties
*/
void lv_ex_style_8(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 77
LVGL Documentation v7.8.0-dev
Image properties
Properties of image.
• image_recolor (lv_color_t): Mix this color to the pattern image. In case of symbols (texts) it
will be the text color. Default value: LV_COLOR_BLACK
• image_recolor_opa (lv_opa_t): Intensity of recoloring. Default value: LV_OPA_TRANSP (no
recoloring). Default value: LV_OPA_TRANSP
• image_opa (lv_opa_t): Opacity of the image. Default value: LV_OPA_COVER
• image_blend_mode (lv_blend_mode_t): Set the blend mode of the image. Can be
LV_BLEND_MODE_NORMAL/ADDITIVE/SUBTRACTIVE). Default value: LV_BLEND_MODE_NORMAL.
#include "../../lv_examples.h"
/**
* Using the image style properties
*/
void lv_ex_style_9(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 78
LVGL Documentation v7.8.0-dev
Transition properties
4.4. Styles 79
LVGL Documentation v7.8.0-dev
#include "../../lv_examples.h"
/**
* Using the transitions style properties
*/
void lv_ex_style_10(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 80
LVGL Documentation v7.8.0-dev
Scale properties
Auxiliary properties for scale-like elements. Scales have a normal and end region. As the name implies the
end region is the end of the scale where can be critical values or inactive values. The normal region is before
the end region. Both regions could have different properties.
• scale_grad_color (lv_color_t): In normal region make gradient to this color on the scale lines.
Default value: LV_COLOR_BLACK.
• scale_end_color (lv_color_t): Color of the scale lines in the end region. Default value:
LV_COLOR_BLACK.
• scale_width (lv_style_int_t): Width of the scale. Default value: LV_DPI / 8. Default value:
LV_DPI / 8.
• scale_border_width (lv_style_int_t): Width of a border drawn on the outer side of the scale
in the normal region. Default value: 0.
• scale_end_border_width (lv_style_int_t): Width of a border drawn on the outer side of the
scale in the end region. Default value: 0.
• scale_end_line_width (lv_style_int_t): Width of a scale lines in the end region. Default
value: 0.
#include "../../lv_examples.h"
/**
* Using the scale style properties
*/
void lv_ex_style_11(void)
{
static lv_style_t style;
lv_style_init(&style);
4.4. Styles 81
LVGL Documentation v7.8.0-dev
/*Gauge has a needle but for simplicity its style is not initialized here*/
It the documentation of the widgets you will see sentences like ”The widget use the typical background
properties”. The ”typical background” properties are:
• Background
• Border
• Outline
• Shadow
• Pattern
• Value
4.4.10 Themes
Themes are a collection of styles. There is always an active theme whose styles are automatically applied
when an object is created. It gives a default appearance to UI which can be modified by adding further
styles.
The default theme is set in lv_conf.h with LV_THEME_... defines. Every theme has the following
properties
• primary color
• secondary color
• small font
• normal font
• subtitle font
• title font
• flags (specific to the given theme)
4.4. Styles 82
LVGL Documentation v7.8.0-dev
Extending themes
Built-in themes can be extended by custom theme. If a custom theme is created a ”base theme” can be
selected. The base theme’s styles will be added before the custom theme. Any number of themes can be
chained this was. E.g. material theme -> custom theme -> dark theme.
Here is an example about how to create a custom theme based on the currently active built-in theme.
/*Get the current theme (e.g. material). It will be the base of the custom theme.*/
lv_theme_t * base_theme = lv_theme_get_act();
...
switch(name) {
case LV_THEME_BTN:
list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN);
_lv_style_list_add_style(list, &my_style);
break;
}
}
4.4. Styles 83
LVGL Documentation v7.8.0-dev
4.4.11 Example
Styling a button
#include "../../lv_examples.h"
/**
* Create styles from scratch for buttons.
*/
void lv_ex_get_started_2(void)
{
static lv_style_t style_btn;
static lv_style_t style_btn_red;
/*Add a border*/
lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70);
lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2);
4.4. Styles 84
LVGL Documentation v7.8.0-dev
4.4. Styles 85
LVGL Documentation v7.8.0-dev
Important: Before reading further, please read the [Porting](/porting/indev) section of Input devices
4.5.1 Pointers
...
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
Note that the cursor object should have lv_obj_set_click(cursor_obj, false). For images, click-
ing is disabled by default.
You can fully control the user interface without touchpad or mouse using a keypad or encoder(s). It works
similar to the TAB key on the PC to select the element in an application or a web page.
Groups
The objects, you want to control with keypad or encoder, needs to be added to a Group. In every group,
there is exactly one focused object which receives the pressed keys or the encoder actions. For example, if
a Text area is focused and you press some letter on a keyboard, the keys will be sent and inserted into the
text area. Similarly, if a Slider is focused and you press the left or right arrows, the slider’s value will be
changed.
You need to associate an input device with a group. An input device can send the keys to only one group
but, a group can receive data from more than one input device too.
To create a group use lv_group_t * g = lv_group_create() and to add an object to the group use
lv_group_add_obj(g, obj).
To associate a group with an input device use lv_indev_set_group(indev, g), where indev is the
return value of lv_indev_drv_register()
Keys
Since a keypad has plenty of keys, it’s easy to navigate between the objects and edit them using the keypad.
But, the encoders have a limited number of ”keys” hence, it is difficult to navigate using the default options.
Navigate and Edit are created to avoid this problem with the encoders.
In Navigate mode, the encoders LV_KEY_LEFT/RIGHT is translated to LV_KEY_NEXT/PREV. Therefore
the next or previous object will be selected by turning the encoder. Pressing LV_KEY_ENTER will change
to Edit mode.
In Edit mode, LV_KEY_NEXT/PREV is usually used to edit the object. Depending on the object’s type, a
short or long press of LV_KEY_ENTER changes back to Navigate mode. Usually, an object which can not be
pressed (like a Slider) leaves Edit mode on short click. But with objects where short click has meaning (e.g.
Button), a long press is required.
Styling
If an object is focused either by clicking it via touchpad, or focused via an encoder or keypad it goes to
LV_STATE_FOCUSED. Hence focused styles will be applied on it.
If the object goes to edit mode it goes to LV_STATE_FOCUSED | LV_STATE_EDITED state so these style
properties will be shown.
For a more detaild description read the Style section.
4.5.3 API
Input device
Functions
void _lv_indev_init(void)
Initialize the display input device subsystem
void _lv_indev_read_task(lv_task_t *task)
Called periodically to read the input devices
Parameters
• task: pointer to the task itself
lv_indev_t *lv_indev_get_act(void)
Get the currently processed input device. Can be used in action functions too.
Return pointer to the currently processed input device or NULL if no input device processing right
now
lv_indev_type_t lv_indev_get_type(const lv_indev_t *indev)
Get the type of an input device
Return the type of the input device from lv_hal_indev_type_t (LV_INDEV_TYPE_...)
Parameters
• indev: pointer to an input device
void lv_indev_reset(lv_indev_t *indev, lv_obj_t *obj)
Reset one or all input devices
Parameters
• indev: pointer to an input device to reset or NULL to reset all of them
• obj: pointer to an object which triggers the reset.
void lv_indev_reset_long_press(lv_indev_t *indev)
Reset the long press state of an input device
Parameters
• indev_proc: pointer to an input device
void lv_indev_enable(lv_indev_t *indev, bool en)
Enable or disable an input devices
Parameters
• indev: pointer to an input device
• en: true: enable; false: disable
void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj)
Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and
LV_INPUT_TYPE_BUTTON)
Parameters
• indev: pointer to an input device
• cur_obj: pointer to an object to be used as cursor
void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group)
Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD)
Parameters
• indev: pointer to an input device
• group: point to a group
void lv_indev_set_button_points(lv_indev_t *indev, const lv_point_t points[])
Set the an array of points for LV_INDEV_TYPE_BUTTON. These points will be assigned to the
buttons to press a specific point on the screen
Parameters
• indev: pointer to an input device
• group: point to a group
void lv_indev_get_point(const lv_indev_t *indev, lv_point_t *point)
Get the last point of an input device (for LV_INDEV_TYPE_POINTER and
LV_INDEV_TYPE_BUTTON)
Parameters
• indev: pointer to an input device
• point: pointer to a point to store the result
lv_gesture_dir_t lv_indev_get_gesture_dir(const lv_indev_t *indev)
Get the current gesture direct
Return current gesture direct
Parameters
Parameters
• indev: pointer to an inout device
Groups
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_KEY_UP = 17
enumerator LV_KEY_DOWN = 18
enumerator LV_KEY_RIGHT = 19
enumerator LV_KEY_LEFT = 20
enumerator LV_KEY_ESC = 27
enumerator LV_KEY_DEL = 127
enumerator LV_KEY_BACKSPACE = 8
enumerator LV_KEY_ENTER = 10
enumerator LV_KEY_NEXT = 9
enumerator LV_KEY_PREV = 11
enumerator LV_KEY_HOME = 2
enumerator LV_KEY_END = 3
enum [anonymous]
Values:
enumerator LV_GROUP_REFOCUS_POLICY_NEXT = 0
enumerator LV_GROUP_REFOCUS_POLICY_PREV = 1
Functions
void _lv_group_init(void)
Init. the group module
Remark Internal function, do not call directly.
lv_group_t *lv_group_create(void)
Create a new object group
Return pointer to the new object group
void lv_group_del(lv_group_t *group)
Delete a group object
Parameters
• group: pointer to a group
void lv_group_add_obj(lv_group_t *group, lv_obj_t *obj)
Add an object to a group
Parameters
• group: pointer to a group
• obj: pointer to an object to add
void lv_group_remove_obj(lv_obj_t *obj)
Remove an object from its group
Parameters
• obj: pointer to an object to remove
void lv_group_remove_all_objs(lv_group_t *group)
Remove all objects from a group
Parameters
• group: pointer to a group
void lv_group_focus_obj(lv_obj_t *obj)
Focus on an object (defocus the current)
Parameters
• obj: pointer to an object to focus on
void lv_group_focus_next(lv_group_t *group)
Focus the next object in a group (defocus the current)
Parameters
• group: pointer to a group
void lv_group_focus_prev(lv_group_t *group)
Focus the previous object in a group (defocus the current)
Parameters
• group: pointer to a group
void lv_group_focus_freeze(lv_group_t *group, bool en)
Do not let to change the focus from the current object
Parameters
Public Members
lv_ll_t obj_ll
Linked list to store the objects in the group
lv_obj_t **obj_focus
The object in focus
lv_group_focus_cb_t focus_cb
A function to call when a new object is focused (optional)
lv_group_user_data_t user_data
uint8_t frozen
1: can’t focus to new object
uint8_t editing
1: Edit mode, 0: Navigate mode
uint8_t click_focus
1: If an object in a group is clicked by an indev then it will be focused
uint8_t refocus_policy
1: Focus prev if focused on deletion. 0: Focus next if focused on deletion.
uint8_t wrap
1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.
4.6 Displays
Important: The basic concept of display in LVGL is explained in the [Porting](/porting/display) section.
So before reading further, please read the [Porting](/porting/display) section first.
In LVGL, you can have multiple displays, each with their own driver and objects. The only limitation is
that every display needs to be have same color depth (as defined in LV_COLOR_DEPTH). If the displays are
different in this regard the rendered image can be converted to the correct format in the drivers flush_cb.
Creating more displays is easy: just initialize more display buffers and register another driver for every
display. When you create the UI, use lv_disp_set_default(disp) to tell the library on which display
to create objects.
Why would you want multi-display support? Here are some examples:
• Have a ”normal” TFT display with local UI and create ”virtual” screens on VNC on demand. (You
need to add your VNC driver).
• Have a large TFT display and a small monochrome display.
• Have some smaller and simple displays in a large instrument or technology.
• Have two large TFT displays: one for a customer and one for the shop assistant.
Using more displays can be useful, but in most cases, it’s not required. Therefore, the whole concept of
multi-display is completely hidden if you register only one display. By default, the lastly created (the only
one) display is used as default.
lv_scr_act(), lv_scr_load(scr), lv_layer_top(), lv_layer_sys(), LV_HOR_RES and
LV_VER_RES are always applied on the lastly created (default) screen. If you pass NULL as
disp parameter to display related function, usually the default display will be used. E.g.
lv_disp_trig_activity(NULL) will trigger a user activity on the default screen. (See below in In-
activity).
4.6. Displays 95
LVGL Documentation v7.8.0-dev
Mirror display
To mirror the image of the display to another display, you don’t need to use the multi-display support. Just
transfer the buffer received in drv.flush_cb to another display too.
Split image
You can create a larger display from smaller ones. You can create it as below:
1. Set the resolution of the displays to the large display’s resolution.
2. In drv.flush_cb, truncate and modify the area parameter for each display.
3. Send the buffer’s content to each display with the truncated area.
4.6.2 Screens
Every display has each set of Screens and the object on the screens.
Be sure not to confuse displays and screens:
• Displays are the physical hardware drawing the pixels.
• Screens are the high-level root objects associated with a particular display. One display can have
multiple screens associated with it, but not vice versa.
Screens can be considered the highest level containers which have no parent. The screen’s size is always
equal to its display and size their position is (0;0). Therefore, the screens coordinates can’t be changed, i.e.
lv_obj_set_pos(), lv_obj_set_size() or similar functions can’t be used on screens.
A screen can be created from any object type but, the two most typical types are the Base object and the
Image (to create a wallpaper).
To create a screen, use lv_obj_t * scr = lv_<type>_create(NULL, copy). copy can be an other
screen to copy it.
To load a screen, use lv_scr_load(scr). To get the active screen, use lv_scr_act(). These
functions works on the default display. If you want to to specify which display to work on, use
lv_disp_get_scr_act(disp) and lv_disp_load_scr(disp, scr).
Screens can be deleted with lv_obj_del(scr), but ensure that you do not delete the currently loaded
screen.
Transparent screens
Usually, the opacity of the screen is LV_OPA_COVER to provide a solid background for its children. If it’s
not the case (opacity < 100%) the display’s background color or image will be visible. See the Display
background section for more details. If the display’s background opacity is also not LV_OPA_COVER LVGL
has no solid background to draw.
This configuration (transparent screen ans display) could be used to create for example OSD menus where
a video is played to lower layer, and menu is created on an upper layer.
To handle transparent displays special (slower) color mixing algorithms needs to be used by LVGL so this
feature needs to enabled with LV_COLOR_SCREEN_TRANSP n lv_conf.h. As this mode operates on the
Alpha channel of the pixels LV_COLOR_DEPTH = 32 is also required. The Alpha channel of 32-bit colors
will be 0 where there are no objects and will be 255 where there are solid objects.
In summary, to enable transparent screen and displays to create OSD menu-like UIs:
4.6. Displays 96
LVGL Documentation v7.8.0-dev
Inactivity
The user’s inactivity is measured on each display. Every use of an Input device (if associ-
ated with the display) counts as an activity. To get time elapsed since the last activity, use
lv_disp_get_inactive_time(disp). If NULL is passed, the overall smallest inactivity time will be
returned from all displays (not the default display).
You can manually trigger an activity using lv_disp_trig_activity(disp). If disp is NULL, the
default screen will be used (and not all displays).
Background
Every display has background color, a background image and background opacity properties. They become
visible when the current screen is transparent or not positioned to cover the whole display.
Background color is a simple color to fill the display. It can be adjusted with
lv_disp_set_bg_color(disp, color);
Background image is path to file or pointer to an lv_img_dsc_t variable (converted image) to be used as
wallpaper. It can be set with lv_disp_set_bg_color(disp, &my_img); If the background image is
set (not NULL) the background won’t filled with bg_color.
The opacity of the background color or image can be adjusted with lv_disp_set_bg_opa(disp, opa).
The disp parameter of these functions can be NULL to refer it to the default display.
4.6.4 Colors
The color module handles all color-related functions like changing color depth, creating colors from hex code,
converting between color depths, mixing colors, etc.
The following variable types are defined by the color module:
• lv_color1_t Store monochrome color. For compatibility, it also has R, G, B fields but they are
always the same value (1 byte)
• lv_color8_t A structure to store R (3 bit),G (3 bit),B (2 bit) components for 8-bit colors (1 byte)
• lv_color16_t A structure to store R (5 bit),G (6 bit),B (5 bit) components for 16-bit colors (2 byte)
• lv_color32_t A structure to store R (8 bit),G (8 bit), B (8 bit) components for 24-bit colors (4 byte)
• lv_color_t Equal to lv_color1/8/16/24_t according to color depth settings
• lv_color_int_t uint8_t, uint16_t or uint32_t according to color depth setting. Used to build
color arrays from plain numbers.
4.6. Displays 97
LVGL Documentation v7.8.0-dev
Convert color
You can convert a color from the current color depth to another. The converter functions return with a
number, so you have to use the full field:
lv_color_t c;
c.red = 0x38;
c.green = 0x70;
c.blue = 0xCC;
lv_color1_t c1;
c1.full = lv_color_to1(c); /*Return 1 for light colors, 0 for dark colors*/
lv_color8_t c8;
c8.full = lv_color_to8(c); /*Give a 8 bit number with the converted color*/
lv_color16_t c16;
c16.full = lv_color_to16(c); /*Give a 16 bit number with the converted color*/
lv_color32_t c24;
c32.full = lv_color_to32(c); /*Give a 32 bit number with the converted color*/
Swap 16 colors
You may set LV_COLOR_16_SWAP in lv_conf.h to swap the bytes of RGB565 colors. It’s useful if you send
the 16-bit colors via a byte-oriented interface like SPI.
As 16-bit numbers are stored in Little Endian format (lower byte on the lower address), the interface will
send the lower byte first. However, displays usually need the higher byte first. A mismatch in the byte order
will result in highly distorted colors.
4.6. Displays 98
LVGL Documentation v7.8.0-dev
You can create colors with the current color depth using the LV_COLOR_MAKE macro. It takes 3
arguments (red, green, blue) as 8-bit numbers. For example to create light red color: my_color =
COLOR_MAKE(0xFF,0x80,0x80).
Colors can be created from HEX codes too: my_color = lv_color_hex(0x288ACF) or my_color =
lv_folro_hex3(0x28C).
Mixing two colors is possible with mixed_color = lv_color_mix(color1, color2, ratio). Ra-
tion can be 0..255. 0 results fully color2, 255 result fully color1.
Colors can be created with from HSV space too using lv_color_hsv_to_rgb(hue, saturation,
value) . hue should be in 0..360 range, saturation and value in 0..100 range.
Opacity
To describe opacity the lv_opa_t type is created as a wrapper to uint8_t. Some defines are also intro-
duced:
• LV_OPA_TRANSP Value: 0, means the opacity makes the color completely transparent
• LV_OPA_10 Value: 25, means the color covers only a little
• LV_OPA_20 ... OPA_80 come logically
• LV_OPA_90 Value: 229, means the color near completely covers
• LV_OPA_COVER Value: 255, means the color completely covers
You can also use the LV_OPA_* defines in lv_color_mix() as a ratio.
Built-in colors
The color module defines the most basic colors such as:
• LV_COLOR_WHITE
• LV_COLOR_BLACK
• LV_COLOR_GRAY
• LV_COLOR_SILVER
• LV_COLOR_RED
• LV_COLOR_MAROON
• LV_COLOR_LIME
• LV_COLOR_GREEN
• LV_COLOR_OLIVE
• LV_COLOR_BLUE
• LV_COLOR_NAVY
• LV_COLOR_TEAL
• LV_COLOR_CYAN
4.6. Displays 99
LVGL Documentation v7.8.0-dev
• LV_COLOR_AQUA
• LV_COLOR_PURPLE
• LV_COLOR_MAGENTA
• LV_COLOR_ORANGE
• LV_COLOR_YELLOW
as well as LV_COLOR_WHITE (fully white).
4.6.5 API
Display
Enums
enum lv_scr_load_anim_t
Values:
enumerator LV_SCR_LOAD_ANIM_NONE
enumerator LV_SCR_LOAD_ANIM_OVER_LEFT
enumerator LV_SCR_LOAD_ANIM_OVER_RIGHT
enumerator LV_SCR_LOAD_ANIM_OVER_TOP
enumerator LV_SCR_LOAD_ANIM_OVER_BOTTOM
enumerator LV_SCR_LOAD_ANIM_MOVE_LEFT
enumerator LV_SCR_LOAD_ANIM_MOVE_RIGHT
enumerator LV_SCR_LOAD_ANIM_MOVE_TOP
enumerator LV_SCR_LOAD_ANIM_MOVE_BOTTOM
enumerator LV_SCR_LOAD_ANIM_FADE_ON
Functions
Colors
Typedefs
Enums
enum [anonymous]
Opacity percentages.
Values:
enumerator LV_OPA_TRANSP = 0
enumerator LV_OPA_0 = 0
enumerator LV_OPA_10 = 25
enumerator LV_OPA_20 = 51
enumerator LV_OPA_30 = 76
enumerator LV_OPA_40 = 102
enumerator LV_OPA_50 = 127
enumerator LV_OPA_60 = 153
enumerator LV_OPA_70 = 178
enumerator LV_OPA_80 = 204
enumerator LV_OPA_90 = 229
enumerator LV_OPA_100 = 255
enumerator LV_OPA_COVER = 255
Functions
Public Members
uint8_t blue
uint8_t green
uint8_t red
union lv_color1_t::[anonymous] ch
uint8_t full
union lv_color8_t
Public Members
uint8_t blue
uint8_t green
uint8_t red
struct lv_color8_t::[anonymous] ch
uint8_t full
union lv_color16_t
Public Members
uint16_t blue
uint16_t green
uint16_t red
uint16_t green_h
uint16_t green_l
struct lv_color16_t::[anonymous] ch
uint16_t full
union lv_color32_t
Public Members
uint8_t blue
uint8_t green
uint8_t red
uint8_t alpha
struct lv_color32_t::[anonymous] ch
uint32_t full
struct lv_color_hsv_t
Public Members
uint16_t h
uint8_t s
uint8_t v
4.7 Fonts
In LVGL fonts are collections of bitmaps and other information required to render the images of the letters
(glyph). A font is stored in a lv_font_t variable and can be set in style’s text_font field. For example:
The fonts have a bpp (bits per pixel) property. It shows how many bits are used to describe a pixel in
the font. The value stored for a pixel determines the pixel’s opacity. This way, with higher bpp, the edges of
the letter can be smoother. The possible bpp values are 1, 2, 4 and 8 (higher value means better quality).
The bpp also affects the required memory size to store the font. For example, bpp = 4 makes the font nearly
4 times greater compared to bpp = 1.
LVGL supports UTF-8 encoded Unicode characters. Your editor needs to be configureed to save your
code/text as UTF-8 (usually this the default) and be sure that, LV_TXT_ENC is set to LV_TXT_ENC_UTF8
in lv_conf.h. (This is the default value)
To test it try
There are several built-in fonts in different sizes, which can be enabled in lv_conf.h by LV_FONT_...
defines:
• LV_FONT_MONTSERRAT_12 12 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_14 14 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_16 16 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_18 18 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_20 20 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_22 22 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_24 24 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_26 26 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_28 28 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_30 30 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_32 32 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_34 34 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_36 36 px ASCII + built-in symbol
• LV_FONT_MONTSERRAT_38 38 px ASCII + built-in symbol
lv_label_set_text(my_label, LV_SYMBOL_OK);
Bidirectional support
Most of the languages use Left-to-Right (LTR for short) writing direction, however some languages (such as
Hebrew, Persian or Arabic) uses Right-to-Left (RTL for short) direction.
LVGL not only supports RTL texts but supports mixed (a.k.a. bidirectional, BiDi) text rendering too. Some
examples:
There are some special rules to display Arabic and Persian characters: the form of the character depends on
their position in the text. A different form of the same letter needs to be used if it isolated, start, middle or
end position. Besides these some conjunction rules also should be taken into account.
LVGL supports to apply these rules if LV_USE_ARABIC_PERSIAN_CHARS is enabled.
However, there some limitations:
• Only displaying texts is supported (e.g. on labels), text inputs (e.g. text area) doesn’t support this
feature
• Static text (i.e. const) are not processed. E.g. texts set by lv_label_set_text() will ”Arabic
processed” but lv_lable_set_text_static() won’t.
• Text get functions (e.g. lv_label_get_text()) will return the processed text.
Subpixel rendering
Subpixel rendering means to triple the horizontal resolution by rendering on Red, Green and Blue channel
instead of pixel level. It takes advantage of the position of physical color channels of each pixel. It results in
higher quality letter anti-aliasing. Lear more here.
Subpixel rendering requires to generate the fonts with special settings:
• In the online converter tick the Subpixel box
• In the command line tool use --lcd flag. Note that the generated font needs about 3 times more
memory.
Subpixel rendering works only if the color channels of the pixels have a horizontal layout. That is the R, G,
B channels are next each other and not above each other. The order of color channels also needs to match
with the library settings. By default the LVGL assumes RGB order, however it can be swapped by setting
LV_SUBPX_BGR 1 in lv_conf.h.
Compress fonts
LVGL’s font interface is designed to be very flexible. You don’t need to use LVGL’s internal font engine
but, you can add your own. For example, use FreeType to real-time render glyphs from TTF fonts or use
an external flash to store the font’s bitmap and read them when the library needs them.
A raedy to use FreeType can be found in lv_freetype repository.
To do this a custom lv_font_t variable needs to be created:
...
*/
bool my_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out,␣
,→uint32_t unicode_letter, uint32_t unicode_letter_next)
{
/*Your code here*/
return true; /*true: glyph found; false: glyph was not found*/
}
{
/* Your code here */
4.8 Images
An image can be a file or variable which stores the bitmap itself and some metadata.
Variables
The images stored internally in a variable is composed mainly of an lv_img_dsc_t structure with the
following fields:
• header
– cf Color format. See below
– w width in pixels (<= 2048)
– h height in pixels (<= 2048)
– always zero 3 bits which need to be always zero
– reserved reserved for future use
• data pointer to an array where the image itself is stored
• data_size length of data in bytes
These are usually stored within a project as C files. They are linked into the resulting executable like any
other constant data.
Files
To deal with files you need to add a Drive to LVGL. In short, a Drive is a collection of functions (open, read,
close, etc.) registered in LVGL to make file operations. You can add an interface to a standard file system
(FAT32 on SD card) or you create your simple file system to read data from an SPI Flash memory. In every
case, a Drive is just an abstraction to read and/or write data to a memory. See the File system section to
learn more.
Images stored as files are not linked into the resulting executable, and must be read to RAM before being
drawn. As a result, they are not as resource-friendly as variable images. However, they are easier to replace
without needing to recompile the main program.
Online converter
If you are generating an image at run-time, you can craft an image variable to display it using LVGL. For
example:
Use images
The simplest way to use an image in LVGL is to display it with an lv_img object:
/*From variable*/
lv_img_set_src(icon, &my_icon_dsc);
/*From file*/
lv_img_set_src(icon, "S:my_icon.bin");
If the image was converted with the online converter, you should use LV_IMG_DECLARE(my_icon_dsc)
to declare the image in the file where you want to use it.
As you can see in the Color formats section, LVGL supports several built-in image formats. In many cases,
these will be all you need. LVGL doesn’t directly support, however, generic image formats like PNG or JPG.
To handle non-built-in image formats, you need to use external libraries and attach them to LVGL via the
Image decoder interface.
The image decoder consists of 4 callbacks:
• info get some basic info about the image (width, height and color format).
• open open the image: either store the decoded image or set it to NULL to indicate the image can be
read line-by-line.
• read if open didn’t fully open the image this function should give some decoded data (max 1 line)
from a given position.
• close close the opened image, free the allocated resources.
You can add any number of image decoders. When an image needs to be drawn, the library will try all the
registered image decoder until finding one which can open the image, i.e. knowing that format.
The LV_IMG_CF_TRUE_COLOR_..., LV_IMG_INDEXED_... and LV_IMG_ALPHA_... formats (essen-
tially, all non-RAW formats) are understood by the built-in decoder.
The easiest way to create a custom image is to use the online image converter and set Raw, Raw with
alpha or Raw with chrome keyed format. It will just take every byte of the binary file you uploaded
and write it as the image ”bitmap”. You then need to attach an image decoder that will parse that bitmap
and generate the real, renderable bitmap.
header.cf will be LV_IMG_CF_RAW, LV_IMG_CF_RAW_ALPHA or LV_IMG_CF_RAW_CHROME_KEYED
accordingly. You should choose the correct format according to your needs: fully opaque image, use alpha
channel or use chroma keying.
After decoding, the raw formats are considered True color by the library. In other words, the image decoder
must decode the Raw images to True color according to the format described in [#color-formats](Color
formats) section.
If you want to create a custom image, you should use LV_IMG_CF_USER_ENCODED_0..7 color formats.
However, the library can draw the images only in True color format (or Raw but finally it’s supposed to
be in True color format). So the LV_IMG_CF_USER_ENCODED_... formats are not known by the library,
therefore, they should be decoded to one of the known formats from [#color-formats](Color formats) section.
It’s possible to decode the image to a non-true color format first, for example, LV_IMG_INDEXED_4BITS,
and then call the built-in decoder functions to convert it to True color.
With User encoded formats, the color format in the open function (dsc->header.cf) should be changed
according to the new format.
/**
* Get info about a PNG image
* @param decoder pointer to the decoder where this function belongs
* @param src can be file name or pointer to a C array
* @param header store the info here
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info
*/
static lv_res_t decoder_info(lv_img_decoder_t * decoder, const void * src, lv_img_
,→header_t * header)
{
/*Check whether the type `src` is known by the decoder*/
if(is_png(src) == false) return LV_RES_INV;
header->cf = LV_IMG_CF_RAW_ALPHA;
header->w = width;
header->h = height;
}
/**
* Open a PNG image and return the decided image
* @param decoder pointer to the decoder where this function belongs
* @param dsc pointer to a descriptor which describes this decoding session
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info
*/
static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{
return res;
}
/**
* Decode `len` pixels starting from the given `x`, `y` coordinates and store them in␣
,→`buf`.
* Required only if the "open" function can't open the whole decoded pixel array.␣
,→(dsc->img_data == NULL)
{
/*With PNG it's usually not required*/
/*Copy `len` pixels from `x` and `y` coordinates in True color format to `buf` */
/**
* Free the allocated resources
* @param decoder pointer to the decoder where this function belongs
* @param dsc pointer to a descriptor which describes this decoding session
*/
static void decoder_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{
/*Free all allocated data*/
/*Call the built-in close function if the built-in open/read_line was used*/
lv_img_decoder_built_in_close(decoder, dsc);
So in summary:
• In decoder_info, you should collect some basic information about the image and store it in header.
• In decoder_open, you should try to open the image source pointed by dsc->src. Its type is already
in dsc->src_type == LV_IMG_SRC_FILE/VARIABLE. If this format/type is not supported by the
decoder, return LV_RES_INV. However, if you can open the image, a pointer to the decoded True color
image should be set in dsc->img_data. If the format is known but, you don’t want to decode while
image (e.g. no memory for it) set dsc->img_data = NULL to call read_line to get the pixels.
LVGL will use the registered image decoder automatically if you try and draw a raw image (i.e. using
the lv_img object) but you can use them manually too. Create a lv_img_decoder_dsc_t variable to
describe the decoding session and call lv_img_decoder_open().
lv_res_t res;
lv_img_decoder_dsc_t dsc;
res = lv_img_decoder_open(&dsc, &my_img_dsc, LV_COLOR_WHITE);
if(res == LV_RES_OK) {
/*Do something with `dsc->img_data`*/
lv_img_decoder_close(&dsc);
}
Sometimes it takes a lot of time to open an image. Continuously decoding a PNG image or loading images
from a slow external memory would be inefficient and detrimental to the user experience.
Therefore, LVGL caches a given number of images. Caching means some images will be left open, hence
LVGL can quickly access them from dsc->img_data instead of needing to decode them again.
Of course, caching images is resource-intensive as it uses more RAM (to store the decoded image). LVGL
tries to optimize the process as much as possible (see below), but you will still need to evaluate if this would
be beneficial for your platform or not. If you have a deeply embedded target which decodes small images
from a relatively fast storage medium, image caching may not be worth it.
Cache size
The number of cache entries can be defined in LV_IMG_CACHE_DEF_SIZE in lv_conf.h. The default value
is 1 so only the most recently used image will be left open.
The size of the cache can be changed at run-time with lv_img_cache_set_size(entry_num).
Value of images
When you use more images than cache entries, LVGL can’t cache all of the images. Instead, the library will
close one of the cached images (to free space).
To decide which image to close, LVGL uses a measurement it previously made of how long it took to open
the image. Cache entries that hold slower-to-open images are considered more valuable and are kept in the
cache as long as possible.
If you want or need to override LVGL’s measurement, you can manually set the time to open value in the
decoder open function in dsc->time_to_open = time_ms to give a higher or lower value. (Leave it
unchanged to let LVGL set it.)
Every cache entry has a ”life” value. Every time an image opening happens through the cache, the life of
all entries are decreased to make them older. When a cached image is used, its life is increased by the time
to open value to make it more alive.
If there is no more space in the cache, always the entry with the smallest life will be closed.
Memory usage
Note that, the cached image might continuously consume memory. For example, if 3 PNG images are cached,
they will consume memory while they are opened.
Therefore, it’s the user’s responsibility to be sure there is enough RAM to cache, even the largest images at
the same time.
Let’s say you have loaded a PNG image into a lv_img_dsc_t my_png variable and use it in an lv_img
object. If the image is already cached and you then change the underlying PNG file, you need to notify LVGL
to cache the image again. Otherwise, there is no easy way of detecting that the underlying file changed and
LVGL will still draw the old image.
To do this, use lv_img_cache_invalidate_src(&my_png). If NULL is passed as a parameter, the
whole cache will be cleaned.
4.8.6 API
Image decoder
Typedefs
Enums
enum [anonymous]
Source of image.
Values:
enumerator LV_IMG_SRC_VARIABLE
enumerator LV_IMG_SRC_FILE
Binary/C variable
enumerator LV_IMG_SRC_SYMBOL
File in filesystem
enumerator LV_IMG_SRC_UNKNOWN
Symbol (lv_symbol_def.h)
Functions
void _lv_img_decoder_init(void)
Initialize the image decoder module
lv_res_t lv_img_decoder_get_info(const char *src, lv_img_header_t *header)
Get information about an image. Try the created image decoder one by one. Once one is able to get
info that info will be used.
Return LV_RES_OK: success; LV_RES_INV: wasn’t able to get info about the image
Parameters
• src: the image source. Can be 1) File name: E.g. ”S:folder/img1.png” (The drivers needs
to registered via lv_fs_add_drv()) 2) Variable: Pointer to an lv_img_dsc_t variable
3) Symbol: E.g. LV_SYMBOL_OK
• header: the image info will be stored here
lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t *dsc, const void *src, lv_color_t color)
Open an image. Try the created image decoder one by one. Once one is able to open the image that
decoder is save in dsc
Return LV_RES_OK: opened the image. dsc->img_data and dsc->header are set.
LV_RES_INV: none of the registered image decoders were able to open the image.
Parameters
• dsc: describe a decoding session. Simply a pointer to an lv_img_decoder_dsc_t variable.
• src: the image source. Can be 1) File name: E.g. ”S:folder/img1.png” (The drivers needs
to registered via lv_fs_add_drv()) 2) Variable: Pointer to an lv_img_dsc_t variable
3) Symbol: E.g. LV_SYMBOL_OK
• color: The color of the image with LV_IMG_CF_ALPHA_...
lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t *dsc, lv_coord_t x, lv_coord_t
y, lv_coord_t len, uint8_t *buf )
Read a line from an opened image
Return LV_RES_OK: success; LV_RES_INV: an error occurred
Parameters
• dsc: pointer to lv_img_decoder_dsc_t used in lv_img_decoder_open
• x: start X coordinate (from left)
• y: start Y coordinate (from top)
• len: number of pixels to read
• buf: store the data here
void lv_img_decoder_close(lv_img_decoder_dsc_t *dsc)
Close a decoding session
Parameters
• dsc: pointer to lv_img_decoder_dsc_t used in lv_img_decoder_open
lv_img_decoder_t *lv_img_decoder_create(void)
Create a new image decoder
Return pointer to the new image decoder
Parameters
• decoder: the decoder where this function belongs
• dsc: pointer to decoder descriptor. src, style are already initialized in it.
lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t *decoder,
lv_img_decoder_dsc_t *dsc, lv_coord_t
x, lv_coord_t y, lv_coord_t len, uint8_t
*buf )
Decode len pixels starting from the given x, y coordinates and store them in buf. Required only if
the ”open” function can’t return with the whole decoded pixel array.
Return LV_RES_OK: ok; LV_RES_INV: failed
Parameters
• decoder: pointer to the decoder the function associated with
• dsc: pointer to decoder descriptor
• x: start x coordinate
• y: start y coordinate
• len: number of pixels to decode
• buf: a buffer to store the decoded pixels
void lv_img_decoder_built_in_close(lv_img_decoder_t *decoder, lv_img_decoder_dsc_t
*dsc)
Close the pending decoding. Free resources etc.
Parameters
• decoder: pointer to the decoder the function associated with
• dsc: pointer to decoder descriptor
struct _lv_img_decoder
Public Members
lv_img_decoder_info_f_t info_cb
lv_img_decoder_open_f_t open_cb
lv_img_decoder_read_line_f_t read_line_cb
lv_img_decoder_close_f_t close_cb
lv_img_decoder_user_data_t user_data
struct _lv_img_decoder_dsc
#include <lv_img_decoder.h> Describe an image decoding session. Stores data about the decoding
Public Members
lv_img_decoder_t *decoder
The decoder which was able to open the image source
const void *src
The image source. A file path like ”S:my_img.png” or pointer to an lv_img_dsc_t variable
lv_color_t color
Style to draw the image.
lv_img_src_t src_type
Type of the source: file or variable. Can be set in open function if required
lv_img_header_t header
Info about the opened image: color format, size, etc. MUST be set in open function
const uint8_t *img_data
Pointer to a buffer where the image’s data (pixels) are stored in a decoded, plain format. MUST
be set in open function
uint32_t time_to_open
How much time did it take to open the image. [ms] If not set lv_img_cache will measure and
set the time to open
const char *error_msg
A text to display instead of the image when the image can’t be opened. Can be set in open
function or set NULL.
void *user_data
Store any custom data here is required
Image cache
Functions
Parameters
• src: an image source path to a file or pointer to an lv_img_dsc_t variable.
struct lv_img_cache_entry_t
#include <lv_img_cache.h> When loading images from the network it can take a long time to down-
load and decode the image.
To avoid repeating this heavy load images can be cached.
Public Members
lv_img_decoder_dsc_t dec_dsc
Image information
int32_t life
Count the cache entries’s life. Add time_tio_open to life when the entry is used. Decrement
all lifes by one every in every ::lv_img_cache_open. If life == 0 the entry can be reused
LVGL has a ’File system’ abstraction module that enables you to attach any type of file systems. The file
system is identified by a drive letter. For example, if the SD card is associated with the letter 'S', a file
can be reached like "S:path/to/file.txt".
lv_fs_drv_t drv;
lv_fs_drv_init(&drv); /*Basic initialization*/
Any of the callbacks can be NULL to indicate that that operation is not supported.
As an example of how the callbacks are used, if you use lv_fs_open(&file, "S:/folder/file.txt",
LV_FS_MODE_WR), LVGL:
1. Verifies that a registered drive exists with the letter 'S'.
2. Checks if it’s open_cb is implemented (not NULL).
3. Calls the set open_cb with "folder/file.txt" path.
uint32_t read_num;
uint8_t buf[8];
res = lv_fs_read(&f, buf, 8, &read_num);
if(res != LV_FS_RES_OK || read_num != 8) my_error_handling();
lv_fs_close(&f);
char fn[256];
while(1) {
res = lv_fs_dir_read(&dir, fn);
if(res != LV_FS_RES_OK) {
my_error_handling();
break;
}
printf("%s\n", fn);
}
lv_fs_dir_close(&dir);
Image objects can be opened from files too (besides variables stored in the flash).
To initialize the image, the following callbacks are required:
• open
• close
• read
• seek
• tell
4.9.4 API
Typedefs
Enums
enum [anonymous]
Errors in the file system module.
Values:
enumerator LV_FS_RES_OK = 0
enumerator LV_FS_RES_HW_ERR
enumerator LV_FS_RES_FS_ERR
enumerator LV_FS_RES_NOT_EX
enumerator LV_FS_RES_FULL
enumerator LV_FS_RES_LOCKED
enumerator LV_FS_RES_DENIED
enumerator LV_FS_RES_BUSY
enumerator LV_FS_RES_TOUT
enumerator LV_FS_RES_NOT_IMP
enumerator LV_FS_RES_OUT_OF_MEM
enumerator LV_FS_RES_INV_PARAM
enumerator LV_FS_RES_UNKNOWN
enum [anonymous]
Filesystem mode.
Values:
enumerator LV_FS_MODE_WR = 0x01
enumerator LV_FS_MODE_RD = 0x02
Functions
void _lv_fs_init(void)
Initialize the File system interface
void lv_fs_drv_init(lv_fs_drv_t *drv)
Initialize a file system driver with default values. It is used to surly have known values in the fields
ant not memory junk. After it you can set the fields.
Parameters
• drv: pointer to driver variable to initialize
void lv_fs_drv_register(lv_fs_drv_t *drv_p)
Add a new drive
Parameters
• drv_p: pointer to an lv_fs_drv_t structure which is inited with the corresponding function
pointers. The data will be copied so the variable can be local.
lv_fs_drv_t *lv_fs_get_drv(char letter)
Give a pointer to a driver from its letter
Return pointer to a driver or NULL if not found
Parameters
• letter: the driver letter
bool lv_fs_is_ready(char letter)
Test if a drive is ready or not. If the ready function was not initialized true will be returned.
Return true: drive is ready; false: drive is not ready
Parameters
• letter: letter of the drive
lv_fs_res_t lv_fs_open(lv_fs_file_t *file_p, const char *path, lv_fs_mode_t mode)
Open a file
Return LV_FS_RES_OK or any error from lv_fs_res_t enum
Parameters
• file_p: pointer to a lv_fs_file_t variable
• path: path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
Public Members
char letter
uint16_t file_size
uint16_t rddir_size
bool (*ready_cb)(struct _lv_fs_drv_t *drv)
lv_fs_res_t (*open_cb)(struct _lv_fs_drv_t *drv, void *file_p, const char *path,
lv_fs_mode_t mode)
lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t *drv, void *file_p)
lv_fs_res_t (*remove_cb)(struct _lv_fs_drv_t *drv, const char *fn)
lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr,
uint32_t *br)
Public Members
void *file_d
lv_fs_drv_t *drv
struct lv_fs_dir_t
Public Members
void *dir_d
lv_fs_drv_t *drv
4.10 Animations
You can automatically change the value of a variable between a start and an end value using animations.
The animation will happen by the periodical call of an ”animator” function with the corresponding value
parameter.
The animator functions has the following prototype:
This prototype is compatible with the majority of the set function of LVGL. For example
lv_obj_set_x(obj, value) or lv_obj_set_width(obj, value)
To create an animation an lv_anim_t variable has to be initialized and configured with lv_anim_set_.
..() functions.
/* INITIALIZE AN ANIMATION
*-----------------------*/
lv_anim_t a;
lv_anim_init(&a);
/* MANDATORY SETTINGS
*------------------*/
/* OPTIONAL SETTINGS
*------------------*/
/*Play the animation backward too with this duration. Default is 0 (disabled) [ms]*/
lv_anim_set_playback_time(&a, wait_time);
lv_anim_set_repeat_count(&a, wait_time);
/*true (default): apply the start vale immediately, false: apply start vale after␣
,→delay when then anim. really starts. */
lv_anim_set_early_apply(&a, true/false);
(continues on next page)
You can apply multiple different animations on the same variable at the same time. For example,
animate the x and y coordinates with lv_obj_set_x and lv_obj_set_y. However, only one animation
can exist with a given variable and function pair. Therefore lv_anim_start() will delete the already
existing variable-function animations.
You can determinate the path of animation. In the most simple case, it is linear, which means the current
value between start and end is changed linearly. A path is mainly a function which calculates the next value
to set based on the current state of the animation. Currently, there are the following built-in paths functions:
• lv_anim_path_linear linear animation
• lv_anim_path_step change in one step at the end
• lv_anim_path_ease_in slow at the beginning
• lv_anim_path_ease_out slow at the end
• lv_anim_path_ease_in_out slow at the beginning and end too
• lv_anim_path_overshoot overshoot the end value
• lv_anim_path_bounce bounce back a little from the end value (like hitting a wall)
A path can be initialized like this:
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_overshoot);
lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/
By default, you can set the animation time. But, in some cases, the animation speed is more practical.
The lv_anim_speed_to_time(speed, start, end) function calculates the required time in millisec-
onds to reach the end value from a start value with the given speed. The speed is interpreted in unit/sec
dimension. For example, lv_anim_speed_to_time(20,0,100) will give 5000 milliseconds. For exam-
ple, in case of lv_obj_set_x unit is pixels so 20 means 20 px/sec speed.
You can delete an animation by lv_anim_del(var, func) by providing the animated variable and
its animator function.
4.10.5 API
Input device
Typedefs
Enums
enum [anonymous]
Can be used to indicate if animations are enabled or disabled in a case
Values:
enumerator LV_ANIM_OFF
enumerator LV_ANIM_ON
Functions
void _lv_anim_core_init(void)
Init. the animation module
void lv_anim_init(lv_anim_t *a)
Initialize an animation variable. E.g.: lv_anim_t a; lv_anim_init(&a); lv_anim_set_...(&a);
Parameters
• a: pointer to an lv_anim_t variable to initialize
void lv_anim_set_var(lv_anim_t *a, void *var)
Set a variable to animate
Parameters
• a: pointer to an initialized lv_anim_t variable
• var: pointer to a variable to animate
void lv_anim_set_exec_cb(lv_anim_t *a, lv_anim_exec_xcb_t exec_cb)
Set a function to animate var
Parameters
• a: pointer to an initialized lv_anim_t variable
• exec_cb: a function to execute during animation LittelvGL’s built-in functions can be used.
E.g. lv_obj_set_x
void lv_anim_set_time(lv_anim_t *a, uint32_t duration)
Set the duration of an animation
Parameters
• a: pointer to an initialized lv_anim_t variable
• duration: duration of the animation in milliseconds
void lv_anim_set_delay(lv_anim_t *a, uint32_t delay)
Set a delay before starting the animation
Parameters
• a: pointer to an initialized lv_anim_t variable
• delay: delay before the animation in milliseconds
void lv_anim_set_values(lv_anim_t *a, lv_anim_value_t start, lv_anim_value_t end)
Set the start and end values of an animation
Parameters
• a: pointer to an initialized lv_anim_t variable
• start: the start value
• end: the end value
void lv_anim_set_custom_exec_cb(lv_anim_t *a, lv_anim_custom_exec_cb_t exec_cb)
Similar to lv_anim_set_exec_cb but lv_anim_custom_exec_cb_t receives lv_anim_t * as
its first parameter instead of void *. This function might be used when LVGL is binded to other
languages because it’s more consistent to have lv_anim_t * as first parameter. The variable to
animate can be stored in the animation’s user_sata
Parameters
as their first parameter. It’s not practical in C but might make the API more consequent and makes
easier to generate bindings.
Return true: at least 1 animation is deleted, false: no animation is deleted
Parameters
• a: pointer to an animation.
• exec_cb: a function pointer which is animating ’var’, or NULL to ignore it and delete all
the animations of ’var
uint16_t lv_anim_count_running(void)
Get the number of currently running animations
Return the number of running animations
uint16_t lv_anim_speed_to_time(uint16_t speed, lv_anim_value_t start, lv_anim_value_t
end)
Calculate the time of an animation with a given speed and the start and end values
Return the required time [ms] for the animation with the given parameters
Parameters
• speed: speed of animation in unit/sec
• start: start value of the animation
• end: end value of the animation
void lv_anim_refr_now(void)
Manually refresh the state of the animations. Useful to make the animations running in a blocking
process where lv_task_handler can’t run for a while. Shouldn’t be used directly because it is called
in lv_refr_now().
lv_anim_value_t lv_anim_path_linear(const lv_anim_path_t *path, const lv_anim_t *a)
Calculate the current value of an animation applying linear characteristic
Return the current value to set
Parameters
• a: pointer to an animation
lv_anim_value_t lv_anim_path_ease_in(const lv_anim_path_t *path, const lv_anim_t *a)
Calculate the current value of an animation slowing down the start phase
Return the current value to set
Parameters
• a: pointer to an animation
lv_anim_value_t lv_anim_path_ease_out(const lv_anim_path_t *path, const lv_anim_t
*a)
Calculate the current value of an animation slowing down the end phase
Return the current value to set
Parameters
• a: pointer to an animation
lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_path_t *path, const
lv_anim_t *a)
Calculate the current value of an animation applying an ”S” characteristic (cosine)
Variables
Public Members
lv_anim_path_cb_t cb
void *user_data
struct _lv_anim_t
#include <lv_anim.h> Describes an animation
Public Members
void *var
Variable to animate
lv_anim_exec_xcb_t exec_cb
Function to execute to animate
lv_anim_start_cb_t start_cb
Call it when the animation is starts (considering delay)
lv_anim_ready_cb_t ready_cb
Call it when the animation is ready
lv_anim_path_t path
Describe the path (curve) of animations
int32_t start
Start value
int32_t current
Current value
int32_t end
End value
int32_t time
Animation time in ms
int32_t act_time
Current time in animation. Set to negative to make delay.
uint32_t playback_delay
Wait before play back
uint32_t playback_time
Duration of playback animation
uint32_t repeat_delay
Wait before repeat
uint16_t repeat_cnt
Repeat count for the animation
uint8_t early_apply
1: Apply start value immediately even is there is delay
lv_anim_user_data_t user_data
Custom user data
uint32_t time_orig
uint8_t playback_now
Play back is in progress
uint32_t has_run
Indicates the animation has run in this round
4.11 Tasks
LVGL has a built-in task system. You can register a function to have it be called periodically. The tasks are
handled and called in lv_task_handler(), which needs to be called periodically every few milliseconds.
See Porting for more information.
The tasks are non-preemptive, which means a task cannot interrupt another task. Therefore, you can call
any LVGL related function in a task.
...
You can make a task to run only once by callinglv_task_once(task). The task will automatically be
deleted after being called for the first time.
You can get the idle percentage time lv_task_handler with lv_task_get_idle(). Note that, it
doesn’t measure the idle time of the overall system, only lv_task_handler. It can be misleading if you
use an operating system and call lv_task_handler in an task, as it won’t actually measure the time the
OS spends in an idle thread.
In some cases, you can’t do an action immediately. For example, you can’t delete an object right now
because something else is still using it or you don’t want to block the execution now. For these cases, you
can use the lv_async_call(my_function, data_p) to make my_function be called on the next
call of lv_task_handler. data_p will be passed to function when it’s called. Note that, only the pointer
of the data is saved so you need to ensure that the variable will be ”alive” while the function is called. You
can use static, global or dynamically allocated data.
For example:
...
/*The screen is still valid so you can do other things with it*/
If you just want to delete an object, and don’t need to clean anything up in my_screen_cleanup, you
could just use lv_obj_del_async, which will delete the object on the next call to lv_task_handler.
4.11.7 API
Typedefs
Enums
enum [anonymous]
Possible priorities for lv_tasks
Values:
enumerator LV_TASK_PRIO_OFF = 0
enumerator LV_TASK_PRIO_LOWEST
enumerator LV_TASK_PRIO_LOW
enumerator LV_TASK_PRIO_MID
enumerator LV_TASK_PRIO_HIGH
enumerator LV_TASK_PRIO_HIGHEST
enumerator _LV_TASK_PRIO_NUM
Functions
void _lv_task_core_init(void)
Init the lv_task module
lv_task_t *lv_task_create_basic(void)
Create an ”empty” task. It needs to initialized with at least lv_task_set_cb and
lv_task_set_period
Return pointer to the created task
lv_task_t *lv_task_create(lv_task_cb_t task_xcb, uint32_t period, lv_task_prio_t prio, void
*user_data)
Create a new lv_task
Return pointer to the new task
Parameters
• task_xcb: a callback which is the task itself. It will be called periodically. (the ’x’ in
the argument name indicates that its not a fully generic function because it not follows the
func_name(object, callback, ...) convention)
• period: call period in ms unit
• prio: priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
• user_data: custom parameter
void lv_task_del(lv_task_t *task)
Delete a lv_task
Parameters
• task: pointer to task_cb created by task
void lv_task_set_cb(lv_task_t *task, lv_task_cb_t task_cb)
Set the callback the task (the function to call periodically)
Parameters
• task: pointer to a task
• task_cb: the function to call periodically
Public Members
uint32_t period
How often the task should run
uint32_t last_run
Last time the task ran
lv_task_cb_t task_cb
Task function
void *user_data
Custom user data
int32_t repeat_count
1: Task times; -1 : infinity; 0 : stop ; n>0: residual times
uint8_t prio
Task priority
4.12 Drawing
With LVGL, you don’t need to draw anything manually. Just create objects (like buttons and labels), move
and change them and LVGL will refresh and redraw what is required.
However, it might be useful to have a basic understanding of how drawing happens in LVGL.
The basic concept is to not draw directly to the screen, but draw to an internal buffer first and then copy
that buffer to screen when the rendering is ready. It has two main advantages:
1. Avoids flickering while layers of the UI are drawn. For example, when drawing a background +
button + text, each ”stage” would be visible for a short time.
2. It’s faster to modify a buffer in RAM and finally write one pixel once than read/write a display
directly on each pixel access. (e.g. via a display controller with SPI interface). Hence, it’s suitable for
pixels that are redrawn multiple times (e.g. background + button + text).
As you already might learn in the Porting section, there are 3 types of buffers:
1. One buffer - LVGL draws the content of the screen into a buffer and sends it to the display. The
buffer can be smaller than the screen. In this case, the larger areas will be redrawn in multiple parts.
If only small areas changes (e.g. button press), then only those areas will be refreshed.
2. Two non-screen-sized buffers - having two buffers, LVGL can draw into one buffer while the content
of the other buffer is sent to display in the background. DMA or other hardware should be used to
transfer the data to the display to let the CPU draw meanwhile. This way, the rendering and refreshing
of the display become parallel. If the buffer is smaller than the area to refresh, LVGL will draw the
display’s content in chunks similar to the One buffer.
3. Two screen-sized buffers - In contrast to Two non-screen-sized buffers, LVGL will always provide
the whole screen’s content, not only chunks. This way, the driver can simply change the address of the
frame buffer to the buffer received from LVGL. Therefore, this method works best when the MCU has
an LCD/TFT interface and the frame buffer is just a location in the RAM.
1. Something happens on the GUI which requires redrawing. For example, a button has been pressed, a
chart has been changed or an animation happened, etc.
2. LVGL saves the changed object’s old and new area into a buffer, called an Invalid area buffer. For
optimization, in some cases, objects are not added to the buffer:
• Hidden objects are not added.
• Objects completely out of their parent are not added.
• Areas out of the parent are cropped to the parent’s area.
• The object on other screens are not added.
3. In every LV_DISP_DEF_REFR_PERIOD (set in lv_conf.h):
• LVGL checks the invalid areas and joins the adjacent or intersecting areas.
• Takes the first joined area, if it’s smaller than the display buffer, then simply draw the areas’
content to the display buffer. If the area doesn’t fit into the buffer, draw as many lines as possible
to the display buffer.
• When the area is drawn, call flush_cb from the display driver to refresh the display.
• If the area was larger than the buffer, redraw the remaining parts too.
• Do the same with all the joined areas.
While an area is redrawn, the library searches the most top object which covers the area to redraw, and
starts to draw from that object. For example, if a button’s label has changed, the library will see that it’s
enough to draw the button under the text, and it’s not required to draw the background too.
The difference between buffer types regarding the drawing mechanism is the following:
1. One buffer - LVGL needs to wait for lv_disp_flush_ready() (called at the end of flush_cb)
before starting to redraw the next part.
2. Two non-screen-sized buffers - LVGL can immediately draw to the second buffer when the first
is sent to flush_cb because the flushing should be done by DMA (or similar hardware) in the
background.
3. Two screen-sized buffers - After calling flush_cb, the first buffer, if being displayed as frame
buffer. Its content is copied to the second buffer and all the changes are drawn on top of it.
4.12.3 Masking
Masking is the basic concept of LVGL’s drawing engine. To use LVGL it’s not required to know about the
mechanisms described here, but you might find interesting to know how the drawing works under hood.
To learn masking let’s learn the steps of drawing first:
1. Create a draw descriptor from an object’s styles (e.g. lv_draw_rect_dsc_t). It tells the parameters
of drawing, for example the colors, widths, opacity, fonts, radius, etc.
2. Call the draw function with the initialized descriptor and some other parameters. It renders the
primitive shape to the current draw buffer.
3. If the shape is very simple and doesn’t require masks go to #5. Else create the required masks (e.g. a
rounded rectangle mask)
4. Apply all the created mask(s) for one or a few lines. It create 0..255 values into a mask buffer with the
”shape” of the created masks. E.g. in case of a ”line mask” according to the parameters of the mask,
keep one side of the buffer as it is (255 by default) and set the rest to 0 to indicate that the latter side
should be removed.
5. Blend the image or rectangle to the screen. During blending masks (make some pixels transparent or
opaque), blending modes (additive, subtractive, etc), opacity are handled.
6. Repeat from #4.
Masks are used the create almost every basic primitives:
• letters create a mask from the letter and draw a “letter-colored”rectangle using the mask.
• line created from 4 l”ine masks”, to mask out the left, right, top and bottom part of the line to get
perfectly perpendicular line ending
• rounded rectangle a mask is created real-time for each line of a rounded rectangle and a normal
filled rectangle is drawn according to the mask.
• clip corner to clip to overflowing content on the rounded corners also a rounded rectangle mask is
applied.
• rectangle border same as a rounded rectangle, but inner part is masked out too
• arc drawing a circle border is drawn, but an arc mask is applied.
• ARGB images the alpha channel is separated into a mask and the image is drawn as a normal RGB
image.
As mentioned in #3 above in some cases no mask is required:
• a mono colored, not rounded rectangles
• RGB images
LVGL has the following built-in mask types which can be calculated and applied real-time:
• LV_DRAW_MASK_TYPE_LINE Removes a side of a line (top, bottom, left or right).
lv_draw_line uses 4 of it. Essentially, every (skew) line is bounded with 4 line masks by form-
ing a rectangle.
• LV_DRAW_MASK_TYPE_RADIUS Removes the inner or outer parts of a rectangle which
can have radius too. It’s also used to create circles by setting the radius to large value
(LV_RADIUS_CIRCLE)
• LV_DRAW_MASK_TYPE_ANGLE Removes a circle sector. It is used by lv_draw_arc to
remove the ”empty” sector.
• LV_DRAW_MASK_TYPE_FADE Create a vertical fade (change opacity)
• LV_DRAW_MASK_TYPE_MAP The mask is stored in an array and the necessary parts are
applied
Masks are create and removed automatically during drawing but the lv_objmask allows the user to add
masks. Here is an example:
code
#include "../../../lv_examples.h"
#if LV_USE_OBJMASK
void lv_ex_objmask_1(void)
{
/*Set a very visible color for the screen to clearly see what happens*/
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,␣
,→lv_color_hex3(0xf33));
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_area_t a;
lv_draw_mask_radius_param_t r1;
a.x1 = 10;
a.y1 = 10;
a.x2 = 190;
a.y2 = 190;
lv_draw_mask_radius_init(&r1, &a, LV_RADIUS_CIRCLE, false);
lv_objmask_add_mask(om, &r1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
a.x1 = 100;
a.y1 = 100;
a.x2 = 150;
a.y2 = 150;
lv_draw_mask_radius_init(&r1, &a, LV_RADIUS_CIRCLE, true);
lv_objmask_add_mask(om, &r1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_draw_mask_line_param_t l1;
lv_draw_mask_line_points_init(&l1, 0, 0, 100, 200, LV_DRAW_MASK_LINE_SIDE_TOP);
lv_objmask_add_mask(om, &l1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_draw_mask_fade_param_t f1;
a.x1 = 100;
a.y1 = 0;
a.x2 = 200;
a.y2 = 200;
lv_draw_mask_fade_init(&f1, &a, LV_OPA_TRANSP, 0, LV_OPA_COVER, 150);
lv_objmask_add_mask(om, &f1);
}
#endif
Text mask
code
#include "../../../lv_examples.h"
#if LV_USE_OBJMASK
void lv_ex_objmask_2(void)
{
/*Draw a label to the canvas. The result "image" will be used as mask*/
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = LV_COLOR_WHITE;
lv_canvas_draw_text(canvas, 5, 5, MASK_WIDTH, &label_dsc, "Text with gradient",␣
,→LV_LABEL_ALIGN_CENTER);
/* Create and object with the gradient style on the object mask.
* The text will be masked from the gradient*/
lv_obj_t * bg = lv_obj_create(om, NULL);
lv_obj_reset_style_list(bg, LV_OBJ_PART_MAIN);
lv_obj_add_style(bg, LV_OBJ_PART_MAIN, &style_bg);
lv_obj_set_size(bg, MASK_WIDTH, MASK_HEIGHT);
#endif
MicroPython
No examples yet.
FIVE
WIDGETS
5.1.1 Overview
The ’Base Object’ implements the basic properties of widgets on a screen, such as:
• coordinates
• parent object
• children
• main style
• attributes like Click enable, Drag enable, etc.
In object-oriented thinking, it is the base class from which all other objects in LVGL are inherited. This,
among another things, helps reduce code duplication.
The functions and functionalities of Base object can be used with other widgets too. For example
lv_obj_set_width(slider, 100)
The Base object can be directly used as a simple widgets. It nothing else then a rectangle.
Coordinates
Size
The object size can be modified on individual axes with lv_obj_set_width(obj, new_width) and
lv_obj_set_height(obj, new_height), or both axes can be modified at the same time with
lv_obj_set_size(obj, new_width, new_height).
Styles can add Margin to the objects. Margin tells that ”I want this space around me”.
To set width or height reduced by the margin lv_obj_set_width_margin(obj, new_width)
or lv_obj_set_height_margin(obj, new_height). In more exact way: new_width =
left_margin + object_width + right_margin.
To get the width or height which includes the margins use lv_obj_get_width/height_margin(obj).
Styles can add Padding to the object as well. Padding means ”I don’t want my children too close to my
sides, so keep this space”. To set width or height reduced by the padding lv_obj_set_width_fit(obj,
new_width) or lv_obj_set_height_fit(obj, new_height).In a more exact way: new_width =
left_pad + object_width + right_pad To get the width or height which is REDUCED by padding
use lv_obj_get_width/height_fit(obj). It can be considered the ”useful size of the object”.
154
LVGL Documentation v7.8.0-dev
Margin and padding gets important when Layout or Auto-fit is used by other widgets.
Position
You can set the x and y coordinates relative to the parent with lv_obj_set_x(obj, new_x) and
lv_obj_set_y(obj, new_y), or both at the same time with lv_obj_set_pos(obj, new_x,
new_y).
Alignment
You can align the object to another with lv_obj_align(obj, obj_ref, LV_ALIGN_..., x_ofs,
y_ofs).
• obj is the object to align.
• obj_ref is a reference object. obj will be aligned to it. If obj_ref = NULL, then the parent of
obj will be used.
• The third argument is the type of alignment. These are the possible options:
You can set a new parent for an object with lv_obj_set_parent(obj, new_parent). To get the
current parent, use lv_obj_get_parent(obj).
To get the children of an object, use lv_obj_get_child(obj, child_prev) (from last to first) or
lv_obj_get_child_back(obj, child_prev) (from first to last). To get the first child, pass NULL
as the second parameter and use the return value to iterate through the children. The function will return
NULL if there are no more children. For example:
Screens
When you have created a screen like lv_obj_t * screen = lv_obj_create(NULL, NULL), you can
load it with lv_scr_load(screen). The lv_scr_act() function gives you a pointer to the current
screen.
If you have more display then it’s important to know that these functions operate on the lastly created or
the explicitly selected (with lv_disp_set_default) display.
To get an object’s screen use the lv_obj_get_screen(obj) function.
Layers
Events
5.1.2 Parts
The widgets can have multiple parts. For example a Button has only a main part but a Slider is built from
a background, an indicator and a knob.
The name of the parts is constructed like LV_ + <TYPE> _PART_ <NAME>. For example
LV_BTN_PART_MAIN or LV_SLIDER_PART_KNOB. The parts are usually used when styles are add to
the objects. Using parts different styles can be assigned to the different parts of the objects.
To learn more about the parts read the related section of the Style overview.
States
Style
Attributes
Protect
There are some specific actions which happen automatically in the library. To prevent one or more that kind
of actions, you can protect the object against them. The following protections exists:
• LV_PROTECT_NONE No protection
• LV_PROTECT_POS Prevent automatic positioning (e.g. Layout in Containers)
• LV_PROTECT_FOLLOW Prevent the object be followed (make a ”line break”) in automatic
ordering (e.g. Layout in Containers)
• LV_PROTECT_PARENT Prevent automatic parent change. (e.g. Page moves the children cre-
ated on the background to the scrollable)
• LV_PROTECT_PRESS_LOST Prevent losing press when the press is slid out of the objects.
(E.g. a Button can be released out of it if it was being pressed)
• LV_PROTECT_CLICK_FOCUS Prevent automatically focusing the object if it’s in a Group
and click focus is enabled.
• LV_PROTECT_CHILD_CHG Disable the child change signal. Used internally by the library
The lv_obj_add/clear_protect(obj, LV_PROTECT_...) sets/clears the protection. You can use
’OR’ed values of protection types too.
Groups
Once, an object is added to group with lv_group_add_obj(group, obj) the object’s current group
can be get with lv_obj_get_group(obj).
lv_obj_is_focused(obj) tells if the object is currently focused on its group or not. If the object is not
added to a group, false will be returned.
Read the Input devices overview to learn more about the Groups.
By default, the objects can be clicked only on their coordinates, however, this area can be extended
with lv_obj_set_ext_click_area(obj, left, right, top, bottom). left/right/top/
bottom describes how far the clickable area should extend past the default in each direction.
This feature needs to enabled in lv_conf.h with LV_USE_EXT_CLICK_AREA. The possible values are:
• LV_EXT_CLICK_AREA_FULL store all 4 coordinates as lv_coord_t
• LV_EXT_CLICK_AREA_TINY store only horizontal and vertical coordinates (use the greater
value of left/right and top/bottom) as uint8_t
• LV_EXT_CLICK_AREA_OFF Disable this feature
5.1.3 Events
5.1.4 Keys
5.1.5 Example
code
#include "../../../lv_examples.h"
void lv_ex_obj_1(void)
{
lv_obj_t * obj1;
obj1 = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(obj1, 100, 50);
lv_obj_align(obj1, NULL, LV_ALIGN_CENTER, -60, -30);
MicroPython
No examples yet.
5.1.6 API
Typedefs
Enums
enum [anonymous]
Design modes
Values:
enumerator LV_DESIGN_DRAW_MAIN
Draw the main portion of the object
enumerator LV_DESIGN_DRAW_POST
Draw extras on the object
enumerator LV_DESIGN_COVER_CHK
Check if the object fully covers the ’mask_p’ area
enum [anonymous]
Design results
Values:
enumerator LV_DESIGN_RES_OK
Draw ready
enumerator LV_DESIGN_RES_COVER
Returned on LV_DESIGN_COVER_CHK if the areas is fully covered
enumerator LV_DESIGN_RES_NOT_COVER
Returned on LV_DESIGN_COVER_CHK if the areas is not covered
enumerator LV_DESIGN_RES_MASKED
Returned on LV_DESIGN_COVER_CHK if the areas is masked out (children also not cover)
enum [anonymous]
Values:
enumerator LV_EVENT_PRESSED
The object has been pressed
enumerator LV_EVENT_PRESSING
The object is being pressed (called continuously while pressing)
enumerator LV_EVENT_PRESS_LOST
User is still pressing but slid cursor/finger off of the object
enumerator LV_EVENT_SHORT_CLICKED
User pressed object for a short period of time, then released it. Not called if dragged.
enumerator LV_EVENT_LONG_PRESSED
Object has been pressed for at least LV_INDEV_LONG_PRESS_TIME. Not called if dragged.
enumerator LV_EVENT_LONG_PRESSED_REPEAT
Called after LV_INDEV_LONG_PRESS_TIME in every LV_INDEV_LONG_PRESS_REP_TIME ms.
Not called if dragged.
enumerator LV_EVENT_CLICKED
Called on release if not dragged (regardless to long press)
enumerator LV_EVENT_RELEASED
Called in every cases when the object has been released
enumerator LV_EVENT_DRAG_BEGIN
enumerator LV_EVENT_DRAG_END
enumerator LV_EVENT_DRAG_THROW_BEGIN
enumerator LV_EVENT_GESTURE
The object has been gesture
enumerator LV_EVENT_KEY
enumerator LV_EVENT_FOCUSED
enumerator LV_EVENT_DEFOCUSED
enumerator LV_EVENT_LEAVE
enumerator LV_EVENT_VALUE_CHANGED
The object’s value has changed (i.e. slider moved)
enumerator LV_EVENT_INSERT
enumerator LV_EVENT_REFRESH
enumerator LV_EVENT_APPLY
”Ok”, ”Apply” or similar specific button has clicked
enumerator LV_EVENT_CANCEL
”Close”, ”Cancel” or similar specific button has clicked
enumerator LV_EVENT_DELETE
Object is being deleted
enumerator _LV_EVENT_LAST
Number of events
enum [anonymous]
Signals are for use by the object itself or to extend the object’s functionality. Applications should use
lv_obj_set_event_cb to be notified of events that occur on the object.
Values:
enumerator LV_SIGNAL_CLEANUP
Object is being deleted
enumerator LV_SIGNAL_CHILD_CHG
Child was removed/added
enumerator LV_SIGNAL_COORD_CHG
Object coordinates/size have changed
enumerator LV_SIGNAL_PARENT_SIZE_CHG
Parent’s size has changed
enumerator LV_SIGNAL_STYLE_CHG
Object’s style has changed
enumerator LV_SIGNAL_BASE_DIR_CHG
The base dir has changed
enumerator LV_SIGNAL_REFR_EXT_DRAW_PAD
Object’s extra padding has changed
enumerator LV_SIGNAL_GET_TYPE
LVGL needs to retrieve the object’s type
enumerator LV_SIGNAL_GET_STYLE
Get the style of an object
enumerator LV_SIGNAL_GET_STATE_DSC
Get the state of the object
enumerator LV_SIGNAL_HIT_TEST
Advanced hit-testing
enumerator LV_SIGNAL_PRESSED
The object has been pressed
enumerator LV_SIGNAL_PRESSING
The object is being pressed (called continuously while pressing)
enumerator LV_SIGNAL_PRESS_LOST
User is still pressing but slid cursor/finger off of the object
enumerator LV_SIGNAL_RELEASED
User pressed object for a short period of time, then released it. Not called if dragged.
enumerator LV_SIGNAL_LONG_PRESS
Object has been pressed for at least LV_INDEV_LONG_PRESS_TIME. Not called if dragged.
enumerator LV_SIGNAL_LONG_PRESS_REP
Called after LV_INDEV_LONG_PRESS_TIME in every LV_INDEV_LONG_PRESS_REP_TIME ms.
Not called if dragged.
enumerator LV_SIGNAL_DRAG_BEGIN
enumerator LV_SIGNAL_DRAG_THROW_BEGIN
enumerator LV_SIGNAL_DRAG_END
enumerator LV_SIGNAL_GESTURE
The object has been gesture
enumerator LV_SIGNAL_LEAVE
Another object is clicked or chosen via an input device
enumerator LV_SIGNAL_FOCUS
enumerator LV_SIGNAL_DEFOCUS
enumerator LV_SIGNAL_CONTROL
enumerator LV_SIGNAL_GET_EDITABLE
enum [anonymous]
Values:
enumerator LV_PROTECT_NONE = 0x00
enumerator LV_PROTECT_CHILD_CHG = 0x01
Disable the child change signal. Used by the library
enumerator LV_PROTECT_PARENT = 0x02
Prevent automatic parent change (e.g. in lv_page)
enumerator LV_PROTECT_POS = 0x04
Prevent automatic positioning (e.g. in lv_cont layout)
enumerator LV_PROTECT_FOLLOW = 0x08
Prevent the object be followed in automatic ordering (e.g. in lv_cont PRETTY layout)
enumerator LV_PROTECT_PRESS_LOST = 0x10
If the indev was pressing this object but swiped out while pressing do not search other object.
enumerator LV_PROTECT_CLICK_FOCUS = 0x20
Prevent focusing the object by clicking on it
enum [anonymous]
Values:
enumerator LV_STATE_DEFAULT = 0x00
enumerator LV_STATE_CHECKED = 0x01
enumerator LV_STATE_FOCUSED = 0x02
enumerator LV_STATE_EDITED = 0x04
enumerator LV_STATE_HOVERED = 0x08
enumerator LV_STATE_PRESSED = 0x10
enumerator LV_STATE_DISABLED = 0x20
enum [anonymous]
Values:
enumerator LV_OBJ_PART_MAIN
enumerator _LV_OBJ_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_FIRST
enumerator _LV_OBJ_PART_REAL_LAST = _LV_OBJ_PART_REAL_FIRST
Functions
void lv_init(void)
Init. the ’lv’ library.
void lv_deinit(void)
Deinit the ’lv’ library Currently only implemented when not using custom allocators, or GC is enabled.
lv_obj_t *lv_obj_create(lv_obj_t *parent, const lv_obj_t *copy)
Create a basic object
Return pointer to the new object
Parameters
• parent: pointer to a parent object. If NULL then a screen will be created
• copy: pointer to a base object, if not NULL then the new object will be copied from it
lv_res_t lv_obj_del(lv_obj_t *obj)
Delete ’obj’ and all of its children
Return LV_RES_INV because the object is deleted
Parameters
• obj: pointer to an object to delete
void lv_obj_del_anim_ready_cb(lv_anim_t *a)
A function to be easily used in animation ready callback to delete an object when the animation is
ready
Parameters
• a: pointer to the animation
void lv_obj_del_async(struct _lv_obj_t *obj)
Helper function for asynchronously deleting objects. Useful for cases where you can’t delete an object
directly in an LV_EVENT_DELETE handler (i.e. parent).
See lv_async_call
Parameters
• obj: object to delete
void lv_obj_clean(lv_obj_t *obj)
Delete all children of an object
Parameters
• obj: pointer to an object
void lv_obj_invalidate_area(const lv_obj_t *obj, const lv_area_t *area)
Mark an area of an object as invalid. This area will be redrawn by ’lv_refr_task’
Parameters
• obj: pointer to an object
• area: the area to redraw
void lv_obj_invalidate(const lv_obj_t *obj)
Mark the object as invalid therefore its current position will be redrawn by ’lv_refr_task’
Parameters
• obj: pointer to an object
bool lv_obj_area_is_visible(const lv_obj_t *obj, lv_area_t *area)
Tell whether an area of an object is visible (even partially) now or not
Return true: visible; false: not visible (hidden, out of parent, on other screen, etc)
Parameters
• obj: pointer to an object
• area: the are to check. The visible part of the area will be written back here.
bool lv_obj_is_visible(const lv_obj_t *obj)
Tell whether an object is visible (even partially) now or not
Return true: visible; false: not visible (hidden, out of parent, on other screen, etc)
Parameters
• obj: pointer to an object
void lv_obj_set_parent(lv_obj_t *obj, lv_obj_t *parent)
Set a new parent for an object. Its relative position will be the same.
Parameters
• obj: pointer to an object. Can’t be a screen.
• parent: pointer to the new parent object. (Can’t be NULL)
void lv_obj_move_foreground(lv_obj_t *obj)
Move and object to the foreground
Parameters
• obj: pointer to an object
void lv_obj_move_background(lv_obj_t *obj)
Move and object to the background
Parameters
• obj: pointer to an object
void lv_obj_set_pos(lv_obj_t *obj, lv_coord_t x, lv_coord_t y)
Set relative the position of an object (relative to the parent)
Parameters
• obj: pointer to an object
• x: new distance from the left side of the parent
• y: new distance from the top of the parent
void lv_obj_set_x(lv_obj_t *obj, lv_coord_t x)
Set the x coordinate of a object
Parameters
• obj: pointer to an object
• x: new distance from the left side from the parent
void lv_obj_set_y(lv_obj_t *obj, lv_coord_t y)
Set the y coordinate of a object
Parameters
• obj: pointer to an object
• y: new distance from the top of the parent
void lv_obj_set_size(lv_obj_t *obj, lv_coord_t w, lv_coord_t h)
Set the size of an object
Parameters
• obj: pointer to an object
• w: new width
• h: new height
void lv_obj_set_width(lv_obj_t *obj, lv_coord_t w)
Set the width of an object
Parameters
• obj: pointer to an object
• w: new width
void lv_obj_set_height(lv_obj_t *obj, lv_coord_t h)
Set the height of an object
Parameters
• obj: pointer to an object
• h: new height
void lv_obj_set_width_fit(lv_obj_t *obj, lv_coord_t w)
Set the width reduced by the left and right padding.
Parameters
• obj: pointer to an object
• w: the width without paddings
void lv_obj_set_height_fit(lv_obj_t *obj, lv_coord_t h)
Set the height reduced by the top and bottom padding.
Parameters
• obj: pointer to an object
• h: the height without paddings
void lv_obj_set_width_margin(lv_obj_t *obj, lv_coord_t w)
Set the width of an object by taking the left and right margin into account. The object width will be
obj_w = w - margin_left - margin_right
Parameters
• obj: pointer to an object
• w: new height including margins
void lv_obj_set_height_margin(lv_obj_t *obj, lv_coord_t h)
Set the height of an object by taking the top and bottom margin into account. The object height will
be obj_h = h - margin_top - margin_bottom
Parameters
• base: pointer to an object (if NULL the parent is used). ’obj’ will be aligned to it.
• align: type of alignment (see ’lv_align_t’ enum)
• x_ofs: x coordinate offset after alignment
void lv_obj_align_mid_y(lv_obj_t *obj, const lv_obj_t *base, lv_align_t align, lv_coord_t
y_ofs)
Align an object’s middle point to an other object vertically.
Parameters
• obj: pointer to an object to align
• base: pointer to an object (if NULL the parent is used). ’obj’ will be aligned to it.
• align: type of alignment (see ’lv_align_t’ enum)
• y_ofs: y coordinate offset after alignment
void lv_obj_realign(lv_obj_t *obj)
Realign the object based on the last lv_obj_align parameters.
Parameters
• obj: pointer to an object
void lv_obj_set_auto_realign(lv_obj_t *obj, bool en)
Enable the automatic realign of the object when its size has changed based on the last lv_obj_align
parameters.
Parameters
• obj: pointer to an object
• en: true: enable auto realign; false: disable auto realign
void lv_obj_set_ext_click_area(lv_obj_t *obj, lv_coord_t left, lv_coord_t right, lv_coord_t
top, lv_coord_t bottom)
Set the size of an extended clickable area
Parameters
• obj: pointer to an object
• left: extended clickable are on the left [px]
• right: extended clickable are on the right [px]
• top: extended clickable are on the top [px]
• bottom: extended clickable are on the bottom [px]
void lv_obj_add_style(lv_obj_t *obj, uint8_t part, lv_style_t *style)
Add a new style to the style list of an object.
Parameters
• obj: pointer to an object
• part: the part of the object which style property should be set. E.g. LV_OBJ_PART_MAIN,
LV_BTN_PART_MAIN, LV_SLIDER_PART_KNOB
• style: pointer to a style to add (Only its pointer will be saved)
void lv_obj_remove_style(lv_obj_t *obj, uint8_t part, lv_style_t *style)
Remove a style from the style list of an object.
Parameters
Note shouldn’t be used directly. Use the specific property remove functions instead. For example:
lv_obj_style_remove_border_opa()
Return true: the property was found and removed; false: the property was not found
Parameters
• obj: pointer to an object
• part: the part of the object which style property should be removed. E.g.
LV_OBJ_PART_MAIN, LV_BTN_PART_MAIN, LV_SLIDER_PART_KNOB
• prop: a style property ORed with a state. E.g. LV_STYLE_TEXT_FONT |
(LV_STATE_PRESSED << LV_STYLE_STATE_POS)
void _lv_obj_disable_style_caching(lv_obj_t *obj, bool dis)
Enable/disable the use of style cahche for an object
Parameters
• obj: pointer to an object
• dis: true: disable; false: enable (re-enable)
void lv_obj_set_hidden(lv_obj_t *obj, bool en)
Hide an object. It won’t be visible and clickable.
Parameters
• obj: pointer to an object
• en: true: hide the object
void lv_obj_set_adv_hittest(lv_obj_t *obj, bool en)
Set whether advanced hit-testing is enabled on an object
Parameters
• obj: pointer to an object
• en: true: advanced hit-testing is enabled
void lv_obj_set_click(lv_obj_t *obj, bool en)
Enable or disable the clicking of an object
Parameters
• obj: pointer to an object
• en: true: make the object clickable
void lv_obj_set_top(lv_obj_t *obj, bool en)
Enable to bring this object to the foreground if it or any of its children is clicked
Parameters
• obj: pointer to an object
• en: true: enable the auto top feature
void lv_obj_set_drag(lv_obj_t *obj, bool en)
Enable the dragging of an object
Parameters
• obj: pointer to an object
• en: true: make the object draggable
Parameters
• obj: pointer to an object
• prot: ’OR’-ed values from lv_protect_t
void lv_obj_clear_protect(lv_obj_t *obj, uint8_t prot)
Clear a bit or bits in the protect filed
Parameters
• obj: pointer to an object
• prot: ’OR’-ed values from lv_protect_t
void lv_obj_set_state(lv_obj_t *obj, lv_state_t state)
Set the state (fully overwrite) of an object. If specified in the styles a transition animation will be
started from the previous state to the current
Parameters
• obj: pointer to an object
• state: the new state
void lv_obj_add_state(lv_obj_t *obj, lv_state_t state)
Add a given state or states to the object. The other state bits will remain unchanged. If specified in
the styles a transition animation will be started from the previous state to the current
Parameters
• obj: pointer to an object
• state: the state bits to add. E.g LV_STATE_PRESSED | LV_STATE_FOCUSED
void lv_obj_clear_state(lv_obj_t *obj, lv_state_t state)
Remove a given state or states to the object. The other state bits will remain unchanged. If specified
in the styles a transition animation will be started from the previous state to the current
Parameters
• obj: pointer to an object
• state: the state bits to remove. E.g LV_STATE_PRESSED | LV_STATE_FOCUSED
void lv_obj_finish_transitions(lv_obj_t *obj, uint8_t part)
Finish all pending transitions on a part of an object
Parameters
• obj: pointer to an object
• part: part of the object, e.g LV_BRN_PART_MAIN or LV_OBJ_PART_ALL for all parts
void lv_obj_set_event_cb(lv_obj_t *obj, lv_event_cb_t event_cb)
Set a an event handler function for an object. Used by the user to react on event which happens with
the object.
Parameters
• obj: pointer to an object
• event_cb: the new event function
lv_res_t lv_event_send(lv_obj_t *obj, lv_event_t event, const void *data)
Send an event to the object
Return LV_RES_OK: obj was not deleted in the event; LV_RES_INV: obj was deleted in the
event
Parameters
• obj: pointer to an object
• event: the type of the event from lv_event_t.
• data: arbitrary data depending on the object type and the event. (Usually NULL)
lv_res_t lv_event_send_refresh(lv_obj_t *obj)
Send LV_EVENT_REFRESH event to an object
Return LV_RES_OK: success, LV_RES_INV: to object become invalid (e.g. deleted) due to this
event.
Parameters
• obj: point to an obejct. (Can NOT be NULL)
void lv_event_send_refresh_recursive(lv_obj_t *obj)
Send LV_EVENT_REFRESH event to an object and all of its children
Parameters
• obj: pointer to an object or NULL to refresh all objects of all displays
lv_res_t lv_event_send_func(lv_event_cb_t event_xcb, lv_obj_t *obj, lv_event_t event,
const void *data)
Call an event function with an object, event, and data.
Return LV_RES_OK: obj was not deleted in the event; LV_RES_INV: obj was deleted in the
event
Parameters
• event_xcb: an event callback function. If NULL LV_RES_OK will return without any ac-
tions. (the ’x’ in the argument name indicates that its not a fully generic function because it
not follows the func_name(object, callback, ...) convention)
• obj: pointer to an object to associate with the event (can be NULL to simply call the
event_cb)
• event: an event
• data: pointer to a custom data
const void *lv_event_get_data(void)
Get the data parameter of the current event
Return the data parameter
void lv_obj_set_signal_cb(lv_obj_t *obj, lv_signal_cb_t signal_cb)
Set the a signal function of an object. Used internally by the library. Always call the previous signal
function in the new.
Parameters
• obj: pointer to an object
• signal_cb: the new signal function
lv_res_t lv_signal_send(lv_obj_t *obj, lv_signal_t signal, void *param)
Send an event to the object
Return LV_RES_OK or LV_RES_INV
Parameters
• obj: pointer to an object
• event: the type of the event from lv_event_t.
void lv_obj_set_design_cb(lv_obj_t *obj, lv_design_cb_t design_cb)
Set a new design function for an object
Parameters
• obj: pointer to an object
• design_cb: the new design function
void *lv_obj_allocate_ext_attr(lv_obj_t *obj, uint16_t ext_size)
Allocate a new ext. data for an object
Return pointer to the allocated ext
Parameters
• obj: pointer to an object
• ext_size: the size of the new ext. data
void lv_obj_refresh_ext_draw_pad(lv_obj_t *obj)
Send a ’LV_SIGNAL_REFR_EXT_SIZE’ signal to the object to refresh the extended draw area. he
object needs to be invalidated by lv_obj_invalidate(obj) manually after this function.
Parameters
• obj: pointer to an object
lv_obj_t *lv_obj_get_screen(const lv_obj_t *obj)
Return with the screen of an object
Return pointer to a screen
Parameters
• obj: pointer to an object
lv_disp_t *lv_obj_get_disp(const lv_obj_t *obj)
Get the display of an object
Return pointer the object’s display
lv_obj_t *lv_obj_get_parent(const lv_obj_t *obj)
Returns with the parent of an object
Return pointer to the parent of ’obj’
Parameters
• obj: pointer to an object
lv_obj_t *lv_obj_get_child(const lv_obj_t *obj, const lv_obj_t *child)
Iterate through the children of an object (start from the ”youngest, lastly created”)
Return the child after ’act_child’ or NULL if no more child
Parameters
• obj: pointer to an object
• child: NULL at first call to get the next children and the previous return value later
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_height(const lv_obj_t *obj)
Get the height of an object
Return the height
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_width_fit(const lv_obj_t *obj)
Get that width reduced by the left and right padding.
Return the width which still fits into the container
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_height_fit(const lv_obj_t *obj)
Get that height reduced by the top an bottom padding.
Return the height which still fits into the container
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_height_margin(lv_obj_t *obj)
Get the height of an object by taking the top and bottom margin into account. The returned height
will be obj_h + margin_top + margin_bottom
Return the height including thee margins
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_width_margin(lv_obj_t *obj)
Get the width of an object by taking the left and right margin into account. The returned width will
be obj_w + margin_left + margin_right
Return the height including thee margins
Parameters
• obj: pointer to an object
lv_coord_t lv_obj_get_width_grid(lv_obj_t *obj, uint8_t div, uint8_t span)
Divide the width of the object and get the width of a given number of columns. Take paddings into
account.
Return the width according to the given parameters
Parameters
• obj: pointer to an object
• div: indicates how many columns are assumed. If 1 the width will be set the the parent’s
width If 2 only half parent width - inner padding of the parent If 3 only third parent width -
2 * inner padding of the parent
• span: how many columns are combined
Return the value of the property of the given part in the current state. If the property is not found
a default value will be returned.
Note shouldn’t be used directly. Use the specific property get functions instead. For example:
lv_obj_style_get_border_opa()
Note for performance reasons it’s not checked if the property really has opacity type
Parameters
• obj: pointer to an object
• part: the part of the object which style property should be get. E.g. LV_OBJ_PART_MAIN,
LV_BTN_PART_MAIN, LV_SLIDER_PART_KNOB
• prop: the property to get. E.g. LV_STYLE_BORDER_OPA. The state of the object will be
added internally
const void *_lv_obj_get_style_ptr(const lv_obj_t *obj, uint8_t part, lv_style_property_t
prop)
Get a style property of a part of an object in the object’s current state. If there is a running transitions
it is taken into account
Return the value of the property of the given part in the current state. If the property is not found
a default value will be returned.
Note shouldn’t be used directly. Use the specific property get functions instead. For example:
lv_obj_style_get_border_opa()
Note for performance reasons it’s not checked if the property really has pointer type
Parameters
• obj: pointer to an object
• part: the part of the object which style property should be get. E.g. LV_OBJ_PART_MAIN,
LV_BTN_PART_MAIN, LV_SLIDER_PART_KNOB
• prop: the property to get. E.g. LV_STYLE_TEXT_FONT. The state of the object will be
added internally
lv_style_t *lv_obj_get_local_style(lv_obj_t *obj, uint8_t part)
Get the local style of a part of an object.
Return pointer to the local style if exists else NULL.
Parameters
• obj: pointer to an object
• part: the part of the object which style property should be set. E.g. LV_OBJ_PART_MAIN,
LV_BTN_PART_MAIN, LV_SLIDER_PART_KNOB
bool lv_obj_get_hidden(const lv_obj_t *obj)
Get the hidden attribute of an object
Return true: the object is hidden
Parameters
• obj: pointer to an object
bool lv_obj_get_adv_hittest(const lv_obj_t *obj)
Get whether advanced hit-testing is enabled on an object
Return true: advanced hit-testing is enabled
Parameters
• obj: pointer to an object
bool lv_obj_get_click(const lv_obj_t *obj)
Get the click enable attribute of an object
Return true: the object is clickable
Parameters
• obj: pointer to an object
bool lv_obj_get_top(const lv_obj_t *obj)
Get the top enable attribute of an object
Return true: the auto top feature is enabled
Parameters
• obj: pointer to an object
bool lv_obj_get_drag(const lv_obj_t *obj)
Get the drag enable attribute of an object
Return true: the object is draggable
Parameters
• obj: pointer to an object
lv_drag_dir_t lv_obj_get_drag_dir(const lv_obj_t *obj)
Get the directions an object can be dragged
Return bitwise OR of allowed directions an object can be dragged in
Parameters
• obj: pointer to an object
bool lv_obj_get_drag_throw(const lv_obj_t *obj)
Get the drag throw enable attribute of an object
Return true: drag throw is enabled
Parameters
• obj: pointer to an object
bool lv_obj_get_drag_parent(const lv_obj_t *obj)
Get the drag parent attribute of an object
Return true: drag parent is enabled
Parameters
• obj: pointer to an object
bool lv_obj_get_focus_parent(const lv_obj_t *obj)
Get the focus parent attribute of an object
Return true: focus parent is enabled
Parameters
• obj: pointer to an object
bool lv_obj_get_parent_event(const lv_obj_t *obj)
Get the drag parent attribute of an object
Public Members
Public Members
uint8_t focus_parent
1: Parent will be focused instead
lv_drag_dir_t drag_dir
Which directions the object can be dragged in
lv_bidi_dir_t base_dir
Base direction of texts related to this object
void *group_p
uint8_t protect
Automatically happening actions can be prevented. ’OR’ed values from lv_protect_t
lv_state_t state
lv_realign_t realign
Information about the last call to lv_obj_align.
lv_obj_user_data_t user_data
Custom user data for object.
struct lv_obj_type_t
#include <lv_obj.h> Used by lv_obj_get_type(). The object’s and its ancestor types are stored
here
Public Members
Public Members
lv_point_t *point
bool result
struct lv_get_style_info_t
Public Members
uint8_t part
lv_style_list_t *result
struct lv_get_state_info_t
Public Members
uint8_t part
lv_state_t result
5.2.1 Overview
The Arc are consists of a background and a foreground arc. Both can have start and end angles and thickness.
The Arc’s main part is called LV_ARC_PART_MAIN. It draws a background using the typical background
style properties and an arc using the line style properties. The arc’s size and position will respect the padding
style properties.
LV_ARC_PART_INDIC is virtual part and it draws an other arc using the line style proeprties. It’s padding
values are interpreted relative to the background arc. The radius of the indicator arc will be modified
according to the greatest padding value.
5.2.3 Usage
Angles
5.2.4 Events
5.2.5 Keys
5.2.6 Example
Simple Arc
code
#include "../../../lv_examples.h"
#if LV_USE_ARC
void lv_ex_arc_1(void)
{
/*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
lv_arc_set_end_angle(arc, 200);
lv_obj_set_size(arc, 150, 150);
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
code
#include "../../../lv_examples.h"
#if LV_USE_ARC
/**
* An `lv_task` to call periodically to set the angles of the arc
* @param t
*/
static void arc_loader(lv_task_t * t)
{
static int16_t a = 270;
a+=5;
lv_arc_set_end_angle(t->user_data, a);
/**
* Create an arc which acts as a loader.
*/
void lv_ex_arc_2(void)
{
/*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL);
lv_arc_set_bg_angles(arc, 0, 360);
lv_arc_set_angles(arc, 270, 270);
lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0);
(continues on next page)
#endif
MicroPython
No examples yet.
5.2.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_ARC_TYPE_NORMAL
enumerator LV_ARC_TYPE_SYMMETRIC
enumerator LV_ARC_TYPE_REVERSE
enum [anonymous]
Values:
enumerator LV_ARC_PART_BG = LV_OBJ_PART_MAIN
enumerator LV_ARC_PART_INDIC
enumerator LV_ARC_PART_KNOB
enumerator _LV_ARC_PART_VIRTUAL_LAST
enumerator _LV_ARC_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST
Functions
Parameters
• arc: pointer to arc object
• type: arc type
void lv_arc_set_value(lv_obj_t *arc, int16_t value)
Set a new value on the arc
Parameters
• arc: pointer to a arc object
• value: new value
void lv_arc_set_range(lv_obj_t *arc, int16_t min, int16_t max)
Set minimum and the maximum values of a arc
Parameters
• arc: pointer to the arc object
• min: minimum value
• max: maximum value
void lv_arc_set_chg_rate(lv_obj_t *arc, uint16_t threshold)
Set the threshold of arc knob increments position.
Parameters
• arc: pointer to a arc object
• threshold: increment threshold
void lv_arc_set_adjustable(lv_obj_t *arc, bool adjustable)
Set whether the arc is adjustable.
Parameters
• arc: pointer to a arc object
• adjustable: whether the arc has a knob that can be dragged
uint16_t lv_arc_get_angle_start(lv_obj_t *arc)
Get the start angle of an arc.
Return the start angle [0..360]
Parameters
• arc: pointer to an arc object
uint16_t lv_arc_get_angle_end(lv_obj_t *arc)
Get the end angle of an arc.
Return the end angle [0..360]
Parameters
• arc: pointer to an arc object
uint16_t lv_arc_get_bg_angle_start(lv_obj_t *arc)
Get the start angle of an arc background.
Return the start angle [0..360]
Parameters
Public Members
uint16_t rotation_angle
uint16_t arc_angle_start
uint16_t arc_angle_end
uint16_t bg_angle_start
uint16_t bg_angle_end
lv_style_list_t style_arc
lv_style_list_t style_knob
int16_t cur_value
int16_t min_value
int16_t max_value
uint16_t dragging
uint16_t type
uint16_t adjustable
uint16_t chg_rate
uint32_t last_tick
int16_t last_angle
5.3.1 Overview
The bar object has a background and an indicator on it. The width of the indicator is set according to the
current value of the bar.
Vertical bars can be created if the width of the object is smaller than its height.
Not only end, but the start value of the bar can be set which changes the start position of the indicator.
The Bar’s main part is called LV_BAR_PART_BG and it uses the typical background style properties.
LV_BAR_PART_INDIC is a virtual part which also uses all the typical background properties. By default
the indicator maximal size is the same as the background’s size but setting positive padding values in
LV_BAR_PART_BG will make the indicator smaller. (negative values will make it larger) If the value style
property is used on the indicator the alignment will be calculated based on the current size of the indicator.
For example a center aligned value is always shown in the middle of the indicator regardless it’s current size.
5.3.3 Usage
Modes
The bar can be drawn symmetrical to zero (drawn from zero, left to right), if it’s enabled with
lv_bar_set_type(bar, LV_BAR_TYPE_SYMMETRICAL).
5.3.4 Events
5.3.5 Keys
5.3.6 Example
Simple Bar
code
#include "../../../lv_examples.h"
#if LV_USE_BAR
void lv_ex_bar_1(void)
{
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
lv_obj_set_size(bar1, 200, 20);
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_anim_time(bar1, 2000);
lv_bar_set_value(bar1, 100, LV_ANIM_ON);
}
#endif
MicroPython
No examples yet.
5.3.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_BAR_TYPE_NORMAL
enumerator LV_BAR_TYPE_SYMMETRICAL
enumerator LV_BAR_TYPE_CUSTOM
enum [anonymous]
Bar parts
Values:
enumerator LV_BAR_PART_BG
enumerator LV_BAR_PART_INDIC
Bar background style.
enumerator _LV_BAR_PART_VIRTUAL_LAST
Bar fill area style.
Functions
Public Members
lv_obj_t *bar
lv_anim_value_t anim_start
lv_anim_value_t anim_end
lv_anim_value_t anim_state
struct lv_bar_ext_t
#include <lv_bar.h> Data of bar
Public Members
int16_t cur_value
int16_t min_value
int16_t max_value
int16_t start_value
lv_area_t indic_area
lv_anim_value_t anim_time
lv_bar_anim_t cur_value_anim
lv_bar_anim_t start_value_anim
uint8_t type
lv_style_list_t style_indic
5.4.1 Overview
Buttons are simple rectangle-like objects. They are derived from Containers so layout and fit are also
available. Besides, it can be enabled to automatically go to checked state on click.
The buttons has only a main style called LV_BTN_PART_MAIN and it can use all the properties from the
following groups:
• background
• border
• outline
• shadow
• value
• pattern
• transitions
It also uses the padding properties when layout or fit is enabled.
5.4.3 Usage
States
To make buttons usage simpler the button’s state can be get with lv_btn_get_state(btn). It returns
one of the following values:
• LV_BTN_STATE_RELEASED
• LV_BTN_STATE_PRESSED
• LV_BTN_STATE_CHECKED_RELEASED
• LV_BTN_STATE_CHECKED_PRESSED
• LV_BTN_STATE_DISABLED
With lv_btn_get_state(btn, LV_BTN_STATE_...) the buttons state can be changed manually.
If a more precise description of the state is required (e.g. focused) the general lv_obj_get_state(btn)
can be used.
Checkable
You can configure the buttons as toggle button with lv_btn_set_checkable(btn, true). In this case,
on click, the button goes to LV_STATE_CHECKED state automatically, or back when clicked again.
5.4.4 Events
Besides the Generic events the following Special events are sent by the buttons:
• LV_EVENT_VALUE_CHANGED - sent when the button is toggled.
Learn more about Events.
5.4.5 Keys
5.4.6 Example
Simple Buttons
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_BTN
void lv_ex_btn_1(void)
{
lv_obj_t * label;
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_BTN
/**
* Advanced button transition examples
*/
void lv_ex_btn_2(void)
{
static lv_anim_path_t path_overshoot;
lv_anim_path_init(&path_overshoot);
lv_anim_path_set_cb(&path_overshoot, lv_anim_path_overshoot);
/*Gum-like button*/
static lv_style_t style_gum;
lv_style_init(&style_gum);
lv_style_set_transform_width(&style_gum, LV_STATE_PRESSED, 10);
lv_style_set_transform_height(&style_gum, LV_STATE_PRESSED, -10);
lv_style_set_value_letter_space(&style_gum, LV_STATE_PRESSED, 5);
lv_style_set_transition_path(&style_gum, LV_STATE_DEFAULT, &path_overshoot);
lv_style_set_transition_path(&style_gum, LV_STATE_PRESSED, &path_ease_in_out);
lv_style_set_transition_time(&style_gum, LV_STATE_DEFAULT, 250);
lv_style_set_transition_delay(&style_gum, LV_STATE_DEFAULT, 100);
lv_style_set_transition_prop_1(&style_gum, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_
,→WIDTH);
/*Halo on press*/
static lv_style_t style_halo;
lv_style_init(&style_halo);
lv_style_set_transition_time(&style_halo, LV_STATE_PRESSED, 400);
lv_style_set_transition_time(&style_halo, LV_STATE_DEFAULT, 0);
lv_style_set_transition_delay(&style_halo, LV_STATE_DEFAULT, 200);
lv_style_set_outline_width(&style_halo, LV_STATE_DEFAULT, 0);
lv_style_set_outline_width(&style_halo, LV_STATE_PRESSED, 20);
lv_style_set_outline_opa(&style_halo, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_outline_opa(&style_halo, LV_STATE_FOCUSED, LV_OPA_COVER); /*Just␣
,→to be sure, the theme might use it*/
/*Ripple on press*/
static lv_style_t style_ripple;
lv_style_init(&style_ripple);
lv_style_set_transition_time(&style_ripple, LV_STATE_PRESSED, 300);
lv_style_set_transition_time(&style_ripple, LV_STATE_DEFAULT, 0);
lv_style_set_transition_delay(&style_ripple, LV_STATE_DEFAULT, 300);
lv_style_set_bg_opa(&style_ripple, LV_STATE_DEFAULT, 0);
lv_style_set_bg_opa(&style_ripple, LV_STATE_PRESSED, LV_OPA_80);
lv_style_set_border_width(&style_ripple, LV_STATE_DEFAULT, 0);
lv_style_set_outline_width(&style_ripple, LV_STATE_DEFAULT, 0);
lv_style_set_transform_width(&style_ripple, LV_STATE_DEFAULT, -20);
lv_style_set_transform_height(&style_ripple, LV_STATE_DEFAULT, -20);
lv_style_set_transform_width(&style_ripple, LV_STATE_PRESSED, 0);
lv_style_set_transform_height(&style_ripple, LV_STATE_PRESSED, 0);
}
#endif
MicroPython
No examples yet.
5.4.7 API
Typedefs
Enums
enum [anonymous]
Possible states of a button. It can be used not only by buttons but other button-like objects too
Values:
enumerator LV_BTN_STATE_RELEASED
enumerator LV_BTN_STATE_PRESSED
enumerator LV_BTN_STATE_DISABLED
enumerator LV_BTN_STATE_CHECKED_RELEASED
enumerator LV_BTN_STATE_CHECKED_PRESSED
enumerator LV_BTN_STATE_CHECKED_DISABLED
enumerator _LV_BTN_STATE_LAST
enum [anonymous]
Styles
Values:
enumerator LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN
enumerator _LV_BTN_PART_VIRTUAL_LAST
enumerator _LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST
Functions
Parameters
• btn: pointer to a button object
• state: the new state of the button (from lv_btn_state_t enum)
void lv_btn_toggle(lv_obj_t *btn)
Toggle the state of the button (ON->OFF, OFF->ON)
Parameters
• btn: pointer to a button object
void lv_btn_set_layout(lv_obj_t *btn, lv_layout_t layout)
Set the layout on a button
Parameters
• btn: pointer to a button object
• layout: a layout from ’lv_cont_layout_t’
void lv_btn_set_fit4(lv_obj_t *btn, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
Set the fit policy in all 4 directions separately. It tells how to change the button size automatically.
Parameters
• btn: pointer to a button object
• left: left fit policy from lv_fit_t
• right: right fit policy from lv_fit_t
• top: top fit policy from lv_fit_t
• bottom: bottom fit policy from lv_fit_t
void lv_btn_set_fit2(lv_obj_t *btn, lv_fit_t hor, lv_fit_t ver)
Set the fit policy horizontally and vertically separately. It tells how to change the button size auto-
matically.
Parameters
• btn: pointer to a button object
• hor: horizontal fit policy from lv_fit_t
• ver: vertical fit policy from lv_fit_t
void lv_btn_set_fit(lv_obj_t *btn, lv_fit_t fit)
Set the fit policy in all 4 direction at once. It tells how to change the button size automatically.
Parameters
• btn: pointer to a button object
• fit: fit policy from lv_fit_t
lv_btn_state_t lv_btn_get_state(const lv_obj_t *btn)
Get the current state of the button
Return the state of the button (from lv_btn_state_t enum) If the button is in disabled state
LV_BTN_STATE_DISABLED will be ORed to the other button states.
Parameters
• btn: pointer to a button object
Public Members
lv_cont_ext_t cont
Ext. of ancestor
uint8_t checkable
1: Toggle enabled
5.5.1 Overview
The Button Matrix objects can display multiple buttons in rows and columns.
The main reasons for wanting to use a button matrix instead of a container and individual button objects
are:
• The button matrix is simpler to use for grid-based button layouts.
• The button matrix consumes a lot less memory per button.
The Button matrix’s main part is called LV_BTNMATRIX_PART_BG. It draws a background using the typical
background style properties.
LV_BTNMATRIX_PART_BTN is virtual part and it refers to the buttons on the button matrix. It also uses
all the typical background properties.
The top/bottom/left/right padding values from the background are used to keep some space on the sides.
Inner padding is applied between the buttons.
5.5.3 Usage
Button’s text
There is a text on each button. To specify them a descriptor string array, called map, needs to be used. The
map can be set with lv_btnmatrix_set_map(btnm, my_map). The declaration of a map should look
like const char * map[] = {"btn1", "btn2", "btn3", ""}. Note that the last element has
to be an empty string!
Use "\n" in the map to make line break. E.g. {"btn1", "btn2", "\n", "btn3", ""}. Each line’s
buttons have their width calculated automatically.
Control buttons
The buttons width can be set relative to the other button in the same line with
lv_btnmatrix_set_btn_width(btnm, btn_id, width) E.g. in a line with two buttons: btnA,
width = 1 and btnB, width = 2, btnA will have 33 % width and btnB will have 66 % width. It’s similar to
how the flex-grow property works in CSS.
In addition to width, each button can be customized with the following parameters:
• LV_BTNMATRIX_CTRL_HIDDEN - make a button hidden (hidden buttons still take up space
in the layout, they are just not visible or clickable)
• LV_BTNMATRIX_CTRL_NO_REPEAT - disable repeating when the button is long pressed
• LV_BTNMATRIX_CTRL_DISABLED - make a button disabled
• LV_BTNMATRIX_CTRL_CHECKABLE - enable toggling of a button
• LV_BTNMATRIX_CTRL_CHECK_STATE - set the toggle state
• LV_BTNMATRIX_CTRL_CLICK_TRIG - if 0, the button will react on press, if 1, will react
on release
The set or clear a button’s control attribute, use lv_btnmatrix_set_btn_ctrl(btnm, btn_id,
LV_BTNM_CTRL_...) and lv_btnmatrix_clear_btn_ctrl(btnm, btn_id, LV_BTNM_CTRL_..
.) respectively. More LV_BTNM_CTRL_... values can be Ored
The set/clear the same control attribute for all buttons of a button matrix, use
lv_btnmatrix_set_btn_ctrl_all(btnm, btn_id, LV_BTNM_CTRL_...) and
lv_btnmatrix_clear_btn_ctrl_all(btnm, btn_id, LV_BTNM_CTRL_...).
The set a control map for a button matrix (similarly to the map for the text), use
lv_btnmatrix_set_ctrl_map(btnm, ctrl_map). An element of ctrl_map should look like
ctrl_map[0] = width | LV_BTNM_CTRL_NO_REPEAT | LV_BTNM_CTRL_TGL_ENABLE. The num-
ber of elements should be equal to the number of buttons (excluding newlines characters).
One check
The ”One check” feature can be enabled with lv_btnmatrix_set_one_check(btnm, true) to allow
only one button to be checked (toggled) at once.
Recolor
The texts on the button can be recolored similarly to the recolor feature for Label object. To enable it,
use lv_btnmatrix_set_recolor(btnm, true). After that a button with #FF0000 Red# text will
be red.
Notes
The Button matrix object is very light weighted because the buttons are not created just virtually drawn
on the fly. This way, 1 button use only 8 extra bytes instead of the ~100-150 byte size of a normal Button
object (plus the size of its container and a label for each button).
The disadvantage of this setup is that the ability to style individual buttons to be different from others is
limited (aside from the toggling feature). If you require that ability, using individual buttons is very likely
to be a better approach.
5.5.4 Events
Besides the Generic events, the following Special events are sent by the button matrices:
• LV_EVENT_VALUE_CHANGED - sent when the button is pressed/released or repeated after
long press. The event data is set to the ID of the pressed/released button.
Learn more about Events.
5.5.5 Keys
5.5.6 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_BTNMATRIX
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""};
void lv_ex_btnmatrix_1(void)
{
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide␣
,→as "Action2"*/
#endif
MicroPython
No examples yet.
5.5.7 API
Typedefs
Enums
enum [anonymous]
Type to store button control bits (disabled, hidden etc.) The first 3 bits are used to store the width
Values:
enumerator LV_BTNMATRIX_CTRL_HIDDEN = 0x0008
Button hidden
enumerator LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010
Do not repeat press this button.
enumerator LV_BTNMATRIX_CTRL_DISABLED = 0x0020
Disable this button.
enumerator LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040
Button can be toggled.
enumerator LV_BTNMATRIX_CTRL_CHECK_STATE = 0x0080
Button is currently toggled (e.g. checked).
enumerator LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100
1: Send LV_EVENT_SELECTED on CLICK, 0: Send LV_EVENT_SELECTED on PRESS
enum [anonymous]
Values:
enumerator LV_BTNMATRIX_PART_BG
enumerator LV_BTNMATRIX_PART_BTN
Functions
LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE)
lv_obj_t *lv_btnmatrix_create(lv_obj_t *par, const lv_obj_t *copy)
Create a button matrix objects
Return pointer to the created button matrix
Parameters
• par: pointer to an object, it will be the parent of the new button matrix
• copy: pointer to a button matrix object, if not NULL then the new object will be copied
from it
Public Members
5.6.1 Overview
The calendar’s main part is called LV_CALENDAR_PART_BG. It draws a background using the typical back-
ground style properties.
Besides the following virtual parts exist:
• LV_CALENDAR_PART_HEADER The upper area where the current year and month’s name is shown. It
also has buttons to move the next/previous month. It uses typical background properties plus padding
to adjust its size and margin to set the distance from the top of the calendar and the day names below
it.
• LV_CALENDAR_PART_DAY_NAMES Shows the name of the days below the header. It uses the text
style properties padding to keep some distance from the background (left, right), header (top) and
dates (bottom).
• LV_CALENDAR_PART_DATES Show the date numbers from 1..28/29/30/31 (depending on current
month). Different ”state” of the states are drawn according to the states defined in this part:
– normal dates: drawn with LV_STATE_DEFAULT style
– pressed date: drawn with LV_STATE_PRESSED style
– today: drawn with LV_STATE_FOCUSED style
– highlighted dates: drawn with LV_STATE_CHECKED style
5.6.3 Usage
5.6.4 Overview
To set and get dates in the calendar, the lv_calendar_date_t type is used which is a structure with
year, month and day fields.
Current date
Shown date
Highlighted days
5.6.5 Events
Besides the Generic events, the following Special events are sent by the calendars:
LV_EVENT_VALUE_CHANGED is sent when the current month has changed.
In Input device related events, lv_calendar_get_pressed_date(calendar) tells which day is cur-
rently being pressed or return NULL if no date is pressed.
5.6.6 Keys
5.6.7 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_CALENDAR
void lv_ex_calendar_1(void)
{
lv_obj_t * calendar = lv_calendar_create(lv_scr_act(), NULL);
lv_obj_set_size(calendar, 235, 235);
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(calendar, event_handler);
/*Make the date number smaller to be sure they fit into their area*/
lv_obj_set_style_local_text_font(calendar, LV_CALENDAR_PART_DATE, LV_STATE_
,→DEFAULT, lv_theme_get_font_small());
lv_calendar_set_today_date(calendar, &today);
lv_calendar_set_showed_date(calendar, &today);
highlighted_days[0].year = 2018;
highlighted_days[0].month = 10;
highlighted_days[0].day = 6;
highlighted_days[1].year = 2018;
highlighted_days[1].month = 10;
highlighted_days[1].day = 11;
highlighted_days[2].year = 2018;
highlighted_days[2].month = 11;
highlighted_days[2].day = 22;
#endif
MicroPython
No examples yet.
5.6.8 API
Typedefs
Enums
enum [anonymous]
Calendar parts
Values:
enumerator LV_CALENDAR_PART_BG
Background and ”normal” date numbers style
enumerator LV_CALENDAR_PART_HEADER
enumerator LV_CALENDAR_PART_DAY_NAMES
Calendar header style
enumerator LV_CALENDAR_PART_DATE
Day name style
Functions
Parameters
• calendar: pointer to a calendar object
uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t *calendar)
Get the number of the highlighted dates
Return number of highlighted days
Parameters
• calendar: pointer to a calendar object
const char **lv_calendar_get_day_names(const lv_obj_t *calendar)
Get the name of the days
Return pointer to the array of day names
Parameters
• calendar: pointer to a calendar object
const char **lv_calendar_get_month_names(const lv_obj_t *calendar)
Get the name of the month
Return pointer to the array of month names
Parameters
• calendar: pointer to a calendar object
struct lv_calendar_date_t
#include <lv_calendar.h> Represents a date on the calendar object (platform-agnostic).
Public Members
uint16_t year
int8_t month
int8_t day
struct lv_calendar_ext_t
Public Members
lv_calendar_date_t today
lv_calendar_date_t showed_date
lv_calendar_date_t *highlighted_dates
int8_t btn_pressing
uint16_t highlighted_dates_num
lv_calendar_date_t pressed_date
const char **day_names
const char **month_names
lv_style_list_t style_header
lv_style_list_t style_day_names
lv_style_list_t style_date_nums
5.7.1 Overview
A Canvas inherites from Image where the user can draw anything. Rectangles, texts, images, lines arcs can
be drawn here using lvgl’s drawing engine. Besides some ”effects” can be applied as well like rotation, zoom
and blur.
The Canvas has on one main part called LV_CANVAS_PART_MAIN and only the image_recolor property is
used to give a color to LV_IMG_CF_ALPHA_1/2/4/8BIT images.
5.7.3 Usage
Buffer
The Canvas needs a buffer which stores the drawn image. To assign a buffer to a Can-
vas, use lv_canvas_set_buffer(canvas, buffer, width, height, LV_IMG_CF_...). Where
buffer is a static buffer (not just a local variable) to hold the image of the canvas. For
example, static lv_color_t buffer[LV_CANVAS_BUF_SIZE_TRUE_COLOR(width, height)].
LV_CANVAS_BUF_SIZE_... macros help to determine the size of the buffer with different color formats.
The canvas supports all the built-in color formats like LV_IMG_CF_TRUE_COLOR or
LV_IMG_CF_INDEXED_2BIT. See the full list in the Color formats section.
Palette
Drawing
Transformations
lv_canvas_transform() can be used to rotate and/or scale the image of an image and store the result
on the canvas. The function needs the following parameters:
• canvas pointer to a canvas object to store the result of the transformation.
• img pointer to an image descriptor to transform. Can be the image descriptor of an other canvas
too (lv_canvas_get_img()).
• angle the angle of rotation (0..3600), 0.1 deg resolution
• zoom zoom factor (256 no zoom, 512 double size, 128 half size);
• offset_x offset X to tell where to put the result data on destination canvas
• offset_y offset X to tell where to put the result data on destination canvas
• pivot_x pivot X of rotation. Relative to the source canvas. Set to source width / 2 to rotate
around the center
• pivot_y pivot Y of rotation. Relative to the source canvas. Set to source height / 2 to rotate
around the center
• antialias true: apply anti-aliasing during the transformation. Looks better but slower.
Note that a canvas can’t be rotated on itself. You need a source and destination canvas or image.
5.7.4 Blur
A given area of the canvas can be blurred horizontally with lv_canvas_blur_hor(canvas, &area,
r) to vertically with lv_canvas_blur_ver(canvas, &area, r). r is the radius of the blur (greater
value means more intensive burring). area is the area where the blur should be applied (interpreted relative
to the canvas)
5.7.5 Events
As default the clicking of a canvas is disabled (inherited by Image) and therefore no events are generated.
If clicking is enabled (lv_obj_set_click(canvas, true)) only the Generic events are sent by the
object type.
Learn more about Events.
5.7.6 Keys
5.7.7 Example
code
#include "../../../lv_examples.h"
#if LV_USE_CANVAS
void lv_ex_canvas_1(void)
{
(continues on next page)
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = LV_COLOR_YELLOW;
/* Test the rotation. It requires an other buffer where the orignal image is␣
,→stored.
* So copy the current image to buffer and rotate it to the canvas */
static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
lv_img_dsc_t img;
img.data = (void *)cbuf_tmp;
img.header.cf = LV_IMG_CF_TRUE_COLOR;
img.header.w = CANVAS_WIDTH;
img.header.h = CANVAS_HEIGHT;
#endif
code
#include "../../../lv_examples.h"
#if LV_USE_CANVAS
#define CANVAS_WIDTH 50
#define CANVAS_HEIGHT 50
/**
* Create a transparent canvas with Chroma keying and indexed color format (palette).
*/
void lv_ex_canvas_2(void)
{
/*Create a button to better see the transparency*/
lv_btn_create(lv_scr_act(), NULL);
lv_canvas_set_palette(canvas, 0, LV_COLOR_TRANSP);
lv_canvas_set_palette(canvas, 1, LV_COLOR_RED);
c0.full = 0;
c1.full = 1;
(continues on next page)
/*Transparent background*/
lv_canvas_fill_bg(canvas, c1, LV_OPA_TRANSP);
}
#endif
MicroPython
No examples yet.
5.7.8 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_CANVAS_PART_MAIN
Functions
• buf: a buffer where the content of the canvas will be. The required size is
(lv_img_color_format_get_px_size(cf) * w) / 8 * h) It can be allocated with
lv_mem_alloc() or it can be statically allocated array (e.g. static lv_color_t buf[100*50])
or it can be an address in RAM or external SRAM
• canvas: pointer to a canvas object
• w: width of the canvas
• h: height of the canvas
• cf: color format. LV_IMG_CF_...
void lv_canvas_set_px(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y, lv_color_t c)
Set the color of a pixel on the canvas
Parameters
• canvas:
• x: x coordinate of the point to set
• y: x coordinate of the point to set
• c: color of the point
void lv_canvas_set_palette(lv_obj_t *canvas, uint8_t id, lv_color_t c)
Set the palette color of a canvas with index format. Valid only for LV_IMG_CF_INDEXED1/2/4/8
Parameters
• canvas: pointer to canvas object
• id: the palette color to set:
– for LV_IMG_CF_INDEXED1: 0..1
– for LV_IMG_CF_INDEXED2: 0..3
– for LV_IMG_CF_INDEXED4: 0..15
– for LV_IMG_CF_INDEXED8: 0..255
• c: the color to set
lv_color_t lv_canvas_get_px(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y)
Get the color of a pixel on the canvas
Return color of the point
Parameters
• canvas:
• x: x coordinate of the point to set
• y: x coordinate of the point to set
lv_img_dsc_t *lv_canvas_get_img(lv_obj_t *canvas)
Get the image of the canvas as a pointer to an lv_img_dsc_t variable.
Return pointer to the image descriptor.
Parameters
• canvas: pointer to a canvas object
Parameters
• canvas: pointer to a canvas object
• points: point of the line
• point_cnt: number of points
• line_draw_dsc: pointer to an initialized lv_draw_line_dsc_t variable
void lv_canvas_draw_polygon(lv_obj_t *canvas, const lv_point_t points[], uint32_t
point_cnt, const lv_draw_rect_dsc_t *poly_draw_dsc)
Draw a polygon on the canvas
Parameters
• canvas: pointer to a canvas object
• points: point of the polygon
• point_cnt: number of points
• poly_draw_dsc: pointer to an initialized lv_draw_rect_dsc_t variable
void lv_canvas_draw_arc(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y, lv_coord_t r,
int32_t start_angle, int32_t end_angle, const lv_draw_line_dsc_t
*arc_draw_dsc)
Draw an arc on the canvas
Parameters
• canvas: pointer to a canvas object
• x: origo x of the arc
• y: origo y of the arc
• r: radius of the arc
• start_angle: start angle in degrees
• end_angle: end angle in degrees
• arc_draw_dsc: pointer to an initialized lv_draw_line_dsc_t variable
struct lv_canvas_ext_t
Public Members
lv_img_ext_t img
lv_img_dsc_t dsc
5.8.1 Overview
The Checkbox objects are built from a Button background which contains an also Button bullet and a Label
to realize a classical checkbox.
The Check box’s main part is called LV_CHECKBOX_PART_BG. It’s a container for a ”bullet” and a text
next to it. The background uses all the typical background style properties.
The bullet is real lv_obj object and can be referred with LV_CHECKBOX_PART_BULLET. The bullet auto-
matically inherits the state of the background. So the background is pressed the bullet goes to pressed state
as well. The bullet also uses all the typical background style properties.
There is not dedicated part for the label. Its styles can be set in the background’s styles because the text
styles properties are always inherited.
5.8.3 Usage
Text
The text can be modified by the lv_checkbox_set_text(cb, "New text") function. It will dynam-
ically allocate the text.
To set a static text, use lv_checkbox_set_static_text(cb, txt). This way, only a pointer of txt
will be stored and it shouldn’t be deallocated while the checkbox exists.
Check/Uncheck
You can manually check / un-check the Checkbox via lv_checkbox_set_checked(cb, true/false).
Setting true will check the checkbox and false will un-check the checkbox.
Disabled
You can get the current state of the Checkbox with the lv_checkbox_get_state(cb) func-
tion which returns the current state. You can set the current state of the Checkbox with
the lv_checkbox_set_state(cb, state). The available states as defined by the enum
lv_btn_state_t are:
• LV_BTN_STATE_RELEASED
• LV_BTN_STATE_PRESSED
• LV_BTN_STATE_DISABLED
• LV_BTN_STATE_CHECKED_RELEASED
• LV_BTN_STATE_CHECKED_PRESSED
• LV_BTN_STATE_CHECKED_DISABLED
5.8.4 Events
Besides the Generic events the following Special events are sent by the Checkboxes:
• LV_EVENT_VALUE_CHANGED - sent when the checkbox is toggled.
Note that, the generic input device-related events (like LV_EVENT_PRESSED) are sent in the inactive state
too. You need to check the state with lv_cb_is_inactive(cb) to ignore the events from inactive
Checkboxes.
Learn more about Events.
5.8.5 Keys
5.8.6 Example
Simple Checkbox
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_CHECKBOX
void lv_ex_checkbox_1(void)
{
lv_obj_t * cb = lv_checkbox_create(lv_scr_act(), NULL);
lv_checkbox_set_text(cb, "I agree to terms and conditions.");
lv_obj_align(cb, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(cb, event_handler);
}
#endif
MicroPython
No examples yet.
5.8.7 API
Typedefs
Enums
enum [anonymous]
Checkbox styles.
Values:
enumerator LV_CHECKBOX_PART_BG = LV_BTN_PART_MAIN
Style of object background.
enumerator _LV_CHECKBOX_PART_VIRTUAL_LAST
enumerator LV_CHECKBOX_PART_BULLET = _LV_BTN_PART_REAL_LAST
Style of box (released).
enumerator _LV_CHECKBOX_PART_REAL_LAST
Functions
Public Members
lv_btn_ext_t bg_btn
lv_obj_t *bullet
lv_obj_t *label
5.9.1 Overview
Charts are a basic object to visualize data points. They support Line charts (connect points with lines
and/or draw points on them) and Column charts.
Charts also support division lines, 2 y axis, axis ticks, and texts on ticks.
The Chart’s main part is called LV_CHART_PART_BG and it uses all the typical background properties.
The text style properties determine the style of the axis texts and the line properties determine ticks’ style.
Padding values add some space on the sides thus it makes series area smaller. Padding also can be used to
make space for axis texts and ticks.
The background of the series is called LV_CHART_PART_SERIES_BG and it’s placed on the main back-
ground. The division lines, and series data is drawn on this part. Besides the typical background style
properties the line style properties are used by the division lines. The padding values tells the space between
the this part and the axis texts.
The style of the series can be referenced by LV_CHART_PART_SERIES. In case of column type the following
properties are used:
• radius: radius of the bars
5.9.3 Usage
Data series
You can add any number of series to the charts by lv_chart_add_series(chart, color). It allocates
data for a lv_chart_series_t structure which contains the chosen color and an array for the data points
if not using an external array, if an external array is assigned any internal points associated with the series
are deallocated and the series points to the external array instead.
Series’ type
Use LV_CHART_POINT_DEF as value to make the library skip drawing that point, column, or line segment.
If you wish a plot to start from a point other than the default which is point[0] of the series, you can set
an alternative index with the function lv_chart_set_x_start_point(chart, ser, id) where id is
the new index position to start plotting from.
You can make the chart series update from an external data source by assigning it with the function:
lv_chart_set_ext_array(chart, ser, array, point_cnt ) where array is an external array
of lv_coord_t with point_cnt elements. Note: you should call lv_chart_refresh(chart) after the
external data source has been updated, to update the chart.
Update modes
Number of points
Vertical range
You can specify the minimum and maximum values in y-direction with lv_chart_set_range(chart,
y_min, y_max). The value of the points will be scaled proportionally. The default range is: 0..100.
Division lines
Cursor
5.9.4 Events
5.9.5 Keys
5.9.6 Example
Line Chart
code
#include "../../../lv_examples.h"
#if LV_USE_CHART
void lv_ex_chart_1(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
#endif
code
#include "../../../lv_examples.h"
#if LV_USE_CHART
/**
* Add a faded area effect to the line chart
*/
void lv_ex_chart_2(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
#endif
MicroPython
No examples yet.
5.9.7 API
Typedefs
Enums
enum [anonymous]
Chart types
Values:
enumerator LV_CHART_TYPE_NONE = 0x00
Don’t draw the series
enumerator LV_CHART_TYPE_LINE = 0x01
Connect the points with lines
enumerator LV_CHART_TYPE_COLUMN = 0x02
Draw columns
enumerator LV_CHART_TYPE_SCATTER = 0x03
X/Y chart, points and/or lines
enum [anonymous]
Chart update mode for lv_chart_set_next
Values:
enumerator LV_CHART_UPDATE_MODE_SHIFT
Shift old data to the left and add the new one o the right
enumerator LV_CHART_UPDATE_MODE_CIRCULAR
Add the new data in a circular way
enum [anonymous]
Values:
enumerator LV_CHART_AXIS_PRIMARY_Y
enumerator LV_CHART_AXIS_SECONDARY_Y
enumerator _LV_CHART_AXIS_LAST
enum [anonymous]
Data of axis
Values:
enumerator LV_CHART_AXIS_SKIP_LAST_TICK = 0x00
don’t draw the last tick
Functions
LV_EXPORT_CONST_INT(LV_CHART_POINT_DEF)
LV_EXPORT_CONST_INT(LV_CHART_TICK_LENGTH_AUTO)
lv_obj_t *lv_chart_create(lv_obj_t *par, const lv_obj_t *copy)
Create a chart background objects
Return pointer to the created chart background
Parameters
• par: pointer to an object, it will be the parent of the new chart background
• copy: pointer to a chart background object, if not NULL then the new object will be copied
from it
lv_chart_series_t *lv_chart_add_series(lv_obj_t *chart, lv_color_t color)
Allocate and add a data series to the chart
Return pointer to the allocated data series
Parameters
• chart: pointer to a chart object
• color: color of the data series
void lv_chart_clear_series(lv_obj_t *chart, lv_chart_series_t *series)
Clear the point of a series
Parameters
• chart: pointer to a chart object
• series: pointer to the chart’s series to clear
void lv_chart_set_div_line_count(lv_obj_t *chart, uint8_t hdiv, uint8_t vdiv)
Set the number of horizontal and vertical division lines
Parameters
• chart: pointer to a graph background object
• hdiv: number of horizontal division lines
• vdiv: number of vertical division lines
Public Members
lv_coord_t *points
lv_color_t color
uint16_t start_point
uint8_t ext_buf_assigned
lv_chart_axis_t y_axis
struct lv_chart_axis_cfg_t
Public Members
Public Members
lv_ll_t series_ll
lv_coord_t ymin[_LV_CHART_AXIS_LAST]
lv_coord_t ymax[_LV_CHART_AXIS_LAST]
uint8_t hdiv_cnt
uint8_t vdiv_cnt
uint16_t point_cnt
lv_style_list_t style_series_bg
lv_style_list_t style_series
lv_chart_type_t type
lv_chart_axis_cfg_t y_axis
lv_chart_axis_cfg_t x_axis
lv_chart_axis_cfg_t secondary_y_axis
uint8_t update_mode
5.10.1 Overview
The containers are essentially a basic object with some special features.
Layout
You can apply a layout on the containers to automatically order their children. The layout spacing comes
from style.body.padding. ... properties. The possible layout options:
• LV_LAYOUT_OFF - Do not align the children.
• LV_LAYOUT_CENTER - Align children to the center in column and keep padding.inner
space between them.
• LV_LAYOUT_COL_ - Align children in a left-justified column. Keep padding.left space on
the left, pad.top space on the top and padding.inner space between the children.
• LV_LAYOUT_COL_M - Align children in centered column. Keep padding.top space on the
top and padding.inner space between the children.
• LV_LAYOUT_COL_R - Align children in a right-justified column. Keep padding.right space
on the right, padding.top space on the top and padding.inner space between the children.
• LV_LAYOUT_ROW_T - Align children in a top justified row. Keep padding.left space on
the left, padding.top space on the top and padding.inner space between the children.
• LV_LAYOUT_ROW_M - Align children in centered row. Keep padding.left space on the
left and padding.inner space between the children.
• LV_LAYOUT_ROW_B - Align children in a bottom justified row. Keep padding.left space
on the left, padding.bottom space on the bottom and padding.inner space between the children.
• LV_LAYOUT_PRETTY - Put as many objects as possible in a row (with at least padding.
inner space and padding.left/right space on the sides). Divide the space in each line equally
between the children. Keep padding.top space on the top and pad.inner space between the lines.
• LV_LAYOUT_GRID - Similar to LV_LAYOUT_PRETTY but not divide horizontal space equally
just let padding.left/right on the edges and padding.inner space between the elements.
Autofit
Container have an autofit feature which can automatically change the size of the container according to its
children and/or parent. The following options exist:
• LV_FIT_NONE - Do not change the size automatically.
• LV_FIT_TIGHT - Shrink-wrap the container around all of its children, while keeping padding.
top/bottom/left/right space on the edges.
• LV_FIT_FLOOD - Set the size to the parent’s size minus padding.top/bottom/left/right
(from the parent’s style) space.
• LV_FIT_FILL - Use LV_FIT_FLOOD while smaller than the parent and LV_FIT_TIGHT when
larger. It will ensure that the container is, at minimum, the size of its parent.
To set the auto fit mode for all directions, use lv_cont_set_fit(cont, LV_FIT_...). To
use different auto fit horizontally and vertically, use lv_cont_set_fit2(cont, hor_fit_type,
ver_fit_type). To use different auto fit in all 4 directions, use lv_cont_set_fit4(cont,
left_fit_type, right_fit_type, top_fit_type, bottom_fit_type).
5.10.2 Styles
5.10.3 Events
5.10.4 Keys
5.10.5 Example
code
#include "../../../lv_examples.h"
#if LV_USE_CONT
void lv_ex_cont_1(void)
{
lv_obj_t * cont;
lv_cont_set_fit(cont, LV_FIT_TIGHT);
lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_MID);
lv_obj_t * label;
label = lv_label_create(cont, NULL);
lv_label_set_text(label, "Short text");
/*Refresh and pause here for a while to see how `fit` works*/
uint32_t t;
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 500);
#endif
MicroPython
No examples yet.
5.10.6 API
Typedefs
Enums
enum [anonymous]
Container layout options
Values:
enumerator LV_LAYOUT_OFF = 0
No layout
enumerator LV_LAYOUT_CENTER
Center objects
enumerator LV_LAYOUT_COLUMN_LEFT
COULMN:
• Place the object below each other
• Keep pad_top space on the top
• Keep pad_inner space between the objectsColumn left align
enumerator LV_LAYOUT_COLUMN_MID
Column middle align
enumerator LV_LAYOUT_COLUMN_RIGHT
Column right align
enumerator LV_LAYOUT_ROW_TOP
ROW:
• Place the object next to each other
• Keep pad_left space on the left
• Keep pad_inner space between the objects
• If the object which applies the layout has base_dir == LV_BIDI_DIR_RTL the row will
start from the right applying pad.right spaceRow top align
enumerator LV_LAYOUT_ROW_MID
Row middle align
enumerator LV_LAYOUT_ROW_BOTTOM
Row bottom align
enumerator LV_LAYOUT_PRETTY_TOP
PRETTY:
• Place the object next to each other
• If there is no more space start a new row
• Respect pad_left and pad_right when determining the available space in a row
• Keep pad_inner space between the objects in the same row
• Keep pad_inner space between the objects in rows
• Divide the remaining horizontal space equallyRow top align
enumerator LV_LAYOUT_PRETTY_MID
Row middle align
enumerator LV_LAYOUT_PRETTY_BOTTOM
Row bottom align
enumerator LV_LAYOUT_GRID
GRID
• Place the object next to each other
• If there is no more space start a new row
• Respect pad_left and pad_right when determining the available space in a row
• Keep pad_inner space between the objects in the same row
• Keep pad_inner space between the objects in rows
• Unlike PRETTY, GRID always keep pad_inner space horizontally between objects so it
doesn’t divide the remaining horizontal space equallyAlign same-sized object into a grid
enumerator _LV_LAYOUT_LAST
enum [anonymous]
How to resize the container around the children.
Values:
enumerator LV_FIT_NONE
Do not change the size automatically
enumerator LV_FIT_TIGHT
Shrink wrap around the children
enumerator LV_FIT_PARENT
Align the size to the parent’s edge
enumerator LV_FIT_MAX
Align the size to the parent’s edge first but if there is an object out of it then get larger
enumerator _LV_FIT_LAST
enum [anonymous]
Values:
enumerator LV_CONT_PART_MAIN = LV_OBJ_PART_MAIN
enumerator _LV_CONT_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_LAST
enumerator _LV_CONT_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST
Functions
Parameters
• cont: pointer to a container object
lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t *cont)
Get bottom fit mode of a container
Return an element of lv_fit_t
Parameters
• cont: pointer to a container object
struct lv_cont_ext_t
Public Members
lv_layout_t layout
lv_fit_t fit_left
lv_fit_t fit_right
lv_fit_t fit_top
lv_fit_t fit_bottom
5.11.1 Overview
As its name implies Color picker allows to select color. The Hue, Saturation and Value of the color can be
selected after each other.
The widget has two forms: circle (disc) and rectangle.
In both forms, be long pressing the object, the color picker will change to the next parameter of the color
(hue, saturation or value). Besides, double click will reset the current parameter.
The Color picker’s main part is called LV_CPICKER_PART_BG. In circular form it uses scale_width to set
the the width of the circle and pad_inner for padding between the circle and the inner preview circle. In
rectangle mode radius can be used to apply a radius on the rectangle.
The object has virtual part called LV_CPICKER_PART_KNOB which is rectangle (or circle) drawn on the
current value. It uses all the rectangle like style properties and padding to make it larger than the width of
the circle or rectangle background.
5.11.3 Usage
Type
Set color
Color mode
Knob color
5.11.4 Events
5.11.5 Keys
5.11.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_CPICKER
void lv_ex_cpicker_1(void)
{
lv_obj_t * cpicker;
#endif
MicroPython
No examples yet.
5.11.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_CPICKER_TYPE_RECT
enumerator LV_CPICKER_TYPE_DISC
enum [anonymous]
Values:
enumerator LV_CPICKER_COLOR_MODE_HUE
enumerator LV_CPICKER_COLOR_MODE_SATURATION
enumerator LV_CPICKER_COLOR_MODE_VALUE
enum [anonymous]
Values:
enumerator LV_CPICKER_PART_MAIN = LV_OBJ_PART_MAIN
enumerator LV_CPICKER_PART_KNOB = _LV_OBJ_PART_VIRTUAL_LAST
enumerator _LV_CPICKER_PART_VIRTUAL_LAST
enumerator _LV_CPICKER_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST
Functions
Public Members
lv_color_hsv_t hsv
lv_style_list_t style_list
lv_point_t pos
uint8_t colored
struct lv_cpicker_ext_t::[anonymous] knob
uint32_t last_click_time
uint32_t last_change_time
lv_point_t last_press_point
lv_cpicker_color_mode_t color_mode
uint8_t color_mode_fixed
lv_cpicker_type_t type
5.12.1 Overview
The drop-down list allows the user to select one value from a list.
The drop-down list is closed by default and displays a single value or a predefined text. When activated
(by click on the drop-down list), a list is created from which the user may select one option. When the user
selects a new value, the list is deleted.
The drop-down list’s main part is called LV_DROPDOWN_PART_MAIN which is a simple lv_obj object. It
uses all the typical background properties. Pressed, Focused, Edited etc. stiles are also applied as usual.
The list, which is created when the main object is clicked, is an Page. Its background part can be referenced
with LV_DROPDOWN_PART_LIST and uses all the typical background properties for the rectangle itself
and text properties for the options. To adjust the space between the options use the text_line_space style
property. Padding values can be used to make some space on the edges.
The scrollable part of the page is hidden and its styles are always empty (so transparent with no padding).
The scrollbar can be referenced with LV_DROPDOWN_PART_SCRLBAR and uses all the typical background
properties.
The selected option can be referenced with LV_DROPDOWN_PART_SELECTED and uses all the typical back-
ground properties. It will used in its default state to draw a rectangle on the selected option, and in pressed
state to draw a rectangle on the being pressed option.
5.12.3 Usage
5.12.4 Overview
Set options
The options are passed to the drop-down list as a string with lv_dropdown_set_options(dropdown,
options). The options should be separated by \n. For example: "First\nSecond\nThird". The
string will be saved in the drop-down list, so it can in local variable too.
The lv_dropdown_add_option(dropdown, "New option", pos) function inserts a new option to
pos index.
To save memory the options can set from a static(constant) string too with
lv_dropdown_set_static_options(dropdown, options). In this case the options string
should be alive while the drop-down list exists and lv_dropdown_add_option can’t be used
You can select an option manually with lv_dropdown_set_selected(dropdown, id), where id is
the index of an option.
The get the currently selected option, use lv_dropdown_get_selected(dropdown). It will return the
index of the selected option.
lv_dropdown_get_selected_str(dropdown, buf, buf_size) copies the name of the selected op-
tion to a buf.
Direction
The list can be created on any side. The default LV_DROPDOWN_DOWN can be modified by
lv_dropdown_set_dir(dropdown, LV_DROPDOWN_DIR_LEFT/RIGHT/UP/DOWN) function.
If the list would be vertically out of the screen, it will aligned to the edge.
Symbol
A symbol (typically an arrow) can be added to the drop down list with
lv_dropdown_set_symbol(dropdown, LV_SYMBOL_...)
If the direction of the drop-down list is LV_DROPDOWN_DIR_LEFT the symbol will be shown on the left,
else on the right.
Maximum height
Show selected
The main part can either show the selected option or a static text. It can controlled with
lv_dropdown_set_show_selected(sropdown, true/false).
The static text can be set with lv_dropdown_set_text(dropdown, "Text"). Only the pointer of
the text is saved.
Animation time
Manually open/close
5.12.5 Events
Besides the Generic events, the following Special events are sent by the drop-down list:
• LV_EVENT_VALUE_CHANGED - Sent when the new option is selected.
Learn more about Events.
5.12.6 Keys
5.12.7 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
void lv_ex_dropdown_1(void)
{
#endif
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_DROPDOWN
/**
* Create a drop LEFT menu
*/
void lv_ex_dropdown_2(void)
{
/*Create a drop down list*/
lv_obj_t * ddlist = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options(ddlist, "Apple\n"
"Banana\n"
"Orange\n"
"Melon\n"
"Grape\n"
"Raspberry");
lv_dropdown_set_dir(ddlist, LV_DROPDOWN_DIR_LEFT);
lv_dropdown_set_symbol(ddlist, NULL);
lv_dropdown_set_show_selected(ddlist, false);
lv_dropdown_set_text(ddlist, "Fruits");
/*It will be called automatically when the size changes*/
lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 20);
MicroPython
No examples yet.
5.12.8 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_DROPDOWN_DIR_DOWN
enumerator LV_DROPDOWN_DIR_UP
enumerator LV_DROPDOWN_DIR_LEFT
enumerator LV_DROPDOWN_DIR_RIGHT
enum [anonymous]
Values:
enumerator LV_DROPDOWN_PART_MAIN = LV_OBJ_PART_MAIN
enumerator LV_DROPDOWN_PART_LIST = _LV_OBJ_PART_REAL_LAST
enumerator LV_DROPDOWN_PART_SCROLLBAR
enumerator LV_DROPDOWN_PART_SELECTED
Functions
Parameters
• ddlist: pointer to drop down list object
• symbol: a text like LV_SYMBOL_DOWN or NULL to not draw icon
void lv_dropdown_set_show_selected(lv_obj_t *ddlist, bool show)
Set whether the ddlist highlight the last selected option and display its text or not
Parameters
• ddlist: pointer to a drop down list object
• show: true/false
const char *lv_dropdown_get_text(lv_obj_t *ddlist)
Get text of the ddlist (Displayed on the button if show_selected = false)
Return the text string
Parameters
• ddlist: pointer to a drop down list object
const char *lv_dropdown_get_options(const lv_obj_t *ddlist)
Get the options of a drop down list
Return the options separated by ’ ’-s (E.g. ”Option1\nOption2\nOption3”)
Parameters
• ddlist: pointer to drop down list object
uint16_t lv_dropdown_get_selected(const lv_obj_t *ddlist)
Get the selected option
Return id of the selected option (0 ... number of option - 1);
Parameters
• ddlist: pointer to drop down list object
uint16_t lv_dropdown_get_option_cnt(const lv_obj_t *ddlist)
Get the total number of options
Return the total number of options in the list
Parameters
• ddlist: pointer to drop down list object
void lv_dropdown_get_selected_str(const lv_obj_t *ddlist, char *buf, uint32_t buf_size)
Get the current selected option as a string
Parameters
• ddlist: pointer to ddlist object
• buf: pointer to an array to store the string
• buf_size: size of buf in bytes. 0: to ignore it.
lv_coord_t lv_dropdown_get_max_height(const lv_obj_t *ddlist)
Get the fix height value.
Return the height if the ddlist is opened (0: auto size)
Parameters
Public Members
lv_obj_t *page
const char *text
const char *symbol
char *options
lv_style_list_t style_selected
lv_style_list_t style_page
lv_style_list_t style_scrlbar
lv_coord_t max_height
uint16_t option_cnt
uint16_t sel_opt_id
uint16_t sel_opt_id_orig
uint16_t pr_opt_id
lv_dropdown_dir_t dir
uint8_t show_selected
uint8_t static_txt
5.13.1 Overview
The gauge is a meter with scale labels and one or more needles.
The Gauge’s main part is called LV_GAUGE_PART_MAIN. It draws a background using the typical back-
ground style properties and ”minor” scale lines using the line and scale style properties. It also uses the text
properties to set the style of the scale labels. pad_inner is used to set space between the scale lines and the
scale labels.
LV_GAUGE_PART_MAJOR is a virtual part which describes the major scale lines (where labels are added)
using the line and scale style properties.
LV_GAUGE_PART_NEEDLE is also virtual part and it describes the needle(s) via the line style properties.
The size and the typical background properties are used to describe a rectangle (or circle) in the pivot point
of the needle(s). pad_inner is used to to make the needle(s) smaller than the outer radius of the scale lines.
5.13.3 Usage
The gauge can show more than one needle. Use the lv_gauge_set_needle_count(gauge,
needle_num, color_array) function to set the number of needles and an array with colors for each
needle. The array must be static or global variable because only its pointer is stored.
You can use lv_gauge_set_value(gauge, needle_id, value) to set the value of a needle.
Scale
You can use the lv_gauge_set_scale(gauge, angle, line_num, label_cnt) function to adjust
the scale angle and the number of the scale lines and labels. The default settings are 220 degrees, 6 scale
labels, and 21 lines.
The scale of the Gauge can have offset. It can be adjusted with lv_gauge_set_angle_offset(gauge,
angle).
Range
The range of the gauge can be specified by lv_gauge_set_range(gauge, min, max). The default
range is 0..100.
Needle image
An images also can be used as needles. The image should point to the right (like ==>). To set an image
use lv_gauge_set_needle_img(gauge1, &img, pivot_x, pivot_y). pivot_x and pivot_y
are offset of the rotation center from the top left corner. Images will be recolored to the needle’s color with
image_recolor_opa (style property) intensity.
Critical value
To set a critical value, use lv_gauge_set_critical_value(gauge, value). The scale color will be
changed to scale_end_color after this value. The default critical value is 80.
5.13.4 Events
5.13.5 Keys
5.13.6 Example
Simple Gauge
code
#include "../../../lv_examples.h"
#if LV_USE_GAUGE
void lv_ex_gauge_1(void)
{
/*Describe the color for the needles*/
static lv_color_t needle_colors[3];
needle_colors[0] = LV_COLOR_BLUE;
needle_colors[1] = LV_COLOR_ORANGE;
needle_colors[2] = LV_COLOR_PURPLE;
/*Create a gauge*/
lv_obj_t * gauge1 = lv_gauge_create(lv_scr_act(), NULL);
lv_gauge_set_needle_count(gauge1, 3, needle_colors);
lv_obj_set_size(gauge1, 200, 200);
lv_obj_align(gauge1, NULL, LV_ALIGN_CENTER, 0, 0);
#endif
MicroPython
No examples yet.
5.13.7 API
Typedefs
typedef void (*lv_gauge_format_cb_t)(lv_obj_t *gauge, char *buf, int bufsize, int32_t value)
typedef uint8_t lv_gauge_style_t
Enums
enum [anonymous]
Values:
enumerator LV_GAUGE_PART_MAIN = LV_LINEMETER_PART_MAIN
enumerator LV_GAUGE_PART_MAJOR = _LV_LINEMETER_PART_VIRTUAL_LAST
enumerator LV_GAUGE_PART_NEEDLE
enumerator _LV_GAUGE_PART_VIRTUAL_LAST = _LV_LINEMETER_PART_VIRTUAL_LAST
enumerator _LV_GAUGE_PART_REAL_LAST = _LV_LINEMETER_PART_REAL_LAST
Functions
Parameters
• gauge: pointer to a gauge object
uint16_t lv_gauge_get_angle_offset(lv_obj_t *gauge)
Get the offset for the gauge.
Return angle offset (0..360)
Parameters
• gauge: pointer to a gauge object
const void *lv_gauge_get_needle_img(lv_obj_t *gauge)
Get an image to display as needle(s).
Return pointer to an lv_img_dsc_t variable or a path to an image (not an lv_img object). NULL
if not used.
Parameters
• gauge: pointer to a gauge object
lv_coord_t lv_gauge_get_needle_img_pivot_x(lv_obj_t *gauge)
Get the X coordinate of the rotation center of the needle image
Return the X coordinate of rotation center of the image
Parameters
• gauge: pointer to a gauge object
lv_coord_t lv_gauge_get_needle_img_pivot_y(lv_obj_t *gauge)
Get the Y coordinate of the rotation center of the needle image
Return the X coordinate of rotation center of the image
Parameters
• gauge: pointer to a gauge object
struct lv_gauge_ext_t
Public Members
lv_linemeter_ext_t lmeter
int32_t *values
const lv_color_t *needle_colors
const void *needle_img
lv_point_t needle_img_pivot
lv_style_list_t style_needle
lv_style_list_t style_strong
uint8_t needle_count
uint8_t label_count
lv_gauge_format_cb_t format_cb
5.14.1 Overview
Images are the basic object to display from the flash (as arrays) or externally as files. Images can display
symbols (LV_SYMBOL_...) too.
Using the Image decoder interface custom image formats can be supported as well.
The images has only a main part called LV_IMG_PART_MAIN which uses the typical background style
propeties to draw a background rectangle and the image properties. The padding values are used to make
the background virtually larger. (It won’t change the image’s real size but the size modification is applied
only during drawing)
5.14.3 Usage
Image source
Label as an image
Images and labels are sometimes used to convey the same thing. For example, to describe what a button
does. Therefore, images and labels are somewhat interchangeable. To handle these images can even dis-
play texts by using LV_SYMBOL_DUMMY as the prefix of the text. For example, lv_img_set_src(img,
LV_SYMBOL_DUMMY "Some text").
Transparency
The internal (variable) and external images support 2 transparency handling methods:
• Chrome keying - Pixels with LV_COLOR_TRANSP (lv_conf.h) color will be transparent.
• Alpha byte - An alpha byte is added to every pixel.
Besides True color (RGB) color format, the following formats are also supported:
• Indexed - Image has a palette.
• Alpha indexed - Only alpha values are stored.
These options can be selected in the font converter. To learn more about the color formats, read the Images
section.
Recolor
The images can be re-colored in run-time to any color according to the brightness of the pixels. It is
very useful to show different states (selected, inactive, pressed, etc.) of an image without storing more
versions of the same image. This feature can be enabled in the style by setting img.intense between
LV_OPA_TRANSP (no recolor, value: 0) and LV_OPA_COVER (full recolor, value: 255). The default value is
LV_OPA_TRANSP so this feature is disabled.
Auto-size
It is possible to automatically set the size of the image object to the image source’s width and height if
enabled by the lv_img_set_auto_size(image, true) function. If auto-size is enabled, then when
a new file is set, the object size is automatically changed. Later, you can modify the size manually. The
auto-size is enabled by default if the image is not a screen.
Mosaic
If the object size is greater than the image size in any directions, then the image will be repeated like a
mosaic. It’s a very useful feature to create a large image from only a very narrow source. For example, you
can have a 300 x 1 image with a special gradient and set it as a wallpaper using the mosaic feature.
Offset
5.14.4 Transformations
Using the lv_img_set_zoom(img, factor) the images will be zoomed. Set factor to 256 or
LV_IMG_ZOOM_NONE to disable zooming. A larger value enlarges the images (e.g. 512 double size), a
smaller value shrinks it (e.g. 128 half size). Fractional scale works as well. E.g. 281 for 10% enlargement.
To rotate the image use lv_img_set_angle(img, angle). Angle has 0.1 degree precision, so for 45.8°
set 458.
By default, the pivot point of the rotation is the center of the image. It can be changed with
lv_img_set_pivot(img, pivot_x, pivot_y). 0;0 is the top left corner.
The quality of the transformation can be adjusted with lv_img_set_antialias(img, true/false).
With enabled anti-aliasing the transformations has a higher quality but they are slower.
The transformations require the whole image to be available. Therefore indexed images
(LV_IMG_CF_INDEXED_...), alpha only images (LV_IMG_CF_ALPHA_...) or images from files can be
transformed. In other words transformations work only on true color images stored as C array, or if a custom
Image decoder returns the whole image.
Note that, the real coordinates of image object won’t change during transformation. That is
lv_obj_get_width/height/x/y() will returned the original, non-zoomed coordinates.
5.14.5 Rotate
5.14.6 Events
5.14.7 Keys
5.14.8 Example
code
#include "../../../lv_examples.h"
#if LV_USE_IMG
void lv_ex_img_1(void)
{
lv_obj_t * img1 = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img1, &img_cogwheel_argb);
lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0, -20);
#endif
Image recoloring
code
#include "../../../lv_examples.h"
#if LV_USE_IMG
#define SLIDER_WIDTH 20
void lv_ex_img_2(void)
{
/*Create 4 sliders to adjust RGB color and re-color intensity*/
create_sliders();
lv_obj_set_event_cb(red_slider, slider_event_cb);
#endif
MicroPython
No examples yet.
5.14.9 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_IMG_PART_MAIN
Functions
Parameters
• img: pointer to an image
lv_coord_t lv_img_get_offset_y(lv_obj_t *img)
Get the offset.y attribute of the img object.
Return offset.y value.
Parameters
• img: pointer to an image
uint16_t lv_img_get_angle(lv_obj_t *img)
Get the rotation angle of the image.
Return rotation angle in degree (0..359)
Parameters
• img: pointer to an image object
void lv_img_get_pivot(lv_obj_t *img, lv_point_t *center)
Get the rotation center of the image.
Parameters
• img: pointer to an image object
• center: rotation center of the image
uint16_t lv_img_get_zoom(lv_obj_t *img)
Get the zoom factor of the image.
Return zoom factor (256: no zoom)
Parameters
• img: pointer to an image object
bool lv_img_get_antialias(lv_obj_t *img)
Get whether the transformations (rotate, zoom) are anti-aliased or not
Return true: anti-aliased; false: not anti-aliased
Parameters
• img: pointer to an image object
struct lv_img_ext_t
Public Members
uint8_t auto_size
uint8_t cf
uint8_t antialias
5.15.1 Overview
The Image button is very similar to the simple ’Button’ object. The only difference is that, it displays
user-defined images in each state instead of drawing a rectangle. Before reading this section, please read the
Button section for better understanding.
The Image button object has only a main part called LV_IMG_BTN_PART_MAIN from where all image
style properties are used. It’s possible to recolor the image in each state with image_recolor and im-
age_recolor_opa proeprties. For example, to make the image darker if it is pressed.
5.15.3 Usage
Image sources
Button features
5.15.4 Events
Beside the Generic events, the following Special events are sent by the buttons:
• LV_EVENT_VALUE_CHANGED - Sent when the button is toggled.
Note that, the generic input device related events (like LV_EVENT_PRESSED) are sent in the inactive state
too. You need to check the state with lv_btn_get_state(btn) to ignore the events from inactive
buttons.
Learn more about Events.
5.15.5 Keys
5.15.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_IMGBTN
void lv_ex_imgbtn_1(void)
{
LV_IMG_DECLARE(imgbtn_green);
LV_IMG_DECLARE(imgbtn_blue);
#endif
MicroPython
No examples yet.
5.15.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_IMGBTN_PART_MAIN = LV_BTN_PART_MAIN
Functions
Public Members
lv_btn_ext_t btn
const void *img_src_mid[_LV_BTN_STATE_LAST]
const void *img_src_left[_LV_BTN_STATE_LAST]
const void *img_src_right[_LV_BTN_STATE_LAST]
lv_img_cf_t act_cf
uint8_t tiled
5.16.1 Overview
The Keyboard object is a special Button matrix with predefined keymaps and other features to realize a
virtual keyboard to write text.
5.16.3 Usage
Modes
You can assign a Text area to the Keyboard to automatically put the clicked characters there. To assign the
text area, use lv_keyboard_set_textarea(kb, ta).
The assigned text area’s cursor can be managed by the keyboard: when the keyboard is assigned, the
previous text area’s cursor will be hidden and the new one will be shown. When the keyboard is closed
by the Ok or Close buttons, the cursor also will be hidden. The cursor manager feature is enabled by
lv_keyboard_set_cursor_manage(kb, true). The default is not managed.
New Keymap
You can specify a new map (layout) for the keyboard with lv_keyboard_set_map(kb, map) and
lv_keyboard_set_ctrl_map(kb, ctrl_map). Learn more about the Button matrix object. Keep
in mind that, using following keywords will have the same effect as with the original map:
• LV_SYMBOL_OK - Apply.
• LV_SYMBOL_CLOSE - Close.
• LV_SYMBOL_BACKSPACE - Delete on the left.
• LV_SYMBOL_LEFT - Move the cursor left.
• LV_SYMBOL_RIGHT - Move the cursor right.
• ”ABC” - Load the uppercase map.
• ”abc” - Load the lower case map.
• ”Enter” - New line.
5.16.4 Events
Besides the Generic events, the following Special events are sent by the keyboards:
• LV_EVENT_VALUE_CHANGED - Sent when the button is pressed/released or repeated after
long press. The event data is set to the ID of the pressed/released button.
• LV_EVENT_APPLY - The Ok button is clicked.
• LV_EVENT_CANCEL - The Close button is clicked.
The keyboard has a default event handler callback called lv_keyboard_def_event_cb. It handles
the button pressing, map changing, the assigned text area, etc. You can completely replace it with your
custom event handler however, you can call lv_keyboard_def_event_cb at the beginning of your event
handler to handle the same things as before.
Learn more about Events.
5.16.5 Keys
5.16.6 Examples
code
#include "../../../lv_examples.h"
#if LV_USE_KEYBOARD
void lv_ex_keyboard_1(void)
{
/*Create a keyboard and apply the styles*/
lv_obj_t *kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_keyboard_set_cursor_manage(kb, true);
MicroPython
No examples yet.
5.16.7 API
Typedefs
Enums
enum [anonymous]
Current keyboard mode.
Values:
enumerator LV_KEYBOARD_MODE_TEXT_LOWER
enumerator LV_KEYBOARD_MODE_TEXT_UPPER
enumerator LV_KEYBOARD_MODE_SPECIAL
enumerator LV_KEYBOARD_MODE_NUM
enum [anonymous]
Values:
enumerator LV_KEYBOARD_PART_BG
enumerator LV_KEYBOARD_PART_BTN
Functions
Parameters
• kb: pointer to a Keyboard object
• mode: the mode from ’lv_keyboard_mode_t’
void lv_keyboard_set_cursor_manage(lv_obj_t *kb, bool en)
Automatically hide or show the cursor of the current Text Area
Parameters
• kb: pointer to a Keyboard object
• en: true: show cursor on the current text area, false: hide cursor
void lv_keyboard_set_map(lv_obj_t *kb, lv_keyboard_mode_t mode, const char *map[])
Set a new map for the keyboard
Parameters
• kb: pointer to a Keyboard object
• mode: keyboard map to alter ’lv_keyboard_mode_t’
• map: pointer to a string array to describe the map. See ’lv_btnmatrix_set_map()’ for more
info.
void lv_keyboard_set_ctrl_map(lv_obj_t *kb, lv_keyboard_mode_t mode, const
lv_btnmatrix_ctrl_t ctrl_map[])
Set the button control map (hidden, disabled etc.) for the keyboard. The control map array will be
copied and so may be deallocated after this function returns.
Parameters
• kb: pointer to a keyboard object
• mode: keyboard ctrl map to alter ’lv_keyboard_mode_t’
• ctrl_map: pointer to an array of lv_btn_ctrl_t control bytes. See:
lv_btnmatrix_set_ctrl_map for more details.
lv_obj_t *lv_keyboard_get_textarea(const lv_obj_t *kb)
Assign a Text Area to the Keyboard. The pressed characters will be put there.
Return pointer to the assigned Text Area object
Parameters
• kb: pointer to a Keyboard object
lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t *kb)
Set a new a mode (text or number map)
Return the current mode from ’lv_keyboard_mode_t’
Parameters
• kb: pointer to a Keyboard object
bool lv_keyboard_get_cursor_manage(const lv_obj_t *kb)
Get the current cursor manage mode.
Return true: show cursor on the current text area, false: hide cursor
Parameters
• kb: pointer to a Keyboard object
Public Members
lv_btnmatrix_ext_t btnm
lv_obj_t *ta
lv_keyboard_mode_t mode
uint8_t cursor_mng
5.17.1 Overview
The label has only a main part, called LV_LABEL_PART_MAIN. It uses all the typical background properties
and the text properties. The padding values can be used to make the area for the text small in the related
direction.
5.17.3 Usage
Set text
You can set the text on a label at runtime with lv_label_set_text(label, "New text"). It will
allocate a buffer dynamically, and the provided string will be copied into that buffer. Therefore, you don’t
need to keep the text you pass to lv_label_set_text in scope after that function returns.
With lv_label_set_text_fmt(label, "Value: %d", 15) printf formatting can be used to set
the text.
Labels are able to show text from a static character buffer which is \0-terminated. To do so, use
lv_label_set_static_text(label, "Text"). In this case, the text is not stored in the dy-
namic memory and the given buffer is used directly instead. This means that the array can’t be a
local variable which goes out of scope when the function exits. Constant strings are safe to use with
lv_label_set_static_text (except when used with LV_LABEL_LONG_DOT, as it modifies the buffer
in-place), as they are stored in ROM memory, which is always accessible.
You can also use a raw array as label text. The array doesn’t have to be \0 terminated. In this case, the
text will be saved to the dynamic memory like with lv_label_set_text. To set a raw character array,
use the lv_label_set_array_text(label, char_array, size) function.
Line break
Line breaks are handled automatically by the label object. You can use \n to make a line break. For
example: "line1\nline2\n\nline4"
Long modes
By default, the width of the label object automatically expands to the text size. Otherwise, the text can be
manipulated according to several long mode policies:
• LV_LABEL_LONG_EXPAND - Expand the object size to the text size (Default)
• LV_LABEL_LONG_BREAK - Keep the object width, break (wrap) the too long lines and expand
the object height
• LV_LABEL_LONG_DOT - Keep the object size, break the text and write dots in the last line
(not supported when using lv_label_set_static_text)
• LV_LABEL_LONG_SROLL - Keep the size and scroll the label back and forth
• LV_LABEL_LONG_SROLL_CIRC - Keep the size and scroll the label circularly
• LV_LABEL_LONG_CROP - Keep the size and crop the text out of it
You can specify the long mode with lv_label_set_long_mode(label, LV_LABEL_LONG_...)
It’s important to note that, when a label is created and its text is set, the label’s size already expanded to
the text size. In addition with the default LV_LABEL_LONG_EXPAND, long mode lv_obj_set_width/
height/size() has no effect.
So you need to change the long mode first set the new long mode and then set the size with
lv_obj_set_width/height/size().
Another important note is that LV_LABEL_LONG_DOT manipulates the text buffer in-place in or-
der to add/remove the dots. When lv_label_set_text or lv_label_set_array_text are used,
a separate buffer is allocated and this implementation detail is unnoticed. This is not the case with
lv_label_set_static_text! The buffer you pass to lv_label_set_static_text must be
writable if you plan to use LV_LABEL_LONG_DOT.
Text align
The lines of the text can be aligned to the left, right or center with lv_label_set_align(label,
LV_LABEL_ALIGN_LEFT/RIGHT/CENTER). Note that, it will align only the lines, not the label object
itself.
Vertical alignment is not supported by the label itself; you should place the label inside a larger container
and align the whole label object instead.
Text recolor
In the text, you can use commands to recolor parts of the text. For example: "Write a #ff0000 red#
word". This feature can be enabled individually for each label by lv_label_set_recolor() function.
Note that, recoloring work only in a single line. Therefore, \n should not use in a recolored text or it should
be wrapped by LV_LABEL_LONG_BREAK else, the text in the new line won’t be recolored.
Lvgl can efficiently handle very long (> 40k characters) by saving some extra data (~12 bytes) to speed up
drawing. To enable this feature, set LV_LABEL_LONG_TXT_HINT 1 in lv_conf.h.
Symbols
The labels can display symbols alongside letters (or on their own). Read the Font section to learn more
about the symbols.
5.17.4 Events
5.17.5 Keys
5.17.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_LABEL
void lv_ex_label_1(void)
{
lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_long_mode(label1, LV_LABEL_LONG_BREAK); /*Break the long lines*/
lv_label_set_recolor(label1, true); /*Enable re-coloring by␣
,→commands in the text*/
#endif
Text shadow
code
#include "../../../lv_examples.h"
#if LV_USE_LABEL
void lv_ex_label_2(void)
{
/* Create a style for the shadow*/
static lv_style_t label_shadow_style;
lv_style_init(&label_shadow_style);
lv_style_set_text_opa(&label_shadow_style, LV_STATE_DEFAULT, LV_OPA_50);
lv_style_set_text_color(&label_shadow_style, LV_STATE_DEFAULT, LV_COLOR_RED);
#endif
Align labels
code
#include "../../../lv_examples.h"
#if LV_USE_LABEL
lv_obj_t * labels[3];
/**
* Create three labels to demonstrate the alignments.
*/
void lv_ex_label_3(void)
{
/*`lv_label_set_align` is not required to align the object itslef.
* It's used only when the text has multiple lines*/
static uint8_t i = 0;
lv_label_set_text(labels[0], texts[i]);
lv_label_set_text(labels[1], texts[i]);
lv_label_set_text(labels[2], texts[i]);
i++;
if(texts[i] == NULL) i = 0;
}
#endif
MicroPython
No examples yet.
5.17.7 API
Typedefs
Enums
enum [anonymous]
Long mode behaviors. Used in ’lv_label_ext_t’
Values:
enumerator LV_LABEL_LONG_EXPAND
Expand the object size to the text size
enumerator LV_LABEL_LONG_BREAK
Keep the object width, break the too long lines and expand the object height
enumerator LV_LABEL_LONG_DOT
Keep the size and write dots at the end if the text is too long
enumerator LV_LABEL_LONG_SROLL
Keep the size and roll the text back and forth
enumerator LV_LABEL_LONG_SROLL_CIRC
Keep the size and roll the text circularly
enumerator LV_LABEL_LONG_CROP
Keep the size and crop the text out of it
enum [anonymous]
Label align policy
Values:
enumerator LV_LABEL_ALIGN_LEFT
Align text to left
enumerator LV_LABEL_ALIGN_CENTER
Align text to center
enumerator LV_LABEL_ALIGN_RIGHT
Align text to right
enumerator LV_LABEL_ALIGN_AUTO
Use LEFT or RIGHT depending on the direction of the text (LTR/RTL)
enum [anonymous]
Label styles
Values:
enumerator LV_LABEL_PART_MAIN
Functions
LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM)
LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST)
LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SEL_OFF)
lv_obj_t *lv_label_create(lv_obj_t *par, const lv_obj_t *copy)
Create a label objects
Return pointer to the created button
Parameters
Parameters
• label: pointer to a label object.
• index: index to set. LV_LABEL_TXT_SEL_OFF to select nothing.
Parameters
• label: pointer to a label object.
• index: index to set. LV_LABEL_TXT_SEL_OFF to select nothing.
Public Members
char *text
char *tmp_ptr
char tmp[LV_LABEL_DOT_NUM + 1]
union lv_label_ext_t::[anonymous] dot
uint32_t dot_end
uint16_t anim_speed
lv_point_t offset
lv_draw_label_hint_t hint
uint32_t sel_start
uint32_t sel_end
lv_label_long_mode_t long_mode
uint8_t static_txt
uint8_t align
uint8_t recolor
uint8_t expand
uint8_t dot_tmp_alloc
5.18.1 Overview
The LEDs are rectangle-like (or circle) object. It’s brightness can be adjusted. With lower brightness the
the colors of the LED become darker.
The LEDs have only one main part, called LV_LED_PART_MAIN and it uses all the typical background style
properties.
5.18.3 Usage
Brightness
You can set their brightness with lv_led_set_bright(led, bright). The brightness should be be-
tween 0 (darkest) and 255 (lightest).
Toggle
Use lv_led_on(led) and lv_led_off(led) to set the brightness to a predefined ON or OFF value.
The lv_led_toggle(led) toggles between the ON and OFF state.
5.18.4 Events
5.18.5 Keys
5.18.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_LED
void lv_ex_led_1(void)
{
/*Create a LED and switch it OFF*/
lv_obj_t * led1 = lv_led_create(lv_scr_act(), NULL);
lv_obj_align(led1, NULL, LV_ALIGN_CENTER, -80, 0);
lv_led_off(led1);
#endif
MicroPython
No examples yet.
5.18.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_LED_PART_MAIN = LV_OBJ_PART_MAIN
Functions
Public Members
uint8_t bright
5.19.1 Overview
The Line object is capable of drawing straight lines between a set of points.
The Line has only a main part, called LV_LABEL_PART_MAIN. It uses all the line style properties.
5.19.3 Usage
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. It can be enable 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. 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 teh obejct. The y invert is disabled by default.
5.19.4 Events
5.19.5 Keys
5.19.6 Example
Simple Line
code
#include "../../../lv_examples.h"
#if LV_USE_LINE
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 style*/
static lv_style_t style_line;
lv_style_init(&style_line);
(continues on next page)
#endif
MicroPython
No examples yet.
5.19.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_LINE_PART_MAIN
Functions
Public Members
5.20.1 Overview
The Lists are built from a background Page and Buttons on it. The Buttons contain an optional icon-like
Image (which can be a symbol too) and a Label. When the list becomes long enough it can be scrolled.
5.20.3 Usage
Add buttons
You can add new list elements (button) with lv_list_add_btn(list, &icon_img, "Text") or with
symbol lv_list_add_btn(list, SYMBOL_EDIT, "Edit text"). If you do not want to add image
use NULL as image source. The function returns with a pointer to the created button to allow further
configurations.
The width of the buttons is set to maximum according to the object width. The height of the buttons are
adjusted automatically according to the content. (content height + padding_top + padding_bottom).
The labels are created with LV_LABEL_LONG_SROLL_CIRC long mode to automatically scroll the long
labels circularly.
lv_list_get_btn_label(list_btn) and lv_list_get_btn_img(list_btn) can be used
to get the label and the image of a list button. The text can be et directly with
lv_list_get_btn_text(list_btn).
Delete buttons
To delete a list element just use lv_obj_del(btn) on the return value of lv_list_add_btn().
To clean the list (remove all buttons) use lv_list_clean(list)
Manual navigation
You can navigate manually in the list with lv_list_up(list) and lv_list_down(list).
You can focus on a button directly using lv_list_focus(btn, LV_ANIM_ON/OFF).
The animation time of up/down/focus movements can be set via: lv_list_set_anim_time(list,
anim_time). Zero animation time means not animations.
Layout
Edge flash
A circle-like effect can be shown when the list reaches the most top or bottom position.
lv_list_set_edge_flash(list, true) enables this feature.
Scroll propagation
If the list is created on an other scrollable element (like a Page) and the list can’t be scrolled further the
scrolling can be propagated to the parent. This way the scroll will be continued on the parent. It can be
enabled with lv_list_set_scroll_propagation(list, true)
5.20.4 Events
5.20.5 Keys
5.20.6 Example
Simple List
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_LIST
void lv_ex_list_1(void)
{
/*Create a list*/
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_size(list1, 160, 200);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
#endif
MicroPython
No examples yet.
5.20.7 API
Typedefs
Enums
enum [anonymous]
List styles.
Values:
enumerator LV_LIST_PART_BG = LV_PAGE_PART_BG
List background style
enumerator LV_LIST_PART_SCROLLBAR = LV_PAGE_PART_SCROLLBAR
List scrollbar style.
enumerator LV_LIST_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH
List edge flash style.
enumerator _LV_LIST_PART_VIRTUAL_LAST = _LV_PAGE_PART_VIRTUAL_LAST
enumerator LV_LIST_PART_SCROLLABLE = LV_PAGE_PART_SCROLLABLE
List scrollable area style.
enumerator _LV_LIST_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST
Functions
Public Members
lv_page_ext_t page
lv_obj_t *last_sel_btn
lv_obj_t *act_sel_btn
5.21.1 Overview
The Line meter object consists of some radial lines which draw a scale. Setting a value for the Line meter
will change the color of the scale lines proportionally.
The Line meter has only a main part, called LV_LINEMETER_PART_MAIN. It uses all the typical background
properties the draw a rectangle-like or circle background and the line and scale properties to draw the scale
lines. The active lines (which are related to smaller values the the current value) are colored from line_color
to scale_grad_color. The lines in the end (after the current value) are set to scale_end_color color.
5.21.3 Usage
Set value
The lv_linemeter_set_range(linemeter, min, max) function sets the range of the line meter.
You can set the angle of the scale and the number of the lines by:
lv_linemeter_set_scale(linemeter, angle, line_num). The default angle is 240 and
the default line number is 31.
Angle offset
By default the scale angle is interpreted symmetrically to the y axis. It results in ”standing” line meter.
With lv_linemeter_set_angle_offset an offset can be added the scale angle. It can used e.g to put
a quarter line meter into a corner or a half line meter to the right or left side.
Mirror
By default the Line meter’s lines are activated clock-wise. It can be changed using
lv_linemeter_set_mirror(linemeter, true/false).
5.21.4 Events
5.21.5 Keys
5.21.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_LINEMETER
void lv_ex_linemeter_1(void)
{
/*Create a line meter */
lv_obj_t * lmeter;
lmeter = lv_linemeter_create(lv_scr_act(), NULL);
lv_linemeter_set_range(lmeter, 0, 100); /*Set the range*/
lv_linemeter_set_value(lmeter, 80); /*Set the current␣
,→value*/
#endif
MicroPython
No examples yet.
5.21.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_LINEMETER_PART_MAIN
enumerator _LV_LINEMETER_PART_VIRTUAL_LAST
enumerator _LV_LINEMETER_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST
Functions
Public Members
uint16_t scale_angle
uint16_t angle_ofs
uint16_t line_cnt
int32_t cur_value
int32_t min_value
int32_t max_value
uint8_t mirrored
5.22.1 Overview
The Message boxes act as pop-ups. They are built from a background Container, a Label and a Button
matrix for buttons.
The text will be broken into multiple lines automatically (has LV_LABEL_LONG_MODE_BREAK) and the
height will be set automatically to involve the text and the buttons (LV_FIT_TIGHT fit vertically)-
The Message box’s main part is called LV_MSGBOX_PART_MAIN and it uses all the typical background style
properties. Using padding will add space on the sides. pad_inner will add space between the text and the
buttons. The label style properties affect the style of text.
The buttons parts are the same as in case of Button matrix:
• LV_MSGBOX_PART_BTN_BG the background of the buttons
• LV_MSGBOX_PART_BTN the buttons
5.22.3 Usage
Set text
To set the text use the lv_msgbox_set_text(msgbox, "My text") function. Not only the pointer of
the text will be saved, so the the text can be in a local variable too.
Add buttons
To add buttons use the lv_msgbox_add_btns(msgbox, btn_str) function. The button’s text needs
to be specified like const char * btn_str[] = {"Apply", "Close", ""}. For more information
visit the Button matrix documentation.
The button matrix will be created only when lv_msgbox_add_btns() is called for the first time.
Auto-close
5.22.4 Events
Besides the Generic events the following Special events are sent by the Message boxes:
• LV_EVENT_VALUE_CHANGED sent when the button is clicked. The event data is set to ID
of the clicked button.
The Message box has a default event callback which closes itself when a button is clicked.
Learn more about Events.
##Keys
The following Keys are processed by the Buttons:
• LV_KEY_RIGHT/DOWN Select the next button
• LV_KEY_LEFT/TOP Select the previous button
• LV_KEY_ENTER Clicks the selected button
Learn more about Keys.
5.22.5 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_MSGBOX
void lv_ex_msgbox_1(void)
{
static const char * btns[] ={"Apply", "Close", ""};
#endif
Modal
code
#include "../../../lv_examples.h"
#if LV_USE_MSGBOX
static const char welcome_info[] = "Welcome to the modal message box demo!\n"
"Press the button to display a message box.";
static const char in_msg_info[] = "Notice that you cannot touch "
"the button again while the message box is open.";
void lv_ex_msgbox_2(void)
{
lv_style_init(&style_modal);
lv_style_set_bg_color(&style_modal, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_label_set_text(info, in_msg_info);
lv_obj_align(info, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5);
}
}
#endif
MicroPython
No examples yet.
5.22.6 API
Typedefs
Enums
enum [anonymous]
Message box styles.
Values:
enumerator LV_MSGBOX_PART_BG = LV_CONT_PART_MAIN
enumerator LV_MSGBOX_PART_BTN_BG = _LV_CONT_PART_REAL_LAST
enumerator LV_MSGBOX_PART_BTN
Functions
Parameters
• mbox: pointer to message box object
uint16_t lv_msgbox_get_anim_time(const lv_obj_t *mbox)
Get the animation duration (close animation time)
Return animation length in milliseconds (0: no animation)
Parameters
• mbox: pointer to a message box object
bool lv_msgbox_get_recolor(const lv_obj_t *mbox)
Get whether recoloring is enabled
Return whether recoloring is enabled
Parameters
• mbox: pointer to a message box object
lv_obj_t *lv_msgbox_get_btnmatrix(lv_obj_t *mbox)
Get message box button matrix
Return pointer to button matrix object
Remark return value will be NULL unless lv_msgbox_add_btns has been already called
Parameters
• mbox: pointer to a message box object
struct lv_msgbox_ext_t
Public Members
lv_cont_ext_t bg
lv_obj_t *text
lv_obj_t *btnm
uint16_t anim_time
5.23.1 Overview
The Object mask is capable of add some mask to drawings when its children is drawn.
The Object mask has only a main part called LV_OBJMASK_PART_BG and it uses the typical background
style properties.
5.23.3 Usage
Adding mask
Before adding a mask to the Object mask the mask should be initialized:
lv_draw_mask_<type>_param_t mask_param;
lv_draw_mask_<type>_init(&mask_param, ...);
lv_objmask_mask_t * mask_p = lv_objmask_add_mask(objmask, &mask_param);
Update mask
Remove mask
5.23.4 Events
5.23.5 Keys
5.23.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_OBJMASK
void lv_ex_objmask_1(void)
{
/*Set a very visible color for the screen to clearly see what happens*/
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,␣
,→lv_color_hex3(0xf33));
uint32_t t;
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_area_t a;
lv_draw_mask_radius_param_t r1;
a.x1 = 10;
a.y1 = 10;
a.x2 = 190;
a.y2 = 190;
lv_draw_mask_radius_init(&r1, &a, LV_RADIUS_CIRCLE, false);
lv_objmask_add_mask(om, &r1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
a.x1 = 100;
a.y1 = 100;
a.x2 = 150;
a.y2 = 150;
lv_draw_mask_radius_init(&r1, &a, LV_RADIUS_CIRCLE, true);
lv_objmask_add_mask(om, &r1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_draw_mask_line_param_t l1;
lv_draw_mask_line_points_init(&l1, 0, 0, 100, 200, LV_DRAW_MASK_LINE_SIDE_TOP);
lv_objmask_add_mask(om, &l1);
lv_refr_now(NULL);
t = lv_tick_get();
while(lv_tick_elaps(t) < 1000);
lv_draw_mask_fade_param_t f1;
a.x1 = 100;
a.y1 = 0;
a.x2 = 200;
a.y2 = 200;
lv_draw_mask_fade_init(&f1, &a, LV_OPA_TRANSP, 0, LV_OPA_COVER, 150);
lv_objmask_add_mask(om, &f1);
#endif
Text mask
code
#include "../../../lv_examples.h"
#if LV_USE_OBJMASK
void lv_ex_objmask_2(void)
{
/*Draw a label to the canvas. The result "image" will be used as mask*/
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = LV_COLOR_WHITE;
lv_canvas_draw_text(canvas, 5, 5, MASK_WIDTH, &label_dsc, "Text with gradient",␣
,→LV_LABEL_ALIGN_CENTER);
/* Create and object with the gradient style on the object mask.
* The text will be masked from the gradient*/
lv_obj_t * bg = lv_obj_create(om, NULL);
lv_obj_reset_style_list(bg, LV_OBJ_PART_MAIN);
lv_obj_add_style(bg, LV_OBJ_PART_MAIN, &style_bg);
lv_obj_set_size(bg, MASK_WIDTH, MASK_HEIGHT);
#endif
MicroPython
No examples yet.
5.23.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_OBJMASK_PART_MAIN
Functions
Public Members
void *param
struct lv_objmask_ext_t
Public Members
lv_cont_ext_t cont
lv_ll_t mask_ll
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_DRAW_MASK_RES_TRANSP
enumerator LV_DRAW_MASK_RES_FULL_COVER
enumerator LV_DRAW_MASK_RES_CHANGED
enumerator LV_DRAW_MASK_RES_UNKNOWN
enum [anonymous]
Values:
enumerator LV_DRAW_MASK_TYPE_LINE
enumerator LV_DRAW_MASK_TYPE_ANGLE
enumerator LV_DRAW_MASK_TYPE_RADIUS
enumerator LV_DRAW_MASK_TYPE_FADE
enumerator LV_DRAW_MASK_TYPE_MAP
enum [anonymous]
Values:
enumerator LV_DRAW_MASK_LINE_SIDE_LEFT = 0
enumerator LV_DRAW_MASK_LINE_SIDE_RIGHT
enumerator LV_DRAW_MASK_LINE_SIDE_TOP
enumerator LV_DRAW_MASK_LINE_SIDE_BOTTOM
Functions
Public Members
lv_draw_mask_xcb_t cb
lv_draw_mask_type_t type
struct lv_draw_mask_line_param_t
Public Members
lv_draw_mask_common_dsc_t dsc
lv_point_t p1
lv_point_t p2
lv_draw_mask_line_side_t side
struct lv_draw_mask_line_param_t::[anonymous] cfg
lv_point_t origo
int32_t xy_steep
int32_t yx_steep
int32_t steep
int32_t spx
uint8_t flat
uint8_t inv
struct lv_draw_mask_angle_param_t
Public Members
lv_draw_mask_common_dsc_t dsc
lv_point_t vertex_p
lv_coord_t start_angle
lv_coord_t end_angle
struct lv_draw_mask_angle_param_t::[anonymous] cfg
lv_draw_mask_line_param_t start_line
lv_draw_mask_line_param_t end_line
uint16_t delta_deg
struct lv_draw_mask_radius_param_t
Public Members
lv_draw_mask_common_dsc_t dsc
lv_area_t rect
lv_coord_t radius
uint8_t outer
struct lv_draw_mask_radius_param_t::[anonymous] cfg
int32_t y_prev
lv_sqrt_res_t y_prev_x
struct lv_draw_mask_fade_param_t
Public Members
lv_draw_mask_common_dsc_t dsc
lv_area_t coords
lv_coord_t y_top
lv_coord_t y_bottom
lv_opa_t opa_top
lv_opa_t opa_bottom
struct lv_draw_mask_fade_param_t::[anonymous] cfg
struct _lv_draw_mask_map_param_t
Public Members
lv_draw_mask_common_dsc_t dsc
lv_area_t coords
const lv_opa_t *map
struct _lv_draw_mask_map_param_t::[anonymous] cfg
struct _lv_draw_mask_saved_t
Public Members
void *param
void *custom_id
5.24.1 Overview
The Page’s main part is called LV_PAGE_PART_BG which is the background of the Page. It uses all the
typical background style properties. Using padding will add space on the sides.
The scrollable object can be referenced via the LV_PAGE_PART_SCRL part. It also uses all the typical
background style properties and padding to add space on the sides.
LV_LIST_PART_SCROLLBAR is a virtual part of the background to draw the scroll bars. Uses all the typical
background style properties, size to set the width of the scroll bars, and pad_right and pad_bottom to set
the spacing.
LV_LIST_PART_EDGE_FLASHis also a virtual part of the background to draw a semicircle on the sides
when the list can not be scrolled in that direction further. Uses all the typical background properties.
5.24.3 Usage
The background object can be referenced as the page itself like. E.g. to set the page’s width:
lv_obj_set_width(page, 100).
If a child is created on the page it will be automatically moved to the scrollable container. If the scrollable
container becomes larger then the background it can be scrolled by dragging (like the lists on smartphones).
By default, the scrollable’s has LV_FIT_MAX fit in all directions. It means the scrollable size will be the
same as the background’s size (minus the padding) while the children are in the background. But when an
object is positioned out of the background the scrollable size will be increased to involve it.
Scrollbars
Glue object
A children can be ”glued” to the page. In this case, if the page can be scrolled by dragging that object. It
can be enabled by the lv_page_glue_obj(child, true).
Focus object
Manual navigation
You can move the scrollable object manually using lv_page_scroll_hor(page, dist) and
lv_page_scroll_ver(page, dist)
Edge flash
A circle-like effect can be shown if the list reached the most top/bottom/left/right position.
lv_page_set_edge_flash(list, en) enables this feature.
Scroll propagation
If the list is created on an other scrollable element (like an other page) and the Page can’t be scrolled further
the scrolling can be propagated to the parent to continue the scrolling on the parent. It can be enabled with
lv_page_set_scroll_propagation(list, true)
All the object created on the page can be clean with lv_page_clean(page). Note that
lv_obj_clean(page) doesn’t work here because it would delete the scrollable object too.
Scrollable API
5.24.5 Events
5.24.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_PAGE
void lv_ex_page_1(void)
{
/*Create a page*/
lv_obj_t * page = lv_page_create(lv_scr_act(), NULL);
(continues on next page)
#endif
MicroPython
No examples yet.
5.24.7 API
Typedefs
Enums
enum [anonymous]
Scrollbar modes: shows when should the scrollbars be visible
Values:
enumerator LV_SCROLLBAR_MODE_OFF = 0x0
Never show scroll bars
enumerator LV_SCROLLBAR_MODE_ON = 0x1
Always show scroll bars
Functions
Parameters
• page: pointer to a page object
• hot: horizontal fit policy from lv_fit_t
• ver: vertical fit policy from lv_fit_t
void lv_page_set_scrollable_fit(lv_obj_t *page, lv_fit_t fit)
Set the fit policy in all 4 direction at once. It tell how to change the page size automatically.
Parameters
• page: pointer to a button object
• fit: fit policy from lv_fit_t
void lv_page_set_scrl_width(lv_obj_t *page, lv_coord_t w)
Set width of the scrollable part of a page
Parameters
• page: pointer to a page object
• w: the new width of the scrollable (it ha no effect is horizontal fit is enabled)
void lv_page_set_scrl_height(lv_obj_t *page, lv_coord_t h)
Set height of the scrollable part of a page
Parameters
• page: pointer to a page object
• h: the new height of the scrollable (it ha no effect is vertical fit is enabled)
void lv_page_set_scrl_layout(lv_obj_t *page, lv_layout_t layout)
Set the layout of the scrollable part of the page
Parameters
• page: pointer to a page object
• layout: a layout from ’lv_cont_layout_t’
lv_scrollbar_mode_t lv_page_get_scrollbar_mode(const lv_obj_t *page)
Set the scroll bar mode on a page
Return the mode from ’lv_page_sb.mode_t’ enum
Parameters
• page: pointer to a page object
bool lv_page_get_scroll_propagation(lv_obj_t *page)
Get the scroll propagation property
Return true or false
Parameters
• page: pointer to a Page
bool lv_page_get_edge_flash(lv_obj_t *page)
Get the edge flash effect property.
Parameters
• page: pointer to a Page return true or false
Public Members
lv_cont_ext_t bg
lv_obj_t *scrl
lv_style_list_t style
lv_area_t hor_area
lv_area_t ver_area
uint8_t hor_draw
uint8_t ver_draw
lv_scrollbar_mode_t mode
struct lv_page_ext_t::[anonymous] scrlbar
lv_anim_value_t state
uint8_t enabled
uint8_t top_ip
uint8_t bottom_ip
uint8_t right_ip
uint8_t left_ip
5.25.1 Overview
Roller allows you to simply select one option from more with scrolling.
The Roller’s main part is called LV_ROLLER_PART_BG. It’s a rectangle and uses all the typical background
properties. The style of the Roller’s label is inherited from the text style properties of the background. To
adjust the space between the options use the text_line_space style property. The padding style properties
set the space on the sides.
The selected option in the middle can be referenced with LV_ROLLER_PART_SELECTED virtual part. Be-
sides the typical background properties it uses the text properties to change the appearance of the text in
the selected area.
5.25.3 Usage
Set options
The options are passed to the Roller as a string with lv_roller_set_options(roller, options,
LV_ROLLER_MODE_NORMAL/INFINITE). The options should be separated by \n. For example: "First\
nSecond\nThird".
LV_ROLLER_MODE_INIFINITE make the roller circular.
You can select an option manually with lv_roller_set_selected(roller, id, LV_ANIM_ON/
OFF), where id is the index of an option.
The get the currently selected option use lv_roller_get_selected(roller) it will return the index
of the selected option.
lv_roller_get_selected_str(roller, buf, buf_size) copy the name of the selected option to
buf.
Visible rows
Animation time
When the Roller is scrolled and doesn’t stop exactly on an option it will scroll to the nearest valid option au-
tomatically. The time of this scroll animation can be changed by lv_roller_set_anim_time(roller,
anim_time). Zero animation time means no animation.
5.25.4 Events
Besides, the Generic events the following Special events are sent by the Drop down lists:
• LV_EVENT_VALUE_CHANGED sent when a new option is selected
Learn more about Events.
5.25.5 Keys
5.25.6 Example
Simple Roller
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_ROLLER
void lv_ex_roller_1(void)
{
lv_obj_t *roller1 = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller1,
"January\n"
"February\n"
"March\n"
"April\n"
"May\n"
"June\n"
"July\n"
"August\n"
"September\n"
"October\n"
"November\n"
"December",
LV_ROLLER_MODE_INIFINITE);
(continues on next page)
lv_roller_set_visible_row_count(roller1, 4);
lv_obj_align(roller1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(roller1, event_handler);
}
#endif
MicroPython
No examples yet.
5.25.7 API
Typedefs
Enums
enum [anonymous]
Roller mode.
Values:
enumerator LV_ROLLER_MODE_NORMAL
Normal mode (roller ends at the end of the options).
enumerator LV_ROLLER_MODE_INIFINITE
Infinite mode (roller can be scrolled forever).
enum [anonymous]
Values:
enumerator LV_ROLLER_PART_BG = LV_PAGE_PART_BG
enumerator LV_ROLLER_PART_SELECTED = _LV_PAGE_PART_VIRTUAL_LAST
enumerator _LV_ROLLER_PART_VIRTUAL_LAST
Functions
Public Members
lv_page_ext_t page
lv_style_list_t style_sel
uint16_t option_cnt
uint16_t sel_opt_id
uint16_t sel_opt_id_ori
lv_roller_mode_t mode
uint8_t auto_fit
5.26.1 Overview
The Slider object looks like a Bar supplemented with a knob. The knob can be dragged to set a value. The
Slider also can be vertical or horizontal.
The Slider’s main part is called LV_SLIDER_PART_BG and it uses the typical background style properties.
LV_SLIDER_PART_INDIC is a virtual part which also uses all the typical background properties. By
default, the indicator maximal size is the same as the background’s size but setting positive padding values
in LV_SLIDER_PART_BG will make the indicator smaller. (negative values will make it larger) If the value
style property is used on the indicator the alignment will be calculated based on the current size of the
indicator. For example a center aligned value is always shown in the middle of the indicator regardless it’s
current size.
LV_SLIDER_PART_KNOB is a virtual part using all the typical background properties to describe the knob(s).
Similarly to the indicator the value text is also aligned to the current position and size of the knob. By
default the knob is square (with a radius) with side length equal to the smaller side of the slider. The knob
can be made larger with the padding values. Padding values can be asymmetric too.
5.26.3 Usage
Besides the normal type the Slider can be configured in two additional types:
• LV_SLIDER_TYPE_NORMAL normal type
• LV_SLIDER_TYPE_SYMMETRICAL draw the indicator symmetrical to zero (drawn from zero, left to
right)
• LV_SLIDER_TYPE_RANGE allow the use of an additional knob for the left (start) value. (Can be used
with lv_slider_set/get_left_value())
The type can be changed with lv_slider_set_type(slider, LV_SLIDER_TYPE_...)
Knob-only mode
Normally, the slider can be adjusted either by dragging the knob, or clicking on the slider bar. In the latter
case the knob moves to the point clicked and slider value changes accordingly. In some cases it is desirable
to set the slider to react on dragging the knob only.
This feature is enabled by calling lv_obj_set_adv_hittest(slider, true);.
5.26.4 Events
Besides the Generic events the following Special events are sent by the Slider:
• LV_EVENT_VALUE_CHANGED Sent while the slider is being dragged or changed with
keys. The event is sent continuously while the slider is dragged and only when it is released. Use
lv_slider_is_dragged to decide whether is slider is being dragged or just released.
5.26.5 Keys
5.26.6 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_SLIDER
void lv_ex_slider_1(void)
{
/*Create a slider*/
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(slider, event_handler);
}
#endif
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_SLIDER
void lv_ex_slider_2(void)
{
/* Create a slider in the center of the display */
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
lv_obj_set_width(slider, LV_DPI * 2);
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(slider, slider_event_cb);
lv_slider_set_range(slider, 0, 100);
#endif
MicroPython
No examples yet.
5.26.7 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_SLIDER_TYPE_NORMAL
enumerator LV_SLIDER_TYPE_SYMMETRICAL
enumerator LV_SLIDER_TYPE_RANGE
enum [anonymous]
Built-in styles of slider
Values:
enumerator LV_SLIDER_PART_BG
enumerator LV_SLIDER_PART_INDIC
Slider background style.
enumerator LV_SLIDER_PART_KNOB
Slider indicator (filled area) style.
Functions
Public Members
lv_bar_ext_t bar
lv_style_list_t style_knob
lv_area_t left_knob_area
lv_area_t right_knob_area
int16_t *value_to_set
uint8_t dragging
5.27.1 Overview
The Spinbox contains a number as text which can be increased or decreased by Keys or API functions.
Under the hood the Spinbox is a modified Text area.
The Spinbox’s main part is called LV_SPINBOX_PART_BG which is a rectangle-like background using all
the typical background style properties. It also describes the style of the label with its text style properties.
LV_SPINBOX_PART_CURSOR is a virtual part describing the cursor. Read the Text area documentation for
a detailed description.
Set format
5.27.3 Events
Besides the Generic events the following Special events are sent by the Drop down lists:
• LV_EVENT_VALUE_CHANGED sent when the value has changed. (the value is set as event
data as int32_t)
• LV_EVENT_INSERT sent by the ancestor Text area but shouldn’t be used.
Learn more about Events.
5.27.4 Keys
5.27.5 Example
Simple Spinbox
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_SPINBOX
void lv_ex_spinbox_1(void)
{
spinbox = lv_spinbox_create(lv_scr_act(), NULL);
lv_spinbox_set_range(spinbox, -1000, 90000);
lv_spinbox_set_digit_format(spinbox, 5, 2);
lv_spinbox_step_prev(spinbox);
lv_obj_set_width(spinbox, 100);
lv_obj_align(spinbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_coord_t h = lv_obj_get_height(spinbox);
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_size(btn, h, h);
lv_obj_align(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
lv_theme_apply(btn, LV_THEME_SPINBOX_BTN);
lv_obj_set_style_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_
,→SYMBOL_PLUS);
lv_obj_set_event_cb(btn, lv_spinbox_increment_event_cb);
#endif
MicroPython
No examples yet.
5.27.6 API
Typedefs
Enums
enum [anonymous]
Values:
enumerator LV_SPINBOX_PART_BG = LV_TEXTAREA_PART_BG
enumerator LV_SPINBOX_PART_CURSOR = LV_TEXTAREA_PART_CURSOR
enumerator _LV_SPINBOX_PART_VIRTUAL_LAST = _LV_TEXTAREA_PART_VIRTUAL_LAST
enumerator _LV_SPINBOX_PART_REAL_LAST = _LV_TEXTAREA_PART_REAL_LAST
Functions
• digit_count: number of digit excluding the decimal separator and the sign
• separator_position: number of digit before the decimal point. If 0, decimal point is not
shown
void lv_spinbox_set_step(lv_obj_t *spinbox, uint32_t step)
Set spinbox step
Parameters
• spinbox: pointer to spinbox
• step: steps on increment/decrement
void lv_spinbox_set_range(lv_obj_t *spinbox, int32_t range_min, int32_t range_max)
Set spinbox value range
Parameters
• spinbox: pointer to spinbox
• range_min: maximum value, inclusive
• range_max: minimum value, inclusive
void lv_spinbox_set_padding_left(lv_obj_t *spinbox, uint8_t padding)
Set spinbox left padding in digits count (added between sign and first digit)
Parameters
• spinbox: pointer to spinbox
• cb: Callback function called on value change event
bool lv_spinbox_get_rollover(lv_obj_t *spinbox)
Get spinbox rollover function status
Parameters
• spinbox: pointer to spinbox
int32_t lv_spinbox_get_value(lv_obj_t *spinbox)
Get the spinbox numeral value (user has to convert to float according to its digit format)
Return value integer value of the spinbox
Parameters
• spinbox: pointer to spinbox
void lv_spinbox_step_next(lv_obj_t *spinbox)
Select next lower digit for edition by dividing the step by 10
Parameters
• spinbox: pointer to spinbox
void lv_spinbox_step_prev(lv_obj_t *spinbox)
Select next higher digit for edition by multiplying the step by 10
Parameters
• spinbox: pointer to spinbox
void lv_spinbox_increment(lv_obj_t *spinbox)
Increment spinbox value by one step
Parameters
Public Members
lv_textarea_ext_t ta
int32_t value
int32_t range_max
int32_t range_min
int32_t step
uint8_t rollover
uint16_t digit_count
uint16_t dec_point_pos
uint16_t digit_padding_left
5.27.7 Example
5.28.1 Overview
5.28.3 Usage
Arc length
Spinning speed
Spin types
Spin direction
5.28.4 Events
5.28.5 Keys
5.28.6 Example
Simple spinner
code
#include "../../../lv_examples.h"
#if LV_USE_SPINNER
void lv_ex_spinner_1(void)
{
/*Create a Preloader object*/
lv_obj_t * preload = lv_spinner_create(lv_scr_act(), NULL);
lv_obj_set_size(preload, 100, 100);
lv_obj_align(preload, NULL, LV_ALIGN_CENTER, 0, 0);
}
#endif
MicroPython
MicroPython
No examples yet.
5.28.7 API
Typedefs
Enums
enum [anonymous]
Type of spinner.
Values:
enumerator LV_SPINNER_TYPE_SPINNING_ARC
enumerator LV_SPINNER_TYPE_FILLSPIN_ARC
enumerator LV_SPINNER_TYPE_CONSTANT_ARC
enum [anonymous]
Direction the spinner should spin.
Values:
enumerator LV_SPINNER_DIR_FORWARD
enumerator LV_SPINNER_DIR_BACKWARD
enum [anonymous]
Values:
enumerator LV_SPINNER_PART_BG = LV_ARC_PART_BG
enumerator LV_SPINNER_PART_INDIC = LV_ARC_PART_INDIC
enumerator _LV_SPINNER_PART_VIRTUAL_LAST
enumerator _LV_SPINNER_PART_REAL_LAST = _LV_ARC_PART_REAL_LAST
Functions
Public Members
lv_arc_ext_t arc
lv_anim_value_t arc_length
uint16_t time
lv_spinner_type_t anim_type
lv_spinner_dir_t anim_dir
5.29.1 Overview
The Switch can be used to turn on/off something. It looks like a little slider.
Change state
Animation time
The time of animations, when the switch changes state, can be adjusted with
lv_switch_set_anim_time(switch, anim_time).
5.29.3 Events
Besides the Generic events the following Special events are sent by the Switch:
• LV_EVENT_VALUE_CHANGED Sent when the switch changes state.
5.29.4 Keys
5.29.5 Example
Simple Switch
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_SWITCH
void lv_ex_switch_1(void)
{
/*Create a switch and apply the styles*/
lv_obj_t *sw1 = lv_switch_create(lv_scr_act(), NULL);
lv_obj_align(sw1, NULL, LV_ALIGN_CENTER, 0, -50);
lv_obj_set_event_cb(sw1, event_handler);
(continues on next page)
#endif
MicroPython
No examples yet.
5.29.6 API
Typedefs
Enums
enum [anonymous]
Switch parts.
Values:
enumerator LV_SWITCH_PART_BG = LV_BAR_PART_BG
Switch background.
enumerator LV_SWITCH_PART_INDIC = LV_BAR_PART_INDIC
Switch fill area.
enumerator LV_SWITCH_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST
Switch knob.
enumerator _LV_SWITCH_PART_VIRTUAL_LAST
Functions
• anim: LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value
immediately
void lv_switch_off(lv_obj_t *sw, lv_anim_enable_t anim)
Turn OFF the switch
Parameters
• sw: pointer to a switch object
• anim: LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value
immediately
bool lv_switch_toggle(lv_obj_t *sw, lv_anim_enable_t anim)
Toggle the position of the switch
Return resulting state of the switch.
Parameters
• sw: pointer to a switch object
• anim: LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value
immediately
void lv_switch_set_anim_time(lv_obj_t *sw, uint16_t anim_time)
Set the animation time of the switch
Return style pointer to a style
Parameters
• sw: pointer to a switch object
• anim_time: animation time
bool lv_switch_get_state(const lv_obj_t *sw)
Get the state of a switch
Return false: OFF; true: ON
Parameters
• sw: pointer to a switch object
uint16_t lv_switch_get_anim_time(const lv_obj_t *sw)
Get the animation time of the switch
Return style pointer to a style
Parameters
• sw: pointer to a switch object
struct lv_switch_ext_t
Public Members
lv_bar_ext_t bar
lv_style_list_t style_knob
uint8_t state
5.30.1 Overview
Tables, as usual, are built from rows, columns, and cells containing texts.
The Table object is very light weighted because only the texts are stored. No real objects are created for
cells but they are just drawn on the fly.
The main part of the Table is called LV_TABLE_PART_BG. It’s a rectangle like background and uses all the
typical background style properties.
For the cells there are 4 virtual parts. Every cell has type (1, 2, ... 16) which tells which part’s styles to apply
on them. The cell parts can be referenced by LV_TABLE_PART_CELL1 + x where x is between 0..15.
The number of cell types can be adjusted in lv_conf.h by LV_TABLE_CELL_STYLE_CNT. By default it’s
4. The default 4 cell types’ part be referenced with dedicated names too:
• LV_TABLE_PART_CELL1
• LV_TABLE_PART_CELL2
• LV_TABLE_PART_CELL3
• LV_TABLE_PART_CELL4
The cells also use all the typical background style properties. If there is a line break (\n) in a cell’s content
then a horizontal division line will drawn after the line break using the line style properties.
The style of texts in the cells are inherited from the cell parts or the background part.
5.30.3 Usage
The width of the columns can be set with lv_table_set_col_width(table, col_id, width). The
overall width of the Table object will be set to the sum of columns widths.
The height is calculated automatically from the cell styles (font, padding etc) and the number of rows.
The cells can store only texts so numbers needs to be converted to text before displaying them in a table.
lv_table_set_cell_value(table, row, col, "Content"). The text is saved by the table so it
can be even a local variable.
Line break can be used in the text like "Value\n60.3".
Align
Cell type
You can use 4 different cell types. Each has its own style.
Cell types can be used to add different style for example to:
• table header
• first column
• highlight a cell
• etc
The type can be selected with lv_table_set_cell_type(table, row, col, type) type can be
1, 2, 3 or 4.
Merge cells
Crop text
By default, the texts are word-wrapped to fit into the width of the cell and the height of the cell is set
automatically. To disable this and keep the text as it is enable lv_table_set_cell_crop(table,
row, col, true).
Scroll
5.30.4 Events
5.30.5 Keys
5.30.6 Example
Simple table
code
#include "../../../lv_examples.h"
#if LV_USE_TABLE
void lv_ex_table_1(void)
{
lv_obj_t * table = lv_table_create(lv_scr_act(), NULL);
lv_table_set_col_cnt(table, 2);
(continues on next page)
lv_table_set_cell_type(table, 0, 0, 2);
lv_table_set_cell_type(table, 0, 1, 2);
#endif
MicroPython
No examples yet.
MicroPython
No examples yet.
5.30.7 API
Enums
enum [anonymous]
Values:
enumerator LV_TABLE_PART_BG
enumerator LV_TABLE_PART_CELL1
enumerator LV_TABLE_PART_CELL2
enumerator LV_TABLE_PART_CELL3
enumerator LV_TABLE_PART_CELL4
Functions
Parameters
• table: table pointer to a Table object
lv_coord_t lv_table_get_col_width(lv_obj_t *table, uint16_t col_id)
Get the width of a column
Return width of the column
Parameters
• table: table pointer to a Table object
• col_id: id of the column [0 .. LV_TABLE_COL_MAX -1]
lv_label_align_t lv_table_get_cell_align(lv_obj_t *table, uint16_t row, uint16_t col)
Get the text align of a cell
Return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER
or LV_LABEL_ALIGN_RIGHT
Parameters
• table: pointer to a Table object
• row: id of the row [0 .. row_cnt -1]
• col: id of the column [0 .. col_cnt -1]
lv_label_align_t lv_table_get_cell_type(lv_obj_t *table, uint16_t row, uint16_t col)
Get the type of a cell
Return 1,2,3 or 4
Parameters
• table: pointer to a Table object
• row: id of the row [0 .. row_cnt -1]
• col: id of the column [0 .. col_cnt -1]
lv_label_align_t lv_table_get_cell_crop(lv_obj_t *table, uint16_t row, uint16_t col)
Get the crop property of a cell
Return true: text crop enabled; false: disabled
Parameters
• table: pointer to a Table object
• row: id of the row [0 .. row_cnt -1]
• col: id of the column [0 .. col_cnt -1]
bool lv_table_get_cell_merge_right(lv_obj_t *table, uint16_t row, uint16_t col)
Get the cell merge attribute.
Return true: merge right; false: don’t merge right
Parameters
• table: table pointer to a Table object
• row: id of the row [0 .. row_cnt -1]
• col: id of the column [0 .. col_cnt -1]
Public Members
uint8_t align
uint8_t right_merge
uint8_t type
uint8_t crop
struct lv_table_cell_format_t::[anonymous] s
uint8_t format_byte
struct lv_table_ext_t
Public Members
uint16_t col_cnt
uint16_t row_cnt
char **cell_data
lv_coord_t *row_h
lv_style_list_t cell_style[LV_TABLE_CELL_STYLE_CNT]
lv_coord_t col_w[LV_TABLE_COL_MAX]
uint8_t cell_types
5.31.1 Overview
The Tab view object has several parts. The main is LV_TABVIEW_PART_BG. It a rectangle-like container
which holds the other parts of the Tab view.
On the background 2 important real parts are created:
• LV_TABVIEW_PART_BG_SCRL: it’s the scrollable part of Page. It holds the content of the tabs next
to each other. The background of the Page is always transparent and can’t be accessed externally.
• LV_TABVIEW_PART_TAB_BG: The tab buttons which is a Button matrix. Clicking on a button will
scroll LV_TABVIEW_PART_BG_SCRL to the related tab’s content. The tab buttons can be accessed
via LV_TABVIEW_PART_TAB_BTN. When tabs are selected, the buttons are in the checked state, and
can be styled using LV_STATE_CHECKED. The height of the tab’s button matrix is calculated from
the font height plus padding of the background’s and the button’s style.
All the listed parts supports the typical background style properties and padding.
LV_TABVIEW_PART_TAB_BG has an additional real part, an indicator, called LV_TABVIEW_PART_INDIC.
It’s a thin rectangle-like object under the currently selected tab. When the tab view is animated to an other
tab the indicator will be animated too. It can be styles using the typical background style properties. The
size style property will set the its thickness.
When a new tab is added a Page is create for them on LV_TABVIEW_PART_BG_SCRL and a new button
is added to LV_TABVIEW_PART_TAB_BG Button matrix. The created Pages can be used as normal Pages
and they have the usual Page parts.
5.31.3 Usage
Adding tab
New tabs can be added with lv_tabview_add_tab(tabview, "Tab name"). It will return with a
pointer to a Page object where the tab’s content can be created.
Change tab
To change the name (shown text of the underlying button matrix) of tab id during runtime the function
lv_tabview_set_tab_name(tabview, id, name) can be used.
By default, the tab selector buttons are placed on the top of the Tab view. It can be changed
with lv_tabview_set_btns_pos(tabview, LV_TABVIEW_TAB_POS_TOP/BOTTOM/LEFT/RIGHT/
NONE)
LV_TABVIEW_TAB_POS_NONE will hide the tabs.
Note that, you can’t change the tab position from top or bottom to left or right when tabs are already added.
Animation time
Scroll propagation
As the tabs’ content object is a Page it can receive scroll propagation from an other Page-like ob-
ject. For example, if a text area is created on the tab’s content and that Text area is scrolled but it
reached the end the scroll can be propagated to the content Page. It can be enabled with lv_page/
textarea_set_scroll_propagation(obj, true).
By default the tab’s content Pages have enabled scroll propagation, therefore when they are scrolled hori-
zontally the scroll is propagated to LV_TABVIEW_PART_BG_SCRL and this way the Pages will be scrolled.
The manual sliding can be disabled with lv_page_set_scroll_propagation(tab_page, false).
5.31.4 Events
Besides the Generic events the following Special events are sent by the Slider:
• LV_EVENT_VALUE_CHANGED Sent when a new tab is selected by sliding or clicking the
tab button
Learn more about Events.
5.31.5 Keys
5.31.6 Example
Simple Tabview
code
#include "../../../lv_examples.h"
#if LV_USE_TABVIEW
void lv_ex_tabview_1(void)
{
/*Create a Tab view object*/
lv_obj_t *tabview;
tabview = lv_tabview_create(lv_scr_act(), NULL);
/*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1");
lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2");
lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3");
MicroPython
No examples yet.
5.31.7 API
Typedefs
Enums
enum [anonymous]
Position of tabview buttons.
Values:
enumerator LV_TABVIEW_TAB_POS_NONE
enumerator LV_TABVIEW_TAB_POS_TOP
enumerator LV_TABVIEW_TAB_POS_BOTTOM
enumerator LV_TABVIEW_TAB_POS_LEFT
enumerator LV_TABVIEW_TAB_POS_RIGHT
enum [anonymous]
Values:
enumerator LV_TABVIEW_PART_BG = LV_OBJ_PART_MAIN
enumerator _LV_TABVIEW_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_LAST
enumerator LV_TABVIEW_PART_BG_SCRLLABLE = _LV_OBJ_PART_REAL_LAST
enumerator LV_TABVIEW_PART_TAB_BG
enumerator LV_TABVIEW_PART_TAB_BTN
enumerator LV_TABVIEW_PART_INDIC
enumerator _LV_TABVIEW_PART_REAL_LAST
Functions
Public Members
lv_obj_t *btns
lv_obj_t *indic
lv_obj_t *content
const char **tab_name_ptr
lv_point_t point_last
uint16_t tab_cur
uint16_t tab_cnt
uint16_t anim_time
lv_tabview_btns_pos_t btns_pos
5.32.1 Overview
The Text Area is a Page with a Label and a cursor on it. Texts or characters can be added to it. Long lines
are wrapped and when the text becomes long enough the Text area can be scrolled.
The Text area has the same parts as Page. Expect LV_PAGE_PART_SCRL because it can’t be referenced
and it’s always transparent. Refer the Page’s documentation of details.
Besides the Page parts the virtual LV_TEXTAREA_PART_CURSOR part exists to draw the cursor. The
cursor’s area is always the bounding box of the current character. A block cursor can be created by adding
a background color and background opa to LV_TEXTAREA_PART_CURSOR’s style. The create line cursor
let the cursor transparent and set the border_side property.
5.32.3 Usage
Add text
You can insert text or characters to the current cursor’s position with:
• lv_textarea_add_char(textarea, 'c')
• lv_textarea_add_text(textarea, "insert this text")
To add wide characters like 'á', 'ß' or CJK characters use lv_textarea_add_text(ta, "á").
lv_textarea_set_text(ta, "New text") changes the whole text.
Placeholder
A placeholder text can be specified - which is displayed when the Text area is empty - with
lv_textarea_set_placeholder_text(ta, "Placeholder text")
Delete character
To delete a character from the left of the current cursor position use
lv_textarea_del_char(textarea). To delete from the right use
lv_textarea_del_char_forward(textarea)
The Text area can be configures to be one lined with lv_ta_set_one_line(ta, true). In this mode
the height is set automatically to show only one line, line break character are ignored, and word wrap is
disabled.
Password mode
The text area supports password mode which can be enabled with
lv_textarea_set_pwd_mode(textarea, true).
If the • (Bullet, U+2022) character exists in the font, the entered characters are converted to it after some
time or when a new character is entered. If • not exists, * will be used.
In password mode lv_textarea_get_text(textarea) gives the real text, not the bullet characters.
The visibility time can be adjusted with lv_textarea_set_pwd_show_time(textarea, time_ms).
Text align
The text can be aligned to the left, center or right with lv_textarea_set_text_align(textarea,
LV_LABEL_ALIGN_LET/CENTER/RIGHT).
In one line mode, the text can be scrolled horizontally only if the text is left aligned.
Accepted characters
If there is a very long text in the Text area (e. g. > 20k characters) its scrolling and drawing might be slow.
However, by enabling LV_LABEL_LONG_TXT_HINT 1 in lv_conf.h it can be hugely improved. It will save
some info about the label to speed up its drawing. Using LV_LABEL_LONG_TXT_HINT the scrolling and
drawing will as fast as with ”normal” short texts.
Select text
Scrollbars
Scroll propagation
When the Text area is scrolled on an other scrollable object (like a Page) and the scrolling has reached the
edge of the Text area, the scrolling can be propagated to the parent. In other words, when the Text area
can be scrolled further, the parent will be scrolled instead.
It can be enabled with lv_ta_set_scroll_propagation(ta, true).
Learn more at the Page object.
Edge flash
When the Text area is scrolled to edge a circle like flash animation can be shown if it is enabled with
lv_ta_set_edge_flash(ta, true)
5.32.4 Events
Besides the Generic events the following Special events are sent by the Slider:
• LV_EVENT_INSERT Sent when before a character or text is inserted. The event data is the text
planned to insert. lv_ta_set_insert_replace(ta, "New text") replaces the text to insert.
The new text can’t be in a local variable which is destroyed when the event callback exists. "" means
do not insert anything.
• LV_EVENT_VALUE_CHANGED When the content of the text area has been changed.
• LV_EVENT_APPLY When LV_KEY_ENTER is sent to a text area which is in one line mode.
5.32.5 Keys
5.32.6 Example
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_TEXTAREA
void lv_ex_textarea_1(void)
{
ta1 = lv_textarea_create(lv_scr_act(), NULL);
lv_obj_set_size(ta1, 200, 100);
lv_obj_align(ta1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_textarea_set_text(ta1, "A text in a Text Area"); /*Set an initial text*/
lv_obj_set_event_cb(ta1, event_handler);
}
#endif
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_TEXTAREA && LV_USE_KEYBOARD
void lv_ex_textarea_2(void)
{
/* Create the password box */
lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act(), NULL);
lv_textarea_set_text(pwd_ta, "");
lv_textarea_set_pwd_mode(pwd_ta, true);
lv_textarea_set_one_line(pwd_ta, true);
lv_textarea_set_cursor_hidden(pwd_ta, true);
lv_obj_set_width(pwd_ta, LV_HOR_RES / 2 - 20);
lv_obj_set_pos(pwd_ta, 5, 20);
lv_obj_set_event_cb(pwd_ta, ta_event_cb);
/* Create a keyboard */
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
#endif
Text auto-formatting
code
#include "../../../lv_examples.h"
#include <stdio.h>
#if LV_USE_TEXTAREA && LV_USE_KEYBOARD
/**
* Automatically format text like a clock. E.g. "12:34"
* Add the ':' automatically.
*/
void lv_ex_textarea_3(void)
{
/* Create the text area */
lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(ta, ta_event_cb);
lv_textarea_set_accepted_chars(ta, "0123456789:");
lv_textarea_set_max_length(ta, 5);
lv_textarea_set_one_line(ta, true);
(continues on next page)
/* Create a keyboard*/
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUM);
lv_keyboard_set_textarea(kb, ta);
}
#endif
MicroPython
No examples yet.
5.32.7 API
Typedefs
Enums
enum [anonymous]
Possible text areas styles.
Values:
enumerator LV_TEXTAREA_PART_BG = LV_PAGE_PART_BG
Text area background style
enumerator LV_TEXTAREA_PART_SCROLLBAR = LV_PAGE_PART_SCROLLBAR
Scrollbar style
enumerator LV_TEXTAREA_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH
Edge flash style
enumerator LV_TEXTAREA_PART_CURSOR = _LV_PAGE_PART_VIRTUAL_LAST
Cursor style
enumerator LV_TEXTAREA_PART_PLACEHOLDER
Placeholder style
enumerator _LV_TEXTAREA_PART_VIRTUAL_LAST
enumerator _LV_TEXTAREA_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST
Functions
LV_EXPORT_CONST_INT(LV_TEXTAREA_CURSOR_LAST)
lv_obj_t *lv_textarea_create(lv_obj_t *par, const lv_obj_t *copy)
Create a text area objects
Return pointer to the created text area
Parameters
• par: pointer to an object, it will be the parent of the new text area
• copy: pointer to a text area object, if not NULL then the new object will be copied from it
void lv_textarea_add_char(lv_obj_t *ta, uint32_t c)
Insert a character to the current cursor position. To add a wide char, e.g. ’Á’ use
‘_lv_txt_encoded_conv_wc(’Á’)‘
Parameters
• ta: pointer to a text area object
• c: a character (e.g. ’a’)
void lv_textarea_add_text(lv_obj_t *ta, const char *txt)
Insert a text to the current cursor position
Parameters
• ta: pointer to a text area object
• txt: a ’\0’ terminated string to insert
void lv_textarea_del_char(lv_obj_t *ta)
Delete a the left character from the current cursor position
Parameters
• ta: pointer to a text area object
void lv_textarea_del_char_forward(lv_obj_t *ta)
Delete the right character from the current cursor position
Parameters
• ta: pointer to a text area object
void lv_textarea_set_text(lv_obj_t *ta, const char *txt)
Set the text of a text area
Parameters
• ta: pointer to a text area
• txt: pointer to the text
void lv_textarea_set_placeholder_text(lv_obj_t *ta, const char *txt)
Set the placeholder text of a text area
Parameters
• ta: pointer to a text area
• txt: pointer to the text
void lv_textarea_set_cursor_pos(lv_obj_t *ta, int32_t pos)
Set the cursor position
Parameters
• obj: pointer to a text area object
• pos: the new cursor position in character index < 0 : index from the end of the text
LV_TEXTAREA_CURSOR_LAST: go after the last character
void lv_textarea_set_cursor_hidden(lv_obj_t *ta, bool hide)
Hide/Unhide the cursor.
Parameters
• ta: pointer to a text area object
• hide: true: hide the cursor
void lv_textarea_set_cursor_click_pos(lv_obj_t *ta, bool en)
Enable/Disable the positioning of the the cursor by clicking the text on the text area.
Parameters
• ta: pointer to a text area object
• en: true: enable click positions; false: disable
void lv_textarea_set_pwd_mode(lv_obj_t *ta, bool en)
Enable/Disable password mode
Parameters
• ta: pointer to a text area object
• en: true: enable, false: disable
void lv_textarea_set_one_line(lv_obj_t *ta, bool en)
Configure the text area to one line or back to normal
Parameters
• ta: pointer to a Text area object
• en: true: one line, false: normal
void lv_textarea_set_text_align(lv_obj_t *ta, lv_label_align_t align)
Set the alignment of the text area. In one line mode the text can be scrolled only with
LV_LABEL_ALIGN_LEFT. This function should be called if the size of text area changes.
Parameters
• ta: pointer to a text are object
• align: the desired alignment from lv_label_align_t.
(LV_LABEL_ALIGN_LEFT/CENTER/RIGHT)
void lv_textarea_set_accepted_chars(lv_obj_t *ta, const char *list)
Set a list of characters. Only these characters will be accepted by the text area
Parameters
Parameters
• ta: pointer to a text area object
bool lv_textarea_get_one_line(const lv_obj_t *ta)
Get the one line configuration attribute
Return true: one line configuration is enabled, false: disabled
Parameters
• ta: pointer to a text area object
const char *lv_textarea_get_accepted_chars(lv_obj_t *ta)
Get a list of accepted characters.
Return list of accented characters.
Parameters
• ta: pointer to Text Area
uint32_t lv_textarea_get_max_length(lv_obj_t *ta)
Get max length of a Text Area.
Return the maximal number of characters to be add
Parameters
• ta: pointer to Text Area
lv_scrollbar_mode_t lv_textarea_get_scrollbar_mode(const lv_obj_t *ta)
Get the scroll bar mode of a text area
Return scrollbar mode from ’lv_scrollbar_mode_t’ enum
Parameters
• ta: pointer to a text area object
bool lv_textarea_get_scroll_propagation(lv_obj_t *ta)
Get the scroll propagation property
Return true or false
Parameters
• ta: pointer to a Text area
bool lv_textarea_get_edge_flash(lv_obj_t *ta)
Get the scroll propagation property
Return true or false
Parameters
• ta: pointer to a Text area
bool lv_textarea_text_is_selected(const lv_obj_t *ta)
Find whether text is selected or not.
Return whether text is selected or not
Parameters
• ta: Text area object
bool lv_textarea_get_text_sel_en(lv_obj_t *ta)
Find whether selection mode is enabled.
Public Members
lv_page_ext_t page
lv_obj_t *label
char *placeholder_txt
lv_style_list_t style_placeholder
char *pwd_tmp
const char *accapted_chars
uint32_t max_length
uint16_t pwd_show_time
lv_style_list_t style
lv_coord_t valid_x
uint32_t pos
uint16_t blink_time
lv_area_t area
uint32_t txt_byte_pos
uint8_t state
uint8_t hidden
uint8_t click_pos
struct lv_textarea_ext_t::[anonymous] cursor
uint32_t sel_start
uint32_t sel_end
uint8_t text_sel_in_prog
uint8_t text_sel_en
uint8_t pwd_mode
uint8_t one_line
5.33.1 Overview
The Tileview is a container object where its elements (called tiles) can be arranged in a grid form. By
swiping the user can navigate between the tiles.
If the Tileview is screen sized it gives a user interface you might have seen on the smartwatches.
The Tileview has the same parts as Page. Expect LV_PAGE_PART_SCRL because it can’t be referenced and
it’s always transparent. Refer the Page’s documentation of details.
5.33.3 Usage
Valid positions
The tiles don’t have to form a full grid where every element exists. There can be holes in the grid but it has
to be continuous, i.e. there can’t be an empty rows or columns.
With lv_tileview_set_valid_positions(tileview, valid_pos_array, array_len) the
valid positions can be set. Scrolling will be possible only to this positions. The 0,0 index means the top
left tile. E.g. lv_point_t valid_pos_array[] = {{0,0}, {0,1}, {1,1}, {{LV_COORD_MIN,
LV_COORD_MIN}} gives a Tile view with ”L” shape. It indicates that there is no tile in {1,1} therefore
the user can’t scroll there.
In other words, the valid_pos_array tells where the tiles are. It can be changed on the fly to disable
some positions on specific tiles. For example, there can be a 2x2 grid where all tiles are added but the first
row (y = 0) as a ”main row” and the second row (y = 1) contains options for the tile above it. Let’s say
horizontal scrolling is possible only in the main row and not possible between the options in the second row.
In this case the valid_pos_array needs to changed when a new main tile is selected:
• for the first main tile: {0,0}, {0,1}, {1,0} to disable the {1,1} option tile
• for the second main tile {0,0}, {1,0}, {1,1} to disable the {0,1} option tile
Set tile
Add element
To add elements just create an object on the Tileview and position it manually to the desired position.
lv_tileview_add_element(tielview, element) should be used to make possible to scroll (drag)
the Tileview by one its element. For example, if there is a button on a tile, the button needs to be explicitly
added to the Tileview to enable the user to scroll the Tileview with the button too.
Scroll propagation
The scroll propagation feature of page-like objects (like List) can be used very well here. For example, there
can be a full-sized List and when it reaches the top or bottom most position the user will scroll the tile view
instead.
Animation time
Edge flash
An ”edge flash” effect can be added when the tile view reached hits an invalid position or the end of tile
view when scrolled.
Use lv_tileview_set_edge_flash(tileview, true) to enable this feature.
5.33.4 Events
Besides the Generic events the following Special events are sent by the Slider:
• LV_EVENT_VALUE_CHANGED Sent when a new tile loaded either with scrolling or
lv_tileview_set_act. The event data is set ti the index of the new tile in valid_pos_array
(It’s type is uint32_t *)
5.33.5 Keys
5.33.6 Example
code
#include "../../../lv_examples.h"
#if LV_USE_TILEVIEW
void lv_ex_tileview_1(void)
{
static lv_point_t valid_pos[] = {{0,0}, {0, 1}, {1,1}};
lv_obj_t *tileview;
tileview = lv_tileview_create(lv_scr_act(), NULL);
lv_tileview_set_valid_positions(tileview, valid_pos, 3);
lv_tileview_set_edge_flash(tileview, true);
/*Tile2: a list*/
lv_obj_t * list = lv_list_create(tileview, NULL);
lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES);
lv_obj_set_pos(list, 0, LV_VER_RES);
lv_list_set_scroll_propagation(list, true);
lv_list_set_scrollbar_mode(list, LV_SCROLLBAR_MODE_OFF);
/*Tile3: a button*/
lv_obj_t * tile3 = lv_obj_create(tileview, tile1);
lv_obj_set_pos(tile3, LV_HOR_RES, LV_VER_RES);
lv_tileview_add_element(tileview, tile3);
#endif
MicroPython
No examples yet.
5.33.7 API
Enums
enum [anonymous]
Values:
enumerator LV_TILEVIEW_PART_BG = LV_PAGE_PART_BG
enumerator LV_TILEVIEW_PART_SCROLLBAR = LV_PAGE_PART_SCROLLBAR
enumerator LV_TILEVIEW_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH
enumerator _LV_TILEVIEW_PART_VIRTUAL_LAST = _LV_PAGE_PART_VIRTUAL_LAST
enumerator _LV_TILEVIEW_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST
Functions
Public Members
lv_page_ext_t page
const lv_point_t *valid_pos
uint16_t valid_pos_cnt
uint16_t anim_time
lv_point_t act_id
uint8_t drag_top_en
uint8_t drag_bottom_en
uint8_t drag_left_en
uint8_t drag_right_en
5.34.1 Overview
The Window is container-like objects built from a header with title and button and a content area.
The main part is LV_WIN_PART_BG which holds the two other real parts:
1. LV_WIN_PART_HEADER: a header Container on the top with a title and control buttons
2. LV_WIN_PART_CONTENT_SCRL the scrollable part of a Page for the content below the header.
Besides these, LV_WIN_PART_CONTENT_SCRL has a scrollbar part called LV_WIN_PART_CONTENT_SCRL.
Read the documentation of Page for more details on the scrollbars.
All parts supports the typical background properties. The title uses the Text properties of the header part.
The height of the control buttons is: header height - header padding_top - header padding_bottom.
Title
On the header, there is a title which can be modified by: lv_win_set_title(win, "New title").
Control buttons
Control buttons can be added to the right of the window header with: lv_win_add_btn_right(win,
LV_SYMBOL_CLOSE), to add a button to the left side of the window header use
lv_win_add_btn_left(win, LV_SYMBOL_CLOSE) instead. The second parameter is an Image
source so it can be a symbol, a pointer to an lv_img_dsc_t variable or a path to file.
The width of the buttons can be set with lv_win_set_btn_width(win, w). If w == 0 the buttons
will be square-shaped.
lv_win_close_event_cb can be used as an event callback to close the Window.
Scrollbars
Layout
To set a layout for the content use lv_win_set_layout(win, LV_LAYOUT_...). See Container for
details.
5.34.3 Events
5.34.4 Keys
5.34.5 Example
Simple window
code
#include "../../../lv_examples.h"
#if LV_USE_WIN
void lv_ex_win_1(void)
{
/*Create a window*/
lv_obj_t * win = lv_win_create(lv_scr_act(), NULL);
lv_win_set_title(win, "Window title"); /*Set the title*/
lv_obj_set_event_cb(close_btn, lv_win_close_event_cb);
lv_win_add_btn(win, LV_SYMBOL_SETTINGS); /*Add a setup button*/
#endif
MicroPython
No examples yet.
5.34.6 API
Enums
enum [anonymous]
Window parts.
Values:
enumerator LV_WIN_PART_BG = LV_OBJ_PART_MAIN
Window object background style.
enumerator _LV_WIN_PART_VIRTUAL_LAST
enumerator LV_WIN_PART_HEADER = _LV_OBJ_PART_REAL_LAST
Window titlebar background style.
enumerator LV_WIN_PART_CONTENT_SCROLLABLE
Window content style.
enumerator LV_WIN_PART_SCROLLBAR
Window scrollbar style.
enumerator _LV_WIN_PART_REAL_LAST
Functions
Parameters
• win: pointer to a window object
• img_src: an image source (’lv_img_t’ variable, path to file or a symbol)
lv_obj_t *lv_win_add_btn_left(lv_obj_t *win, const void *img_src)
Add control button on the left side of the window header
Return pointer to the created button object
Parameters
• win: pointer to a window object
• img_src: an image source (’lv_img_t’ variable, path to file or a symbol)
void lv_win_close_event_cb(lv_obj_t *btn, lv_event_t event)
Can be assigned to a window control button to close the window
Parameters
• btn: pointer to the control button on the widows header
• evet: the event type
void lv_win_set_title(lv_obj_t *win, const char *title)
Set the title of a window
Parameters
• win: pointer to a window object
• title: string of the new title
void lv_win_set_header_height(lv_obj_t *win, lv_coord_t size)
Set the control button size of a window
Return control button size
Parameters
• win: pointer to a window object
void lv_win_set_btn_width(lv_obj_t *win, lv_coord_t width)
Set the width of the control buttons on the header
Parameters
• win: pointer to a window object
• width: width of the control button. 0: to make them square automatically.
void lv_win_set_content_size(lv_obj_t *win, lv_coord_t w, lv_coord_t h)
Set the size of the content area.
Parameters
• win: pointer to a window object
• w: width
• h: height (the window will be higher with the height of the header)
void lv_win_set_layout(lv_obj_t *win, lv_layout_t layout)
Set the layout of the window
Parameters
Public Members
lv_obj_t *page
lv_obj_t *header
char *title_txt
lv_coord_t btn_w
SIX
CONTRIBUTING
6.1 Introduction
429
LVGL Documentation v7.8.0-dev
Merging new code into lvgl, documentation, blog, examples, and other repositories happen via Pull requests
(PR for short). A PR is a notification like ”Hey, I made some updates to your project. Here are the changes,
you can add them if you want.” To do this you need a copy (called fork) of the original project under your
account, make some changes there, and notify the original repository about your updates. You can see how
it looks like on GitHub for lvgl here: https://github.com/lvgl/lvgl/pulls.
To add your changes you can edit files online on GitHub and send a new Pull request from there (recom-
mended for small changes) or add the updates in your favorite editor/IDE and use git to publish the changes
(recommended for more complex updates).
The instructions describe the main lvgl repository but it works the same way for the other repositories.
1. Fork the lvgl repository. To do this click the ”Fork” button in the top right corner. It will
”copy” the lvgl repository to your GitHub account (https://github.com/<YOUR_NAME>?
tab=repositories)
2. Clone your forked repository.
3. Add your changes. You can create a feature branch from master for the updates: git checkout -b
the-new-feature
4. Commit and push you changed to the forked lvgl repository.
5. Create a PR on GitHub from the page of your lvgl repository (https://github.com/
<YOUR_NAME>/lvgl) by clicking the ”New pull request” button. Don’t forget to select the branch
where you added your changes.
6. Set the base branch. It means where you want to merge your update. In the lvgl repo fixes go to
master, new features to dev branch.
7. Describe what is in the update. An example code is welcome if applicable.
8. If you need to make more changes, just update your forked lvgl repo with new commits. They will
automatically appear in the PR.
6.3.1 Overview
To ensure that all licensing criteria is met for all repositories of the LVGL project we apply a process called
DCO (Developer’s Certificate of Origin).
The text of DCO can be read here: https://developercertificate.org/.
By contributing to any repositories of the LVGL project you state that your contribution corresponds with
the DCO.
No further action is required if your contribution fulfills the DCO. If you are not sure about it feel free to
ask us in a comment.
To make the DCO easier to digest, here are some practical guides about specific cases:
The simplest case is when the contribution is solely your own work. In this case you can just send a Pull
Request without worrying about any licensing issues.
If the code you would like to add is based on an article, post or comment on a website (e.g. StackOverflow)
the license and/or rules of that site should be followed.
For example in case of StackOwerflow a notice like this can be used:
As LVGL is also MIT licensed other MIT licensed code can be integrated without issues. The MIT license
requests a copyright notice be added to the derived work. So you need to copy the original work’s license
file or it’s text to the code you want to add.
As GPL license is not compatible with MIT license so LVGL can not accept GPL licensed code.
Even if you’re just getting started with LVGL there are plenty of ways to get your feet wet. Most of these
options don’t even require knowing a single line of code of LVGL.
Have you already started using LVGL in a Simulator, a development board, or your custom hardware? Was
it easy or were there some obstacles? Are you happy with the result?
If so why don’t you tell it to your friends? You can post it on Twitter, Facebook, LinkedIn, or create a
YouTube video.
Any of these helps a lot to spread the word of LVGL and familiarize it with new developers.
Only thing: don’t forget to add a link to https://lvgl.io or https://github.com/lvgl and #lvgl.
Thank you! :)
As you learn LVGL probably you will play with the features of widgets. But why don’t you publish your
experiments?
Every widgets’ documentation contains some examples. For example here are the examples of the Drop-down
list. The examples are directly loaded from the lv_examples repository.
So all you need to do is send a Pull request to the lv_examples repository and follow some conventions:
• Name the examples like lv_ex_<widget_name>_<id>
• Make the example as short and simple as possible
• Add comments to explain what the example does
• Use 320x240 resolution
• Create a screenshot about the example
• Update index.rst in the example’s folder with your new example. See how the other examples are
added.
As you read the documentation you might see some typos or unclear sentences. For typos and straightforward
fixes, you can simply edit the file on GitHub. There is an Edit on Github link on the top right-hand
corner of all pages. Click it to see the file on GitHub, hit the Edit button, and add you fixes as described in
Pull request - From GitHub section.
Note that the documentation is also formatted in Markdown.
If you have more free time you can even translate the documentation. The currently available languages are
shown in the locals folder.
If your chosen language is still not added, please write a comment here.
To add your translations:
• Find the .po in <language_code>/LC_MESSAGES/<section_name>.po. E.g. the widgets trans-
lated to German should be in de/LC_MESSAGES/widgets.po.
• Open a po file and fill the msgstr fields with the translation
• Send a Pull request
To display a translation in the public documentation page at least these sections should be translated:
• Get started: Quick overview
• Overview: Objects, Events, Styles
• Porting: System overview, Set-up a project, Display interface, Input device Interface, Tick interface
• 5 widgets of your choice
The LVGL Blog welcomes posts from anyone. It’s a good place to talk about a project you created with
LVGL, write a tutorial, or share some nice tricks. The latest blog posts are shown on the homepage of LVGL
to make your work more visible.
The blog is hosted on GitHub. If you add a post GitHub automatically turns it into a website. See the
README of the blog repo to see how to add your post.
Let us know what you are working on! You can open a new topic in the My projects category of the Forum.
Showing your project to others is a win-win situation because it increases your and LVGL’s reputation at
the same time.
If you don’t want to speak about it publicly feel free to use Contact form on lvgl.io to private message to us.
As you use LVGL you might find bugs. Before reporting them be sure to check the relevant parts of the
documentation.
If it really seems like a bug feel free to open an issue on GitHub.
When filing the issue be sure to fill the template. It helps a lot to find the root of the problems and helps
to avoid a lot of questions.
The beauty of open-source software is you can easily dig in to it to understand how it works. You can also
fix or adjust it as you wish.
If you found and fixed a bug don’t hesitate to send a Pull request with the fix.
In your Pull request please also add a line to CHANGELOG.md.
It feels great to know you are not alone if something is not working. It’s even better to help others when
they struggle with something.
While you were learning LVGL you might have questions and used the Forum to get answers. As a result,
you probably have more knowledge about how LVGL works.
One of the best ways to give back is to use the Forum and answer the questions of newcomers - like you were
once.
Just read the titles and if you are familiar with the topic don’t hesitate to share your thoughts and suggestions.
Participating in the discussions is one of the best ways to become part of the project and get to know
like-minded people!
We collect the planned features in GitHub issues tracker and mark them with Help wanted label. If you are
interested in any of them feel free to share your opinion and/or participate in the the implementation.
Other features which are (still) not on the road map are listed in the Feature request category of the Forum.
If you have a feature idea for LVGL please use the Forum to share it! Make sure to check that there isn’t
an existing post; if there is, you should comment on it instead to show that there is increased interest in an
existing request.
When adding a new features the followings also needs to be updated:
• Add a line to CHANGELOG.md.
• Update the documentation. See this guide.
• Add an example if applicable. See this guide.
If you want to become part of the core development team, you can become a maintainer of a repository.
By becoming a maintainer:
• you get write access to that repo: - add code directly without sending a pull request - accept
pull requests - close/reopen/edit issues
• your name will be added in the credits section of lvgl.io/about (will be added soon) and lvgl’s
README.
• you can join the Core_contributor group in the Forum and get the LVGL logo on your avatar.
• your word has higher impact when we make decisions
You can become a maintainer by invitation, however the following conditions need to met
1. Have > 50 replies in the Forum. You can look at your stats here
2. Send > 5 non-trivial pull requests to the repo where you would like to be a maintainer
If you are interested, just send a message (e.g. from the Forum) to the current maintainers of the repository.
They will check is the prerequisites are met. Note that meeting the prerequisites is not a guarantee of
acceptance, i.e. if the conditions are met you won’t automatically become a maintainer. It’s up to the
current maintainers to make the decision.
Besides the core lvgl repository there are other repos for ports to development boards, IDEs or other
environment. If you ported LVGL to a new platform we can host it under the LVGL organization among
the other repos.
This way your project will become part of the whole LVGL project and can get more visibility. If you are
interested in this opportunity just open an issue in lvgl repo and tell what you have!
If we agree that your port is useful, we will open a repository for your project where you will have admin
rights.
To make this concept sustainable there a few rules to follow:
• You need to add a README to your repo.
• We expect to maintain the repo to some extent:
– Follow at least the major versions of lvgl
– Respond to the issues (in a reasonable time)
• If there is no activity in a repo for 6 months it will be archived