From 64bd9053a25297f7a442ca831c7da5b44bd33f84 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 12 Jun 2024 17:54:40 +1000 Subject: Update LVGL to v9.1.0 --- lib/lvgl/examples/widgets/imagebutton/index.rst | 7 ++++ .../widgets/imagebutton/lv_example_imagebutton_1.c | 43 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 lib/lvgl/examples/widgets/imagebutton/index.rst create mode 100644 lib/lvgl/examples/widgets/imagebutton/lv_example_imagebutton_1.c (limited to 'lib/lvgl/examples/widgets/imagebutton') diff --git a/lib/lvgl/examples/widgets/imagebutton/index.rst b/lib/lvgl/examples/widgets/imagebutton/index.rst new file mode 100644 index 00000000..b33ab13b --- /dev/null +++ b/lib/lvgl/examples/widgets/imagebutton/index.rst @@ -0,0 +1,7 @@ + +Simple Image button +------------------- + +.. lv_example:: widgets/imagebutton/lv_example_imagebutton_1 + :language: c + diff --git a/lib/lvgl/examples/widgets/imagebutton/lv_example_imagebutton_1.c b/lib/lvgl/examples/widgets/imagebutton/lv_example_imagebutton_1.c new file mode 100644 index 00000000..22fd694f --- /dev/null +++ b/lib/lvgl/examples/widgets/imagebutton/lv_example_imagebutton_1.c @@ -0,0 +1,43 @@ +#include "../../lv_examples.h" +#if LV_USE_IMAGEBUTTON && LV_BUILD_EXAMPLES + +void lv_example_imagebutton_1(void) +{ + LV_IMAGE_DECLARE(imagebutton_left); + LV_IMAGE_DECLARE(imagebutton_right); + LV_IMAGE_DECLARE(imagebutton_mid); + + /*Create a transition animation on width transformation and recolor.*/ + static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMAGE_RECOLOR_OPA, 0}; + static lv_style_transition_dsc_t tr; + lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL); + + static lv_style_t style_def; + lv_style_init(&style_def); + lv_style_set_text_color(&style_def, lv_color_white()); + lv_style_set_transition(&style_def, &tr); + + /*Darken the button when pressed and make it wider*/ + static lv_style_t style_pr; + lv_style_init(&style_pr); + lv_style_set_image_recolor_opa(&style_pr, LV_OPA_30); + lv_style_set_image_recolor(&style_pr, lv_color_black()); + lv_style_set_transform_width(&style_pr, 20); + + /*Create an image button*/ + lv_obj_t * imagebutton1 = lv_imagebutton_create(lv_screen_active()); + lv_imagebutton_set_src(imagebutton1, LV_IMAGEBUTTON_STATE_RELEASED, &imagebutton_left, &imagebutton_mid, + &imagebutton_right); + lv_obj_add_style(imagebutton1, &style_def, 0); + lv_obj_add_style(imagebutton1, &style_pr, LV_STATE_PRESSED); + + lv_obj_set_width(imagebutton1, 100); + lv_obj_align(imagebutton1, LV_ALIGN_CENTER, 0, 0); + + /*Create a label on the image button*/ + lv_obj_t * label = lv_label_create(imagebutton1); + lv_label_set_text(label, "Button"); + lv_obj_align(label, LV_ALIGN_CENTER, 0, -4); +} + +#endif -- cgit v1.2.3