2021-12-17 03:49:41 +08:00
# Demos for LVGL
## Add the examples to your projects
2022-03-21 18:25:51 +08:00
1. demos can be found in the 'demos' folder once you clone the lvgl.
2022-01-21 02:52:52 +08:00
2. In the ** *lv_conf.h*** or equivalent places, you can find demo related macros, change its value to enable or disable specified demos:
```c
...
/*===================
* DEMO USAGE
====================*/
2024-09-26 18:09:04 +08:00
/* Show some widget. It might be required to increase `LV_MEM_SIZE` */
2022-01-21 02:52:52 +08:00
#define LV_USE_DEMO_WIDGETS 0
2024-09-26 18:09:04 +08:00
/* Demonstrate the usage of encoder and keyboard */
2022-01-21 02:52:52 +08:00
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0
2024-09-26 18:09:04 +08:00
/* Benchmark your system */
2022-01-21 02:52:52 +08:00
#define LV_USE_DEMO_BENCHMARK 0
2024-09-26 18:09:04 +08:00
/* Stress test for LVGL */
2022-01-21 02:52:52 +08:00
#define LV_USE_DEMO_STRESS 0
2024-09-26 18:09:04 +08:00
/* Music player demo */
2022-01-21 02:52:52 +08:00
#define LV_USE_DEMO_MUSIC 0
#if LV_USE_DEMO_MUSIC
# define LV_DEMO_MUSIC_SQUARE 0
# define LV_DEMO_MUSIC_LANDSCAPE 0
# define LV_DEMO_MUSIC_ROUND 0
# define LV_DEMO_MUSIC_LARGE 0
# define LV_DEMO_MUSIC_AUTO_PLAY 0
#endif
2023-10-11 04:28:17 +08:00
2024-09-26 18:09:04 +08:00
/* Flex layout demo */
2023-10-11 04:28:17 +08:00
#define LV_USE_DEMO_FLEX_LAYOUT 0
2024-09-26 18:09:04 +08:00
/* Smart-phone like multi-language demo */
2023-10-11 04:28:17 +08:00
#define LV_USE_DEMO_MULTILANG 0
2024-09-26 18:09:04 +08:00
/* Widget transformation demo */
2023-10-11 04:28:17 +08:00
#define LV_USE_DEMO_TRANSFORM 0
2024-09-26 18:09:04 +08:00
/* Demonstrate scroll settings */
2023-10-11 04:28:17 +08:00
#define LV_USE_DEMO_SCROLL 0
2022-01-21 02:52:52 +08:00
...
```
2022-03-21 18:25:51 +08:00
3. If your development environment or toolchain does not add source files inside '***lvgl***' folder automatically, ensure the `demos` folder is included for compilation.
2022-01-21 02:52:52 +08:00
4. Include "***demos/lv_demos.h***" in your application source file, for example:
```c
//! main.c
#include "lvgl.h"
#include "demos/lv_demos.h"
...
```
2023-10-11 04:28:17 +08:00
## Configure Demos Entry
2022-01-21 02:52:52 +08:00
2024-03-25 14:43:27 +08:00
"demos/lv_demos.c" provides `lv_demos_create` and `lv_demos_show_help` to simplify the creation of demos.
2023-10-11 04:28:17 +08:00
If you build your main program named `lv_demos` , then you can run the widgets demo by running `lv_demos widgets` and the benchmark demo by running `lv_demos benchmark 1` .
For example:
```c
//! main.c
#include "lvgl.h"
#include "demos/lv_demos.h"
...
2024-04-10 15:17:44 +08:00
static lv_display_t* hal_init(void)
2023-10-11 04:28:17 +08:00
{
2024-04-10 15:17:44 +08:00
lv_display_t* disp = NULL;
2023-10-11 04:28:17 +08:00
...
/* TODO: init display and indev */
...
return disp;
}
int main(int argc, char ** argv)
{
lv_init();
2024-04-10 15:17:44 +08:00
lv_display_t* disp = hal_init();
2023-10-11 04:28:17 +08:00
if (disp == NULL) {
LV_LOG_ERROR("lv_demos initialization failure!");
return 1;
}
if (!lv_demos_create(& argv[1], argc - 1)) {
2024-03-25 14:43:27 +08:00
lv_demos_show_help();
2023-10-11 04:28:17 +08:00
goto demo_end;
}
while (1) {
uint32_t delay = lv_timer_handler();
if (delay < 1 ) delay = 1;
usleep(delay * 1000);
}
demo_end:
lv_deinit();
return 0;
}
```
2021-12-17 03:49:41 +08:00
## Demos
### Widgets
2022-03-21 18:25:51 +08:00
Shows how the widgets look like out of the box using the built-in material theme.
2022-01-29 21:34:08 +08:00
2022-02-21 23:13:12 +08:00
See in [widgets ](https://github.com/lvgl/lvgl/tree/master/demos/widgets ) folder.
2021-12-17 03:49:41 +08:00
2022-08-19 18:28:00 +08:00
![Basic demo to show the widgets of LVGL ](widgets/screenshot1.png )
2021-12-17 03:49:41 +08:00
2022-01-29 21:34:08 +08:00
For running this demo properly, please make sure **LV_MEM_SIZE** is at least **38KB** (and **48KB** is recommended):
```c
2024-08-13 17:06:09 +08:00
#define LV_MEM_SIZE (38ul * 1024ul)
2022-01-29 21:34:08 +08:00
```
2021-12-17 03:49:41 +08:00
### Music player
2022-03-21 18:25:51 +08:00
The music player demo shows what kind of modern, smartphone-like user interfaces can be created on LVGL. It works the best with display with 480x272 or 272x480 resolution.
2021-12-17 03:49:41 +08:00
2022-02-21 23:13:12 +08:00
See in [music ](https://github.com/lvgl/lvgl/tree/master/demos/music ) folder.
2021-12-17 03:49:41 +08:00
2022-08-19 18:28:00 +08:00
![Music player demo with LVGL ](music/screenshot1.gif )
2021-12-17 03:49:41 +08:00
### Keypad and encoder
2022-03-21 18:25:51 +08:00
LVGL allows you to control the widgets with a keypad and/or encoder without a touchpad. This demo shows how to handle buttons, drop-down lists, rollers, sliders, switches, and text inputs without touchpad.
2022-02-21 23:13:12 +08:00
Learn more about the touchpad-less usage of LVGL [here ](https://docs.lvgl.io/master/overview/indev.html#keypad-and-encoder ).
2021-12-17 03:49:41 +08:00
2022-02-21 23:13:12 +08:00
See in [keypad_encoder ](https://github.com/lvgl/lvgl/tree/master/demos/keypad_encoder ) folder.
2021-12-17 03:49:41 +08:00
2022-08-19 18:28:00 +08:00
![Keypad and encoder navigation in LVGL embedded GUI library ](keypad_encoder/screenshot1.png )
2021-12-17 03:49:41 +08:00
### Benchmark
2022-03-21 18:25:51 +08:00
A demo to measure the performance of LVGL or to compare different settings.
2022-02-21 23:13:12 +08:00
See in [benchmark ](https://github.com/lvgl/lvgl/tree/master/demos/benchmark ) folder.
2022-08-19 18:28:00 +08:00
![Benchmark demo with LVGL embedded GUI library ](benchmark/screenshot1.png )
2021-12-17 03:49:41 +08:00
### Stress
2022-03-21 18:25:51 +08:00
A stress test for LVGL. It contains a lot of object creation, deletion, animations, style usage, and so on. It can be used if there is any memory corruption during heavy usage or any memory leaks.
2022-02-21 23:13:12 +08:00
See in [stress ](https://github.com/lvgl/lvgl/tree/master/demos/stress ) folder.
2022-08-19 18:28:00 +08:00
![Stress test for LVGL ](stress/screenshot1.png )
2021-12-17 03:49:41 +08:00
## Contributing
2022-01-17 21:10:23 +08:00
For contribution and coding style guidelines, please refer to the file docs/CONTRIBUTING.md in the main LVGL repo:
2021-12-17 03:49:41 +08:00
https://github.com/lvgl/lvgl