mirror of
https://github.com/lvgl/lvgl.git
synced 2026-02-05 13:30:08 +08:00
feat(textarea): static and non-static setter for accepted_chars
This commit is contained in:
committed by
Liam Howatt
parent
20a1ce71a0
commit
e20517aa70
@@ -143,7 +143,8 @@ Accepted characters
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
You can set a list of accepted characters with
|
You can set a list of accepted characters with
|
||||||
:cpp:expr:`lv_textarea_set_accepted_chars(textarea, list)` where ``list`` is a
|
:cpp:expr:`lv_textarea_set_accepted_chars(textarea, list)` or
|
||||||
|
:cpp:expr:`lv_textarea_set_accepted_chars_static(textarea, list)` where ``list`` is a
|
||||||
pointer to a NUL-terminated string, or NULL to accept all characters. Characters
|
pointer to a NUL-terminated string, or NULL to accept all characters. Characters
|
||||||
entered not in this list will be ignored.
|
entered not in this list will be ignored.
|
||||||
|
|
||||||
|
|||||||
@@ -559,9 +559,29 @@ void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list)
|
|||||||
|
|
||||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||||
|
|
||||||
ta->accepted_chars = list;
|
char * copied_list = NULL;
|
||||||
|
if(list) {
|
||||||
|
copied_list = lv_strdup(list);
|
||||||
|
LV_ASSERT_MALLOC(copied_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ta->static_accepted_chars) lv_free(ta->accepted_chars);
|
||||||
|
ta->static_accepted_chars = 0;
|
||||||
|
ta->accepted_chars = copied_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lv_textarea_set_accepted_chars_static(lv_obj_t * obj, const char * list)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
|
||||||
|
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||||
|
|
||||||
|
if(!ta->static_accepted_chars) lv_free(ta->accepted_chars);
|
||||||
|
ta->static_accepted_chars = 1;
|
||||||
|
ta->accepted_chars = (char *)list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void lv_textarea_set_max_length(lv_obj_t * obj, uint32_t num)
|
void lv_textarea_set_max_length(lv_obj_t * obj, uint32_t num)
|
||||||
{
|
{
|
||||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
@@ -893,6 +913,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
|
|||||||
ta->pwd_bullet = NULL;
|
ta->pwd_bullet = NULL;
|
||||||
ta->pwd_show_time = LV_TEXTAREA_DEF_PWD_SHOW_TIME;
|
ta->pwd_show_time = LV_TEXTAREA_DEF_PWD_SHOW_TIME;
|
||||||
ta->accepted_chars = NULL;
|
ta->accepted_chars = NULL;
|
||||||
|
ta->static_accepted_chars = 1;
|
||||||
ta->max_length = 0;
|
ta->max_length = 0;
|
||||||
ta->cursor.show = 1;
|
ta->cursor.show = 1;
|
||||||
/*It will be set to zero later (with zero value lv_textarea_set_cursor_pos(obj, 0); wouldn't do anything as there is no difference)*/
|
/*It will be set to zero later (with zero value lv_textarea_set_cursor_pos(obj, 0); wouldn't do anything as there is no difference)*/
|
||||||
@@ -938,6 +959,8 @@ static void lv_textarea_destructor(const lv_obj_class_t * class_p, lv_obj_t * ob
|
|||||||
lv_free(ta->placeholder_txt);
|
lv_free(ta->placeholder_txt);
|
||||||
ta->placeholder_txt = NULL;
|
ta->placeholder_txt = NULL;
|
||||||
}
|
}
|
||||||
|
if(!ta->static_accepted_chars) lv_free(ta->accepted_chars);
|
||||||
|
ta->accepted_chars = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||||
|
|||||||
@@ -158,10 +158,17 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en);
|
|||||||
/**
|
/**
|
||||||
* Set a list of characters. Only these characters will be accepted by the text area
|
* Set a list of characters. Only these characters will be accepted by the text area
|
||||||
* @param obj pointer to a text area object
|
* @param obj pointer to a text area object
|
||||||
* @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789"
|
* @param list list of characters. A copy is saved. Example: "+-.,0123456789"
|
||||||
*/
|
*/
|
||||||
void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list);
|
void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a list of characters. Only these characters will be accepted by the text area
|
||||||
|
* @param obj pointer to a text area object
|
||||||
|
* @param list list of characters. Only the pointer is saved. Example: "+-.,0123456789"
|
||||||
|
*/
|
||||||
|
void lv_textarea_set_accepted_chars_static(lv_obj_t * obj, const char * list);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set max length of a Text Area.
|
* Set max length of a Text Area.
|
||||||
* @param obj pointer to a text area object
|
* @param obj pointer to a text area object
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct _lv_textarea_t {
|
|||||||
char * placeholder_txt; /**< Place holder label. only visible if text is an empty string */
|
char * placeholder_txt; /**< Place holder label. only visible if text is an empty string */
|
||||||
char * pwd_tmp; /**< Used to store the original text in password mode */
|
char * pwd_tmp; /**< Used to store the original text in password mode */
|
||||||
char * pwd_bullet; /**< Replacement characters displayed in password mode */
|
char * pwd_bullet; /**< Replacement characters displayed in password mode */
|
||||||
const char * accepted_chars; /**< Only these characters will be accepted. NULL: accept all */
|
char * accepted_chars; /**< Only these characters will be accepted. NULL: accept all */
|
||||||
uint32_t max_length; /**< The max. number of characters. 0: no limit */
|
uint32_t max_length; /**< The max. number of characters. 0: no limit */
|
||||||
uint32_t pwd_show_time; /**< Time to show characters in password mode before change them to '*' */
|
uint32_t pwd_show_time; /**< Time to show characters in password mode before change them to '*' */
|
||||||
struct {
|
struct {
|
||||||
@@ -55,6 +55,7 @@ struct _lv_textarea_t {
|
|||||||
#endif
|
#endif
|
||||||
uint8_t pwd_mode : 1; /**< Replace characters with '*' */
|
uint8_t pwd_mode : 1; /**< Replace characters with '*' */
|
||||||
uint8_t one_line : 1; /**< One line mode (ignore line breaks) */
|
uint8_t one_line : 1; /**< One line mode (ignore line breaks) */
|
||||||
|
uint8_t static_accepted_chars : 1; /**<1: Only a pointer is saved in `accepted_chars` */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user