Files
lvgl/demos/lv_demos.c
bjsylvia bdd6209973
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
feat(demos): allow specifying parent for widgets and music demos (#9444)
Signed-off-by: bjsylvia <bjsylvia@163.com>
2026-01-05 12:32:19 +08:00

133 lines
2.9 KiB
C

/**
* @file lv_demos.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_demos.h"
/*********************
* DEFINES
*********************/
#define LV_DEMOS_COUNT (sizeof(demos_entry_info) / sizeof(demo_entry_info_t) - 1)
/**********************
* TYPEDEFS
**********************/
typedef void (*demo_method_cb)(void);
typedef struct {
const char * name;
demo_method_cb entry_cb;
} demo_entry_info_t;
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static const demo_entry_info_t demos_entry_info[] = {
#if LV_USE_DEMO_WIDGETS
{ "widgets", .entry_cb = lv_demo_widgets },
#endif
#if LV_USE_DEMO_MUSIC
{ "music", .entry_cb = lv_demo_music },
#endif
#if LV_USE_DEMO_STRESS
{ "stress", .entry_cb = lv_demo_stress },
#endif
#if LV_USE_DEMO_KEYPAD_AND_ENCODER
{ "keypad_encoder", .entry_cb = lv_demo_keypad_encoder },
#endif
#if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC
{ "vector_graphic_buffered", .entry_cb = lv_demo_vector_graphic_buffered },
#endif
#if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC
{ "vector_graphic_not_buffered", .entry_cb = lv_demo_vector_graphic_not_buffered },
#endif
#if LV_USE_DEMO_BENCHMARK
{ "benchmark", .entry_cb = lv_demo_benchmark },
#endif
{ "", .entry_cb = NULL }
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_demo_args_init(lv_demo_args_t * args)
{
LV_ASSERT_NULL(args);
lv_memzero(args, sizeof(lv_demo_args_t));
args->parent = lv_screen_active();
}
bool lv_demos_create(char * info[], int size)
{
const int demos_count = LV_DEMOS_COUNT;
if(demos_count <= 0) {
LV_LOG_ERROR("Please enable some lv_demos firstly!");
return false;
}
const demo_entry_info_t * entry_info = NULL;
if(size <= 0) { /* default: first demo*/
entry_info = &demos_entry_info[0];
}
else if(entry_info == NULL && info) {
const char * name = info[0];
for(int i = 0; i < demos_count; i++) {
if(lv_strcmp(name, demos_entry_info[i].name) == 0) {
entry_info = &demos_entry_info[i];
}
}
}
if(entry_info == NULL) {
LV_LOG_ERROR("lv_demos create(%s) failure!", size > 0 ? info[0] : "");
return false;
}
if(entry_info->entry_cb) {
entry_info->entry_cb();
return true;
}
return false;
}
void lv_demos_show_help(void)
{
int i;
const int demos_count = LV_DEMOS_COUNT;
if(demos_count == 0) {
LV_LOG("lv_demos: no demo available!\n");
return;
}
LV_LOG("\nUsage: lv_demos demo [parameters]\n");
LV_LOG("\ndemo list:\n");
for(i = 0; i < demos_count; i++) {
LV_LOG(" %s \n", demos_entry_info[i].name);
}
}