diff --git a/src/core/lv_obj_property.h b/src/core/lv_obj_property.h index bfe933c172..4eb51eb74d 100644 --- a/src/core/lv_obj_property.h +++ b/src/core/lv_obj_property.h @@ -115,6 +115,7 @@ enum _lv_prop_id_range_boundary_t { LV_PROPERTY_SPINNER_START = 0x1200, /* lv_spinner.c */ LV_PROPERTY_TABLE_START = 0x1300, /* lv_table.c */ LV_PROPERTY_TABVIEW_START = 0x1400, /* lv_tabview.c */ + LV_PROPERTY_BUTTONMATRIX_START = 0x1500, /* lv_buttonmatrix.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/buttonmatrix/lv_buttonmatrix.c b/src/widgets/buttonmatrix/lv_buttonmatrix.c index 32773b535b..27befa32f2 100644 --- a/src/widgets/buttonmatrix/lv_buttonmatrix.c +++ b/src/widgets/buttonmatrix/lv_buttonmatrix.c @@ -66,6 +66,21 @@ static void free_map(lv_buttonmatrix_t * btnm); static const char * const lv_buttonmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""}; #endif +#if LV_USE_OBJ_PROPERTY +static const lv_property_ops_t lv_buttonmatrix_properties[] = { + { + .id = LV_PROPERTY_BUTTONMATRIX_SELECTED_BUTTON, + .setter = lv_buttonmatrix_set_selected_button, + .getter = lv_buttonmatrix_get_selected_button, + }, + { + .id = LV_PROPERTY_BUTTONMATRIX_ONE_CHECKED, + .setter = lv_buttonmatrix_set_one_checked, + .getter = lv_buttonmatrix_get_one_checked, + }, +}; +#endif + const lv_obj_class_t lv_buttonmatrix_class = { .constructor_cb = lv_buttonmatrix_constructor, .destructor_cb = lv_buttonmatrix_destructor, @@ -77,6 +92,7 @@ const lv_obj_class_t lv_buttonmatrix_class = { .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, .base_class = &lv_obj_class, .name = "lv_buttonmatrix", + LV_PROPERTY_CLASS_FIELDS(buttonmatrix, BUTTONMATRIX) }; /********************** diff --git a/src/widgets/buttonmatrix/lv_buttonmatrix.h b/src/widgets/buttonmatrix/lv_buttonmatrix.h index fc2550e1fe..771be506c4 100644 --- a/src/widgets/buttonmatrix/lv_buttonmatrix.h +++ b/src/widgets/buttonmatrix/lv_buttonmatrix.h @@ -18,6 +18,7 @@ extern "C" { #if LV_USE_BUTTONMATRIX != 0 #include "../../core/lv_obj.h" +#include "../../core/lv_obj_property.h" /********************* * DEFINES @@ -67,6 +68,14 @@ typedef bool (*lv_buttonmatrix_button_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_i LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_buttonmatrix_class; +#if LV_USE_OBJ_PROPERTY +enum _lv_property_buttonmatrix_id_t { + LV_PROPERTY_ID(BUTTONMATRIX, SELECTED_BUTTON, LV_PROPERTY_TYPE_INT, 0), + LV_PROPERTY_ID(BUTTONMATRIX, ONE_CHECKED, LV_PROPERTY_TYPE_BOOL, 1), + LV_PROPERTY_BUTTONMATRIX_END, +}; +#endif + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/property/lv_buttonmatrix_properties.c b/src/widgets/property/lv_buttonmatrix_properties.c new file mode 100644 index 0000000000..b56fd95b12 --- /dev/null +++ b/src/widgets/property/lv_buttonmatrix_properties.c @@ -0,0 +1,24 @@ + +/** + * GENERATED FILE, DO NOT EDIT IT! + * @file lv_buttonmatrix_properties.c + */ + +#include "../buttonmatrix/lv_buttonmatrix.h" + +#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME + +#if LV_USE_BUTTONMATRIX +/** + * Buttonmatrix widget property names, name must be in order. + * Generated code from properties.py + */ +/* *INDENT-OFF* */ +const lv_property_name_t lv_buttonmatrix_property_names[2] = { + {"one_checked", LV_PROPERTY_BUTTONMATRIX_ONE_CHECKED,}, + {"selected_button", LV_PROPERTY_BUTTONMATRIX_SELECTED_BUTTON,}, +}; +#endif /*LV_USE_BUTTONMATRIX*/ + +/* *INDENT-ON* */ +#endif diff --git a/src/widgets/property/lv_obj_property_names.h b/src/widgets/property/lv_obj_property_names.h index 127a2eb601..c41a1f8a85 100644 --- a/src/widgets/property/lv_obj_property_names.h +++ b/src/widgets/property/lv_obj_property_names.h @@ -13,6 +13,7 @@ extern const lv_property_name_t lv_animimage_property_names[4]; extern const lv_property_name_t lv_arc_property_names[11]; extern const lv_property_name_t lv_bar_property_names[6]; + extern const lv_property_name_t lv_buttonmatrix_property_names[2]; extern const lv_property_name_t lv_checkbox_property_names[1]; extern const lv_property_name_t lv_dropdown_property_names[9]; extern const lv_property_name_t lv_image_property_names[11]; diff --git a/tests/src/test_cases/widgets/test_btnmatrix.c b/tests/src/test_cases/widgets/test_btnmatrix.c index 59e508f6c7..4a24947a3a 100644 --- a/tests/src/test_cases/widgets/test_btnmatrix.c +++ b/tests/src/test_cases/widgets/test_btnmatrix.c @@ -456,4 +456,33 @@ void test_button_matrix_focused_event_works(void) TEST_ASSERT_TRUE(event_triggered); } +void test_buttonmatrix_properties(void) +{ +#if LV_USE_OBJ_PROPERTY + lv_obj_t * obj = lv_buttonmatrix_create(lv_screen_active()); + + lv_property_t prop = { }; + + /* Test SELECTED_BUTTON property */ + prop.id = LV_PROPERTY_BUTTONMATRIX_SELECTED_BUTTON; + prop.num = 2; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(2, lv_obj_get_property(obj, LV_PROPERTY_BUTTONMATRIX_SELECTED_BUTTON).num); + + /* Test ONE_CHECKED property */ + lv_buttonmatrix_set_button_ctrl_all(obj, LV_BUTTONMATRIX_CTRL_CHECKABLE); + + prop.id = LV_PROPERTY_BUTTONMATRIX_ONE_CHECKED; + prop.num = 1; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(obj, LV_PROPERTY_BUTTONMATRIX_ONE_CHECKED).num); + + prop.num = 0; + TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK); + TEST_ASSERT_EQUAL_INT(0, lv_obj_get_property(obj, LV_PROPERTY_BUTTONMATRIX_ONE_CHECKED).num); + + lv_obj_delete(obj); +#endif +} + #endif