diff --git a/src/core/lv_obj_property.h b/src/core/lv_obj_property.h index 5642892d5b..92dc88724e 100644 --- a/src/core/lv_obj_property.h +++ b/src/core/lv_obj_property.h @@ -62,6 +62,7 @@ enum { /*Define the property ID for every widget here. */ LV_PROPERTY_OBJ_START = 0x0100, /* lv_obj.c */ LV_PROPERTY_IMAGE_START = 0x0200, /* lv_image.c */ + LV_PROPERTY_LABEL_START = 0x0300, /* lv_label.c */ /*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/ LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/ diff --git a/src/widgets/label/lv_label.c b/src/widgets/label/lv_label.c index d1ca93320c..a358f763a8 100644 --- a/src/widgets/label/lv_label.c +++ b/src/widgets/label/lv_label.c @@ -60,6 +60,31 @@ static void calculate_x_coordinate(int32_t * x, const lv_text_align_t align, con /********************** * STATIC VARIABLES **********************/ +#if LV_USE_OBJ_PROPERTY +static const lv_property_ops_t properties[] = { + { + .id = LV_PROPERTY_LABEL_TEXT, + .setter = lv_label_set_text, + .getter = lv_label_get_text, + }, + { + .id = LV_PROPERTY_LABEL_LONG_MODE, + .setter = lv_label_set_long_mode, + .getter = lv_label_get_long_mode, + }, + { + .id = LV_PROPERTY_LABEL_TEXT_SELECTION_START, + .setter = lv_label_set_text_selection_start, + .getter = lv_label_get_text_selection_start, + }, + { + .id = LV_PROPERTY_LABEL_TEXT_SELECTION_END, + .setter = lv_label_set_text_selection_end, + .getter = lv_label_get_text_selection_end, + }, +}; +#endif + const lv_obj_class_t lv_label_class = { .constructor_cb = lv_label_constructor, .destructor_cb = lv_label_destructor, @@ -69,6 +94,18 @@ const lv_obj_class_t lv_label_class = { .instance_size = sizeof(lv_label_t), .base_class = &lv_obj_class, .name = "label", +#if LV_USE_OBJ_PROPERTY + .prop_index_start = LV_PROPERTY_LABEL_START, + .prop_index_end = LV_PROPERTY_LABEL_END, + .properties = properties, + .properties_count = sizeof(properties) / sizeof(properties[0]), + +#if LV_USE_OBJ_PROPERTY_NAME + .property_names = lv_label_property_names, + .names_count = sizeof(lv_label_property_names) / sizeof(lv_property_name_t), +#endif + +#endif }; /********************** diff --git a/src/widgets/label/lv_label.h b/src/widgets/label/lv_label.h index 2f1954152b..f0143d502e 100644 --- a/src/widgets/label/lv_label.h +++ b/src/widgets/label/lv_label.h @@ -59,6 +59,16 @@ typedef _lv_label_long_mode_t lv_label_long_mode_t; typedef uint8_t lv_label_long_mode_t; #endif /*DOXYGEN*/ +#if LV_USE_OBJ_PROPERTY +enum { + LV_PROPERTY_ID(LABEL, TEXT, LV_PROPERTY_TYPE_TEXT, 0), + LV_PROPERTY_ID(LABEL, LONG_MODE, LV_PROPERTY_TYPE_INT, 1), + LV_PROPERTY_ID(LABEL, TEXT_SELECTION_START, LV_PROPERTY_TYPE_INT, 2), + LV_PROPERTY_ID(LABEL, TEXT_SELECTION_END, LV_PROPERTY_TYPE_INT, 3), + LV_PROPERTY_LABEL_END, +}; +#endif + typedef struct { lv_obj_t obj; char * text; diff --git a/src/widgets/property/lv_label_properties.c b/src/widgets/property/lv_label_properties.c new file mode 100644 index 0000000000..5fc6708b7c --- /dev/null +++ b/src/widgets/property/lv_label_properties.c @@ -0,0 +1,26 @@ + +/** + * GENERATED FILE, DO NOT EDIT IT! + * @file lv_label_properties.c + */ + +#include "../label/lv_label.h" + +#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME + +#if LV_USE_LABEL +/** + * Label widget property names, name must be in order. + * Generated code from properties.py + */ +/* *INDENT-OFF* */ +const lv_property_name_t lv_label_property_names[4] = { + {"long_mode", LV_PROPERTY_LABEL_LONG_MODE,}, + {"text", LV_PROPERTY_LABEL_TEXT,}, + {"text_selection_end", LV_PROPERTY_LABEL_TEXT_SELECTION_END,}, + {"text_selection_start", LV_PROPERTY_LABEL_TEXT_SELECTION_START,}, +}; +#endif /*LV_USE_LABEL*/ + +/* *INDENT-ON* */ +#endif diff --git a/src/widgets/property/lv_obj_property_names.h b/src/widgets/property/lv_obj_property_names.h index 3ac9e15a03..f308bd27d6 100644 --- a/src/widgets/property/lv_obj_property_names.h +++ b/src/widgets/property/lv_obj_property_names.h @@ -11,6 +11,7 @@ #if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME extern const lv_property_name_t lv_image_property_names[11]; + extern const lv_property_name_t lv_label_property_names[4]; extern const lv_property_name_t lv_obj_property_names[73]; extern const lv_property_name_t lv_style_property_names[111]; #endif diff --git a/tests/src/test_cases/widgets/test_obj_property.c b/tests/src/test_cases/widgets/test_obj_property.c index 165732e6b0..998aebd393 100644 --- a/tests/src/test_cases/widgets/test_obj_property.c +++ b/tests/src/test_cases/widgets/test_obj_property.c @@ -271,4 +271,38 @@ void test_obj_property_name(void) #endif } +void test_label_properties(void) +{ +#if LV_USE_OBJ_PROPERTY + lv_obj_t * obj = lv_label_create(lv_screen_active()); + lv_property_t prop = { }; + + prop.id = LV_PROPERTY_LABEL_TEXT; + prop.ptr = "Hello world"; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_STRING("Hello world", lv_label_get_text(obj)); + TEST_ASSERT_EQUAL_STRING("Hello world", lv_obj_get_property(obj, LV_PROPERTY_LABEL_TEXT).ptr); + + prop.id = LV_PROPERTY_LABEL_LONG_MODE; + prop.num = LV_LABEL_LONG_SCROLL; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(LV_LABEL_LONG_SCROLL, lv_label_get_long_mode(obj)); + TEST_ASSERT_EQUAL_INT(LV_LABEL_LONG_SCROLL, lv_obj_get_property(obj, LV_PROPERTY_LABEL_LONG_MODE).num); + +#if LV_LABEL_TEXT_SELECTION + prop.id = LV_PROPERTY_LABEL_TEXT_SELECTION_START; + prop.num = 2; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(2, lv_label_get_text_selection_start(obj)); + TEST_ASSERT_EQUAL_INT(2, lv_obj_get_property(obj, LV_PROPERTY_LABEL_TEXT_SELECTION_START).num); + + prop.id = LV_PROPERTY_LABEL_TEXT_SELECTION_END; + prop.num = 5; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(5, lv_label_get_text_selection_end(obj)); + TEST_ASSERT_EQUAL_INT(5, lv_obj_get_property(obj, LV_PROPERTY_LABEL_TEXT_SELECTION_END).num); +#endif +#endif +} + #endif