同步操作将从 Gitee 极速下载/littlevGL 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
LVGL provides everything you need to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low memory footprint.
Basically, every modern controller (which is able to drive a display) is suitable to run LVGL. The minimal requirements are:
LV_MEM_SIZE
in lv_conf.h.Note that the memory usage might vary depending on the architecture, compiler and build options.
Just to mention some platforms:
The easiest way to get started with LVGL is to run it in a simulator on your PC without any embedded hardware.
Choose a project with your favourite IDE:
Eclipse | CodeBlocks | Visual Studio | PlatformIO | Qt Creator |
---|---|---|---|---|
Cross-platform with SDL (Recommended on Linux and Mac) |
Native Windows | Windows with SDL |
Cross-platform with SDL |
Cross-platform with SDL |
The steps below show how to setup LVGL on an embedded system with a display and a touchpad. You can use the Simulators to get ready to use projects which can be run on your PC.
lvgl
folder into your projectlvgl/lv_conf_template.h
as lv_conf.h
next to the lvgl
folder, change the #if 0
statement near the top of the file to #if 1
and set at least LV_HOR_RES_MAX
, LV_VER_RES_MAX
and LV_COLOR_DEPTH
.lvgl/lvgl.h
where you need to use LVGL related functions.lv_tick_inc(x)
every x
milliseconds (should be 1..10) in a Timer or Task. It is required for the internal timing of LVGL.lv_init()
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
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*/
void my_disp_flush(lv_disp_t * disp, const lv_area_t * area, lv_color_t * color_p)
{
int32_t x, y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
my_set_pixel(x, y, *color_p); /* Put a pixel to the display.*/
color_p++;
}
}
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
}
lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
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*/
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
data->state = my_touchpad_is_pressed() ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&data->point.x, &data->point.y);
return false; /*Return `false` because we are not buffering and no more data to read*/
}
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 more detailed desription visit the Porting section of the documentation.
In this section you can read the very basics of LVGL. For a more detailed guide check the Quick overview in the documentation.
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 types.
Every object has a parent object. The child object moves with the parent and if you delete the parent the children will be deleted too. Children can be visible only on their parent.
The screen are the "root" parents. To get the current screen call lv_scr_act()
.
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 later.
The first parameter is the desired parent, the second parameters can be an object to copy (NULL
if unused).
For example:
lv_obj_t * slider1 = lv_slider_create(lv_scr_act(), NULL);
To set some basic attribute lv_obj_set_<paramters_name>(obj, <value>)
function can be used. For example:
lv_obj_set_x(btn1, 30);
lv_obj_set_y(btn1, 10);
lv_obj_set_size(btn1, 200, 50);
The objects have type specific parameters too which can be set by lv_<type>_set_<paramters_name>(obj, <value>)
functions. For example:
lv_slider_set_value(slider1, 70, LV_ANIM_ON);
To see the full API visit the documentation of the object types or the related header file (e.g. lvgl/src/lv_objx/lv_slider.h
).
To create a new screen pass NULL
as the fisrt paramater of a create function:
lv_obj_t * scr2 = lv_obj_create(NULL, NULL); /*Create a screen*/
lv_scr_load(scr2); /*Load the new screen*/
Widgets are created with a default appearance but it can be changed by adding new styles to them. A new style can be created like this:
static lv_style_t style1; /*Should be static, global or dynamically allocated*/
lv_style_init(&style1);
lv_style_set_bg_color(&style1, LV_STATE_DEFAULT, LV_COLOR_RED); /*Default background color*/
lv_style_set_bg_color(&style1, LV_STATE_PRESSED, LV_COLOR_BLUE); /*Pressed background color*/
The wigedt have parts which can be referenced via LV_<TYPE>_PART_<PART_NAME>
. E.g. LV_BTN_PART_MAIN
or LV_SLIDER_PART_KNOB
. See the documentation of the widgets to see the exisitng parts.
To add the style to a button:
lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &style1);
To remove all styles from a part of an object:
lv_obj_reset_style_list(obj, LV_OBJ_PART_MAIN);
Learn more in Style overview section.
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:
lv_obj_set_event_cb(btn, btn_event_cb); /*Assign a callback to the button*/
...
void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
printf("Clicked\n");
}
}
Learn more about the events in the Event overview section.
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
lv_obj_set_size(btn, 100, 50); /*Set its size*/
lv_obj_set_event_cb(btn, btn_event_cb); /*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/
lv_label_set_text(label, "Button"); /*Set the labels text*/
...
void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
printf("Clicked\n");
}
}
Learn more about Micropython.
# Create a Button and a Label
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")
# Load the screen
lv.scr_load(scr)
LVGL follows the rules of Semantic versioning:
Branches:
master
most recent version, patches are merged directly here.dev
merge new features here until they are merged into master
.release/vX
there is a branch for every major version to allow adding specific, not forward compatible fixes.LVGL has a monthly periodic release cycle.
master
depending on the new features.
- After that merge only patches into master
and add new features into the dev
.master
.
- After that merge the new features from the dev
to master
branch.
- In the rest of the month merge only patches into master
and new features into dev
branch.To ask questions please use the Forum. For development-related things (bug reports, feature suggestions) use GitHub's Issue tracker.
If you are interested in contributing to LVGL you can
Before sending Pull requests, please read the following guides:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。