1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

feat(animimage): add property support

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
Neo Xu 2024-12-01 22:37:28 +08:00 committed by Gabor Kiss-Vamosi
parent 4eacf15f59
commit f5b00f5ad8
7 changed files with 108 additions and 0 deletions

View File

@ -169,6 +169,9 @@ r'''
* End of parsing lv_conf_template.h
-----------------------------------*/
/*Fix inconsistent name*/
#define LV_USE_ANIMIMAGE LV_USE_ANIMIMG
#ifndef __ASSEMBLY__
LV_EXPORT_CONST_INT(LV_DPI_DEF);
LV_EXPORT_CONST_INT(LV_DRAW_BUF_STRIDE_ALIGN);

View File

@ -4127,6 +4127,9 @@
* End of parsing lv_conf_template.h
-----------------------------------*/
/*Fix inconsistent name*/
#define LV_USE_ANIMIMAGE LV_USE_ANIMIMG
#ifndef __ASSEMBLY__
LV_EXPORT_CONST_INT(LV_DPI_DEF);
LV_EXPORT_CONST_INT(LV_DRAW_BUF_STRIDE_ALIGN);

View File

@ -44,11 +44,47 @@ static void lv_animimg_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
* STATIC VARIABLES
**********************/
#if LV_USE_OBJ_PROPERTY
static const lv_property_ops_t properties[] = {
{
.id = LV_PROPERTY_ANIMIMAGE_SRC,
.setter = lv_animimg_set_src,
.getter = lv_animimg_get_src,
},
{
.id = LV_PROPERTY_ANIMIMAGE_DURATION,
.setter = lv_animimg_set_duration,
.getter = lv_animimg_get_duration,
},
{
.id = LV_PROPERTY_ANIMIMAGE_REPEAT_COUNT,
.setter = lv_animimg_set_repeat_count,
.getter = lv_animimg_get_repeat_count,
},
{
.id = LV_PROPERTY_ANIMIMAGE_SRC_COUNT,
.setter = NULL,
.getter = lv_animimg_get_src_count,
},
};
#endif
const lv_obj_class_t lv_animimg_class = {
.constructor_cb = lv_animimg_constructor,
.instance_size = sizeof(lv_animimg_t),
.base_class = &lv_image_class,
.name = "animimg",
#if LV_USE_OBJ_PROPERTY
.prop_index_start = LV_PROPERTY_ANIMIMAGE_START,
.prop_index_end = LV_PROPERTY_ANIMIMAGE_END,
.properties = properties,
.properties_count = sizeof(properties) / sizeof(properties[0]),
#if LV_USE_OBJ_PROPERTY_NAME
.property_names = lv_animimage_property_names,
.names_count = sizeof(lv_animimage_property_names) / sizeof(lv_property_name_t),
#endif
#endif
};
/**********************

View File

@ -31,6 +31,16 @@ extern "C" {
* TYPEDEFS
**********************/
#if LV_USE_OBJ_PROPERTY
enum {
LV_PROPERTY_ID2(ANIMIMAGE, SRC, LV_PROPERTY_TYPE_POINTER, LV_PROPERTY_TYPE_INT, 0),
LV_PROPERTY_ID(ANIMIMAGE, DURATION, LV_PROPERTY_TYPE_INT, 1),
LV_PROPERTY_ID(ANIMIMAGE, REPEAT_COUNT, LV_PROPERTY_TYPE_INT, 2),
LV_PROPERTY_ID(ANIMIMAGE, SRC_COUNT, LV_PROPERTY_TYPE_INT, 3),
LV_PROPERTY_ANIMIMAGE_END,
};
#endif
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_animimg_class;
/** Image parts */

View File

@ -0,0 +1,26 @@
/**
* GENERATED FILE, DO NOT EDIT IT!
* @file lv_animimage_properties.c
*/
#include "../animimage/lv_animimage.h"
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
#if LV_USE_ANIMIMAGE
/**
* Animimage widget property names, name must be in order.
* Generated code from properties.py
*/
/* *INDENT-OFF* */
const lv_property_name_t lv_animimage_property_names[4] = {
{"duration", LV_PROPERTY_ANIMIMAGE_DURATION,},
{"repeat_count", LV_PROPERTY_ANIMIMAGE_REPEAT_COUNT,},
{"src", LV_PROPERTY_ANIMIMAGE_SRC,},
{"src_count", LV_PROPERTY_ANIMIMAGE_SRC_COUNT,},
};
#endif /*LV_USE_ANIMIMAGE*/
/* *INDENT-ON* */
#endif

View File

@ -10,6 +10,7 @@
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
extern const lv_property_name_t lv_animimage_property_names[4];
extern const lv_property_name_t lv_dropdown_property_names[9];
extern const lv_property_name_t lv_image_property_names[11];
extern const lv_property_name_t lv_keyboard_property_names[4];

View File

@ -104,4 +104,33 @@ void test_animimg_start(void)
TEST_ASSERT_NOT_NULL(animimg);
}
void test_animimg_property(void)
{
#if LV_USE_OBJ_PROPERTY
lv_property_t prop;
lv_obj_t * obj = lv_animimg_create(lv_screen_active());
prop.id = LV_PROPERTY_ANIMIMAGE_SRC;
prop.arg1.ptr = anim_imgs;
prop.arg2.num = 3;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_PTR(lv_obj_get_property(obj, LV_PROPERTY_ANIMIMAGE_SRC).ptr, anim_imgs);
TEST_ASSERT_EQUAL_PTR(lv_animimg_get_src(obj), anim_imgs);
TEST_ASSERT_EQUAL_INT(lv_animimg_get_src_count(obj), 3);
TEST_ASSERT_EQUAL_INT(3, lv_obj_get_property(obj, LV_PROPERTY_ANIMIMAGE_SRC_COUNT).num);
prop.id = LV_PROPERTY_ANIMIMAGE_DURATION;
prop.num = 1000;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(1000, lv_animimg_get_duration(obj));
TEST_ASSERT_EQUAL_INT(1000, lv_obj_get_property(obj, LV_PROPERTY_ANIMIMAGE_DURATION).num);
prop.id = LV_PROPERTY_ANIMIMAGE_REPEAT_COUNT;
prop.num = LV_ANIM_REPEAT_INFINITE;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(LV_ANIM_REPEAT_INFINITE, lv_animimg_get_repeat_count(obj));
TEST_ASSERT_EQUAL_INT(LV_ANIM_REPEAT_INFINITE, lv_obj_get_property(obj, LV_PROPERTY_ANIMIMAGE_REPEAT_COUNT).num_u);
#endif
}
#endif