mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 11:07:34 +08:00
feat(checkbox): add property interface support
Add property support for checkbox widget with the following property: - TEXT: checkbox text (LV_PROPERTY_TYPE_TEXT) Also add test_checkbox_properties() test function.
This commit is contained in:
@@ -107,6 +107,7 @@ enum _lv_prop_id_range_boundary_t {
|
||||
LV_PROPERTY_ARC_START = 0x0a00, /* lv_arc.c */
|
||||
LV_PROPERTY_BAR_START = 0x0b00, /* lv_bar.c */
|
||||
LV_PROPERTY_SWITCH_START = 0x0c00, /* lv_switch.c */
|
||||
LV_PROPERTY_CHECKBOX_START = 0x0d00, /* lv_checkbox.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*/
|
||||
|
||||
@@ -38,6 +38,17 @@ static void lv_checkbox_draw(lv_event_t * e);
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
static const lv_property_ops_t lv_checkbox_properties[] = {
|
||||
{
|
||||
.id = LV_PROPERTY_CHECKBOX_TEXT,
|
||||
.setter = lv_checkbox_set_text,
|
||||
.getter = lv_checkbox_get_text,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
const lv_obj_class_t lv_checkbox_class = {
|
||||
.constructor_cb = lv_checkbox_constructor,
|
||||
.destructor_cb = lv_checkbox_destructor,
|
||||
@@ -48,6 +59,7 @@ const lv_obj_class_t lv_checkbox_class = {
|
||||
.instance_size = sizeof(lv_checkbox_t),
|
||||
.base_class = &lv_obj_class,
|
||||
.name = "lv_checkbox",
|
||||
LV_PROPERTY_CLASS_FIELDS(checkbox, CHECKBOX)
|
||||
};
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -24,6 +24,13 @@ extern "C" {
|
||||
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_checkbox_class;
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
enum _lv_property_checkbox_id_t {
|
||||
LV_PROPERTY_ID(CHECKBOX, TEXT, LV_PROPERTY_TYPE_TEXT, 0),
|
||||
LV_PROPERTY_CHECKBOX_END,
|
||||
};
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
/**
|
||||
* GENERATED FILE, DO NOT EDIT IT!
|
||||
* @file lv_checkbox_properties.c
|
||||
*/
|
||||
|
||||
#include "../checkbox/lv_checkbox.h"
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
|
||||
|
||||
#if LV_USE_CHECKBOX
|
||||
/**
|
||||
* Checkbox widget property names, name must be in order.
|
||||
* Generated code from properties.py
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
const lv_property_name_t lv_checkbox_property_names[1] = {
|
||||
{"text", LV_PROPERTY_CHECKBOX_TEXT,},
|
||||
};
|
||||
#endif /*LV_USE_CHECKBOX*/
|
||||
|
||||
/* *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_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];
|
||||
extern const lv_property_name_t lv_keyboard_property_names[4];
|
||||
|
||||
@@ -135,4 +135,21 @@ void test_checkbox_style_opa(void)
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/checkbox_1.png");
|
||||
}
|
||||
|
||||
void test_checkbox_properties(void)
|
||||
{
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
lv_obj_t * obj = lv_checkbox_create(lv_screen_active());
|
||||
lv_property_t prop = { };
|
||||
|
||||
/* Test TEXT property */
|
||||
prop.id = LV_PROPERTY_CHECKBOX_TEXT;
|
||||
prop.ptr = "Test Checkbox";
|
||||
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||
TEST_ASSERT_EQUAL_STRING("Test Checkbox", lv_obj_get_property(obj, LV_PROPERTY_CHECKBOX_TEXT).ptr);
|
||||
TEST_ASSERT_EQUAL_STRING("Test Checkbox", lv_checkbox_get_text(obj));
|
||||
|
||||
lv_obj_delete(obj);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user