mirror of
https://github.com/lvgl/lvgl.git
synced 2026-08-17 18:22:42 +08:00
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 GDB constants are up-to-date / verify-gdb-consts (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
Build .deb packages / build (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (private) (push) Has been cancelled
Install LVGL using CMake / build-examples (public) (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
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
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
Static Checks / Static Checks (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (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
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
87 lines
2.8 KiB
C
87 lines
2.8 KiB
C
#include "../lv_examples.h"
|
|
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
|
#include "../../lvgl_private.h"
|
|
|
|
static lv_style_t style_btn;
|
|
|
|
|
|
/*Will be called when the styles of the base theme are already added
|
|
to add new styles*/
|
|
static void new_theme_apply_cb(lv_theme_t * th, lv_obj_t * obj)
|
|
{
|
|
LV_UNUSED(th);
|
|
|
|
if(lv_obj_check_type(obj, &lv_button_class)) {
|
|
lv_obj_add_style(obj, &style_btn, 0);
|
|
}
|
|
}
|
|
|
|
static void on_display_delete(lv_event_t * e)
|
|
{
|
|
lv_display_t * display = (lv_display_t *) lv_event_get_target(e);
|
|
lv_theme_t * display_theme = lv_display_get_theme(display);
|
|
lv_theme_delete(display_theme);
|
|
}
|
|
|
|
static void new_theme_init_and_set(void)
|
|
{
|
|
lv_display_t * display = lv_display_get_default();
|
|
|
|
/*Initialize the styles*/
|
|
lv_style_init(&style_btn);
|
|
lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_GREEN));
|
|
lv_style_set_border_color(&style_btn, lv_palette_darken(LV_PALETTE_GREEN, 3));
|
|
lv_style_set_border_width(&style_btn, 3);
|
|
|
|
/* Initialize the new theme with the current theme as its parent
|
|
* The user is responsible for freeing the theme when it's no longer needed */
|
|
lv_theme_t * th_act = lv_display_get_theme(NULL);
|
|
lv_theme_t * th_new = lv_theme_create();
|
|
lv_theme_copy(th_new, th_act);
|
|
lv_theme_set_parent(th_new, th_act);
|
|
|
|
/*Set the style apply callback for the new theme*/
|
|
lv_theme_set_apply_cb(th_new, new_theme_apply_cb);
|
|
|
|
/*Assign the new theme to the current display*/
|
|
lv_display_set_theme(display, th_new);
|
|
|
|
/* Assign a delete event callback so that we can delete the theme when the display is deleted*/
|
|
lv_display_add_event_cb(display, on_display_delete, LV_EVENT_DELETE, NULL);
|
|
}
|
|
|
|
/**
|
|
* @title Extending the current theme
|
|
* @brief Create a child theme that adds a green style to every button.
|
|
*
|
|
* A first button labeled `Original theme` is added to the active screen
|
|
* under the system theme. The helper `new_theme_init_and_set` clones
|
|
* the current theme via `lv_theme_copy`, reparents it with
|
|
* `lv_theme_set_parent`, and registers an apply callback that attaches
|
|
* `style_btn` to any `lv_button_class` object. The new theme is
|
|
* assigned with `lv_display_set_theme`, and a second button labeled
|
|
* `New theme` renders with the green background and darker border. A
|
|
* `LV_EVENT_DELETE` handler on the display frees the theme.
|
|
*/
|
|
void lv_example_style_theme(void)
|
|
{
|
|
lv_obj_t * btn;
|
|
lv_obj_t * label;
|
|
|
|
btn = lv_button_create(lv_screen_active());
|
|
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
|
|
|
|
label = lv_label_create(btn);
|
|
lv_label_set_text(label, "Original theme");
|
|
|
|
new_theme_init_and_set();
|
|
|
|
btn = lv_button_create(lv_screen_active());
|
|
lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -20);
|
|
|
|
label = lv_label_create(btn);
|
|
lv_label_set_text(label, "New theme");
|
|
}
|
|
|
|
#endif
|