feat(buttonmatrix): add property interface support

Add property interface for buttonmatrix widget:
- SELECTED_BUTTON, ONE_CHECKED
- Add property test function
This commit is contained in:
Neo Xu
2025-12-02 14:15:39 +08:00
committed by VIFEX
parent 492770e77f
commit 847cc0c8de
6 changed files with 80 additions and 0 deletions
+1
View File
@@ -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*/
@@ -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)
};
/**********************
@@ -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
**********************/
@@ -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
@@ -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];
@@ -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