summaryrefslogtreecommitdiff
path: root/lib/lvgl/examples/widgets/imagebutton
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-06-12 17:54:40 +1000
committerjacqueline <me@jacqueline.id.au>2024-06-12 17:54:40 +1000
commit64bd9053a25297f7a442ca831c7da5b44bd33f84 (patch)
treea90c6cad25a12028302ab1a5334510fba0229bae /lib/lvgl/examples/widgets/imagebutton
parent611176ed667c4ed7ee9f609e958f9404f4aee91d (diff)
downloadtangara-fw-64bd9053a25297f7a442ca831c7da5b44bd33f84.tar.gz
Update LVGL to v9.1.0
Diffstat (limited to 'lib/lvgl/examples/widgets/imagebutton')
-rw-r--r--lib/lvgl/examples/widgets/imagebutton/index.rst7
-rw-r--r--lib/lvgl/examples/widgets/imagebutton/lv_example_imagebutton_1.c43
2 files changed, 50 insertions, 0 deletions
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