feat(roller): add properties
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
committed by
Gabor Kiss-Vamosi
parent
357d5b7ff9
commit
a793178bbf
@@ -66,6 +66,7 @@ enum {
|
||||
LV_PROPERTY_LABEL_START = 0x0300, /* lv_label.c */
|
||||
LV_PROPERTY_KEYBOARD_START = 0x0400, /* lv_keyboard.c */
|
||||
LV_PROPERTY_TEXTAREA_START = 0x0500, /* lv_textarea.c */
|
||||
LV_PROPERTY_ROLLER_START = 0x0600, /* lv_roller.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*/
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
extern const lv_property_name_t lv_keyboard_property_names[4];
|
||||
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_roller_property_names[3];
|
||||
extern const lv_property_name_t lv_style_property_names[112];
|
||||
extern const lv_property_name_t lv_textarea_property_names[15];
|
||||
#endif
|
||||
|
||||
25
src/widgets/property/lv_roller_properties.c
Normal file
25
src/widgets/property/lv_roller_properties.c
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
/**
|
||||
* GENERATED FILE, DO NOT EDIT IT!
|
||||
* @file lv_roller_properties.c
|
||||
*/
|
||||
|
||||
#include "../roller/lv_roller.h"
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
|
||||
|
||||
#if LV_USE_ROLLER
|
||||
/**
|
||||
* Roller widget property names, name must be in order.
|
||||
* Generated code from properties.py
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
const lv_property_name_t lv_roller_property_names[3] = {
|
||||
{"options", LV_PROPERTY_ROLLER_OPTIONS,},
|
||||
{"selected", LV_PROPERTY_ROLLER_SELECTED,},
|
||||
{"visible_row_count", LV_PROPERTY_ROLLER_VISIBLE_ROW_COUNT,},
|
||||
};
|
||||
#endif /*LV_USE_ROLLER*/
|
||||
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
@@ -55,6 +55,26 @@ static void transform_vect_recursive(lv_obj_t * roller, lv_point_t * vect);
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
static const lv_property_ops_t properties[] = {
|
||||
{
|
||||
.id = LV_PROPERTY_ROLLER_OPTIONS,
|
||||
.setter = NULL,
|
||||
.getter = lv_roller_get_options,
|
||||
},
|
||||
{
|
||||
.id = LV_PROPERTY_ROLLER_SELECTED,
|
||||
.setter = NULL,
|
||||
.getter = lv_roller_get_selected,
|
||||
},
|
||||
{
|
||||
.id = LV_PROPERTY_ROLLER_VISIBLE_ROW_COUNT,
|
||||
.setter = lv_roller_set_visible_row_count,
|
||||
.getter = NULL,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
const lv_obj_class_t lv_roller_class = {
|
||||
.constructor_cb = lv_roller_constructor,
|
||||
.event_cb = lv_roller_event,
|
||||
@@ -65,6 +85,17 @@ const lv_obj_class_t lv_roller_class = {
|
||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
|
||||
.base_class = &lv_obj_class,
|
||||
.name = "roller",
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
.prop_index_start = LV_PROPERTY_ROLLER_START,
|
||||
.prop_index_end = LV_PROPERTY_ROLLER_END,
|
||||
.properties = properties,
|
||||
.properties_count = sizeof(properties) / sizeof(properties[0]),
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY_NAME
|
||||
.property_names = lv_roller_property_names,
|
||||
.names_count = sizeof(lv_roller_property_names) / sizeof(lv_property_name_t),
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
const lv_obj_class_t lv_roller_label_class = {
|
||||
@@ -147,7 +178,6 @@ void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_
|
||||
|
||||
/*If the selected text has larger font the label needs some extra draw padding to draw it.*/
|
||||
lv_obj_refresh_ext_draw_size(label);
|
||||
|
||||
}
|
||||
|
||||
void lv_roller_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t anim)
|
||||
|
||||
@@ -38,6 +38,15 @@ typedef enum {
|
||||
LV_ROLLER_MODE_INFINITE, /**< Infinite mode (roller can be scrolled forever).*/
|
||||
} lv_roller_mode_t;
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
enum {
|
||||
LV_PROPERTY_ID(ROLLER, OPTIONS, LV_PROPERTY_TYPE_TEXT, 0),
|
||||
LV_PROPERTY_ID(ROLLER, SELECTED, LV_PROPERTY_TYPE_INT, 1),
|
||||
LV_PROPERTY_ID(ROLLER, VISIBLE_ROW_COUNT, LV_PROPERTY_TYPE_INT, 2),
|
||||
LV_PROPERTY_ROLLER_END,
|
||||
};
|
||||
#endif
|
||||
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_roller_class;
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -330,4 +330,24 @@ void test_roller_appearance(void)
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/roller_3.png");
|
||||
}
|
||||
|
||||
void test_roller_properties(void)
|
||||
{
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
lv_obj_t * obj = lv_roller_create(lv_screen_active());
|
||||
lv_property_t prop = { };
|
||||
|
||||
prop.id = LV_PROPERTY_ROLLER_OPTIONS;
|
||||
prop.ptr = "One\nTwo\nThree";
|
||||
lv_roller_set_options(obj, prop.ptr, LV_ROLLER_MODE_NORMAL);
|
||||
TEST_ASSERT_EQUAL_STRING("One\nTwo\nThree", lv_roller_get_options(obj));
|
||||
TEST_ASSERT_EQUAL_STRING("One\nTwo\nThree", lv_obj_get_property(obj, LV_PROPERTY_ROLLER_OPTIONS).ptr);
|
||||
|
||||
prop.id = LV_PROPERTY_ROLLER_SELECTED;
|
||||
prop.num = 1;
|
||||
lv_roller_set_selected(obj, 1, LV_ANIM_OFF);
|
||||
TEST_ASSERT_EQUAL_INT(1, lv_roller_get_selected(obj));
|
||||
TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(obj, LV_PROPERTY_ROLLER_SELECTED).num);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user