mirror of
https://github.com/lvgl/lvgl.git
synced 2026-06-01 00:51:49 +08:00
feat(keyboard): add properties
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
committed by
Gabor Kiss-Vamosi
parent
6dc75d4995
commit
cd48c3c8d6
@@ -64,6 +64,7 @@ enum {
|
|||||||
LV_PROPERTY_OBJ_START = 0x0100, /* lv_obj.c */
|
LV_PROPERTY_OBJ_START = 0x0100, /* lv_obj.c */
|
||||||
LV_PROPERTY_IMAGE_START = 0x0200, /* lv_image.c */
|
LV_PROPERTY_IMAGE_START = 0x0200, /* lv_image.c */
|
||||||
LV_PROPERTY_LABEL_START = 0x0300, /* lv_label.c */
|
LV_PROPERTY_LABEL_START = 0x0300, /* lv_label.c */
|
||||||
|
LV_PROPERTY_KEYBOARD_START = 0x0400, /* lv_keyboard.c */
|
||||||
|
|
||||||
/*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/
|
/*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*/
|
LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/
|
||||||
|
|||||||
@@ -37,6 +37,30 @@ static void lv_keyboard_update_ctrl_map(lv_obj_t * obj);
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
static const lv_property_ops_t properties[] = {
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_KEYBOARD_TEXTAREA,
|
||||||
|
.setter = lv_keyboard_set_textarea,
|
||||||
|
.getter = lv_keyboard_get_textarea,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_KEYBOARD_MODE,
|
||||||
|
.setter = lv_keyboard_set_mode,
|
||||||
|
.getter = lv_keyboard_get_mode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_KEYBOARD_POPOVERS,
|
||||||
|
.setter = lv_keyboard_set_popovers,
|
||||||
|
.getter = lv_keyboard_get_popovers,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_KEYBOARD_SELECTED_BUTTON,
|
||||||
|
.setter = lv_buttonmatrix_set_selected_button,
|
||||||
|
.getter = lv_keyboard_get_selected_button,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
const lv_obj_class_t lv_keyboard_class = {
|
const lv_obj_class_t lv_keyboard_class = {
|
||||||
.constructor_cb = lv_keyboard_constructor,
|
.constructor_cb = lv_keyboard_constructor,
|
||||||
@@ -46,6 +70,18 @@ const lv_obj_class_t lv_keyboard_class = {
|
|||||||
.editable = 1,
|
.editable = 1,
|
||||||
.base_class = &lv_buttonmatrix_class,
|
.base_class = &lv_buttonmatrix_class,
|
||||||
.name = "keyboard",
|
.name = "keyboard",
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
.prop_index_start = LV_PROPERTY_KEYBOARD_START,
|
||||||
|
.prop_index_end = LV_PROPERTY_KEYBOARD_END,
|
||||||
|
.properties = properties,
|
||||||
|
.properties_count = sizeof(properties) / sizeof(properties[0]),
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY_NAME
|
||||||
|
.property_names = lv_keyboard_property_names,
|
||||||
|
.names_count = sizeof(lv_keyboard_property_names) / sizeof(lv_property_name_t),
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const default_kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n",
|
static const char * const default_kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n",
|
||||||
@@ -260,7 +296,7 @@ lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * obj)
|
|||||||
return keyboard->mode;
|
return keyboard->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lv_buttonmatrix_get_popovers(const lv_obj_t * obj)
|
bool lv_keyboard_get_popovers(const lv_obj_t * obj)
|
||||||
{
|
{
|
||||||
lv_keyboard_t * keyboard = (lv_keyboard_t *)obj;
|
lv_keyboard_t * keyboard = (lv_keyboard_t *)obj;
|
||||||
return keyboard->popovers;
|
return keyboard->popovers;
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ typedef enum {
|
|||||||
#endif
|
#endif
|
||||||
} lv_keyboard_mode_t;
|
} lv_keyboard_mode_t;
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
enum {
|
||||||
|
LV_PROPERTY_ID(KEYBOARD, TEXTAREA, LV_PROPERTY_TYPE_OBJ, 0),
|
||||||
|
LV_PROPERTY_ID(KEYBOARD, MODE, LV_PROPERTY_TYPE_INT, 1),
|
||||||
|
LV_PROPERTY_ID(KEYBOARD, POPOVERS, LV_PROPERTY_TYPE_INT, 2),
|
||||||
|
LV_PROPERTY_ID(KEYBOARD, SELECTED_BUTTON, LV_PROPERTY_TYPE_INT, 3),
|
||||||
|
LV_PROPERTY_KEYBOARD_END,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_keyboard_class;
|
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_keyboard_class;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@@ -123,7 +133,7 @@ lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * kb);
|
|||||||
* @param obj pointer to a Keyboard object
|
* @param obj pointer to a Keyboard object
|
||||||
* @return true: "popovers" mode is enabled; false: disabled
|
* @return true: "popovers" mode is enabled; false: disabled
|
||||||
*/
|
*/
|
||||||
bool lv_buttonmatrix_get_popovers(const lv_obj_t * obj);
|
bool lv_keyboard_get_popovers(const lv_obj_t * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current map of a keyboard
|
* Get the current map of a keyboard
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* GENERATED FILE, DO NOT EDIT IT!
|
||||||
|
* @file lv_keyboard_properties.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../keyboard/lv_keyboard.h"
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
|
||||||
|
|
||||||
|
#if LV_USE_KEYBOARD
|
||||||
|
/**
|
||||||
|
* Keyboard widget property names, name must be in order.
|
||||||
|
* Generated code from properties.py
|
||||||
|
*/
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
const lv_property_name_t lv_keyboard_property_names[4] = {
|
||||||
|
{"mode", LV_PROPERTY_KEYBOARD_MODE,},
|
||||||
|
{"popovers", LV_PROPERTY_KEYBOARD_POPOVERS,},
|
||||||
|
{"selected_button", LV_PROPERTY_KEYBOARD_SELECTED_BUTTON,},
|
||||||
|
{"textarea", LV_PROPERTY_KEYBOARD_TEXTAREA,},
|
||||||
|
};
|
||||||
|
#endif /*LV_USE_KEYBOARD*/
|
||||||
|
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
#endif
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
|
#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_image_property_names[11];
|
||||||
|
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_label_property_names[4];
|
||||||
extern const lv_property_name_t lv_obj_property_names[73];
|
extern const lv_property_name_t lv_obj_property_names[73];
|
||||||
extern const lv_property_name_t lv_style_property_names[112];
|
extern const lv_property_name_t lv_style_property_names[112];
|
||||||
|
|||||||
@@ -39,4 +39,38 @@ void test_keyboard_mode(void)
|
|||||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/keyboard_4.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/keyboard_4.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_keyboard_properties(void)
|
||||||
|
{
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
lv_obj_t * obj = lv_keyboard_create(lv_screen_active());
|
||||||
|
lv_property_t prop = { };
|
||||||
|
|
||||||
|
lv_obj_t * test_area = lv_textarea_create(lv_screen_active());
|
||||||
|
|
||||||
|
prop.id = LV_PROPERTY_KEYBOARD_TEXTAREA;
|
||||||
|
prop.ptr = test_area;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_PTR(test_area, lv_keyboard_get_textarea(obj));
|
||||||
|
TEST_ASSERT_EQUAL_PTR(test_area, lv_obj_get_property(obj, LV_PROPERTY_KEYBOARD_TEXTAREA).ptr);
|
||||||
|
|
||||||
|
prop.id = LV_PROPERTY_KEYBOARD_MODE;
|
||||||
|
prop.num = LV_KEYBOARD_MODE_TEXT_UPPER;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_KEYBOARD_MODE_TEXT_UPPER, lv_keyboard_get_mode(obj));
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_KEYBOARD_MODE_TEXT_UPPER, lv_obj_get_property(obj, LV_PROPERTY_KEYBOARD_MODE).num);
|
||||||
|
|
||||||
|
prop.id = LV_PROPERTY_KEYBOARD_POPOVERS;
|
||||||
|
prop.num = 1;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, lv_keyboard_get_popovers(obj));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(obj, LV_PROPERTY_KEYBOARD_POPOVERS).num);
|
||||||
|
|
||||||
|
prop.id = LV_PROPERTY_KEYBOARD_SELECTED_BUTTON;
|
||||||
|
prop.num = 1;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, lv_keyboard_get_selected_button(obj));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(obj, LV_PROPERTY_KEYBOARD_SELECTED_BUTTON).num);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user