mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 11:07:34 +08:00
fix(textarea): update password bullets immediately on set (#5943)
This commit is contained in:
@@ -59,6 +59,7 @@ static lv_result_t insert_handler(lv_obj_t * obj, const char * txt);
|
||||
static void draw_placeholder(lv_event_t * e);
|
||||
static void draw_cursor(lv_event_t * e);
|
||||
static void auto_hide_characters(lv_obj_t * obj);
|
||||
static void auto_hide_characters_cancel(lv_obj_t * obj);
|
||||
static inline bool is_valid_but_non_printable_char(const uint32_t letter);
|
||||
|
||||
/**********************
|
||||
@@ -312,12 +313,12 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt)
|
||||
}
|
||||
|
||||
if(ta->pwd_mode) {
|
||||
lv_free(ta->pwd_tmp);
|
||||
ta->pwd_tmp = lv_strdup(txt);
|
||||
LV_ASSERT_MALLOC(ta->pwd_tmp);
|
||||
if(ta->pwd_tmp == NULL) return;
|
||||
|
||||
/*Auto hide characters*/
|
||||
auto_hide_characters(obj);
|
||||
pwd_char_hider(obj);
|
||||
}
|
||||
|
||||
lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
@@ -423,6 +424,7 @@ void lv_textarea_set_password_mode(lv_obj_t * obj, bool en)
|
||||
/*Pwd mode is now enabled*/
|
||||
if(en) {
|
||||
char * txt = lv_label_get_text(ta->label);
|
||||
lv_free(ta->pwd_tmp);
|
||||
ta->pwd_tmp = lv_strdup(txt);
|
||||
LV_ASSERT_MALLOC(ta->pwd_tmp);
|
||||
if(ta->pwd_tmp == NULL) return;
|
||||
@@ -469,7 +471,7 @@ void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet)
|
||||
ta->pwd_bullet[txt_len] = '\0';
|
||||
}
|
||||
|
||||
lv_obj_invalidate(obj);
|
||||
pwd_char_hider(obj);
|
||||
}
|
||||
|
||||
void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
|
||||
@@ -544,6 +546,7 @@ void lv_textarea_set_password_show_time(lv_obj_t * obj, uint32_t time)
|
||||
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
ta->pwd_show_time = time;
|
||||
pwd_char_hider(obj);
|
||||
}
|
||||
|
||||
void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align)
|
||||
@@ -1016,6 +1019,8 @@ static void pwd_char_hider(lv_obj_t * obj)
|
||||
lv_label_set_text(ta->label, txt_tmp);
|
||||
lv_free(txt_tmp);
|
||||
|
||||
auto_hide_characters_cancel(obj);
|
||||
|
||||
refr_cursor_area(obj);
|
||||
}
|
||||
|
||||
@@ -1380,6 +1385,11 @@ static void auto_hide_characters(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
static void auto_hide_characters_cancel(lv_obj_t * obj)
|
||||
{
|
||||
lv_anim_delete(obj, pwd_char_hider_anim);
|
||||
}
|
||||
|
||||
static inline bool is_valid_but_non_printable_char(const uint32_t letter)
|
||||
{
|
||||
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
||||
|
||||
@@ -16,7 +16,7 @@ void setUp(void)
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Function run after every test */
|
||||
lv_obj_clean(active_screen);
|
||||
}
|
||||
|
||||
void test_textarea_should_have_valid_documented_default_values(void)
|
||||
@@ -104,4 +104,33 @@ void test_textarea_in_one_line_mode_should_ignore_line_break_characters(void)
|
||||
TEST_ASSERT_EQUAL_STRING(textarea_default_text, lv_textarea_get_text(textarea));
|
||||
}
|
||||
|
||||
void test_textarea_should_hide_password_characters(void)
|
||||
{
|
||||
lv_textarea_set_password_mode(textarea, true);
|
||||
lv_textarea_set_text(textarea, "12345");
|
||||
|
||||
/* setting bullet hides characters */
|
||||
lv_textarea_set_password_bullet(textarea, "O");
|
||||
TEST_ASSERT_EQUAL_STRING("OOOOO", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
|
||||
/* setting text hides characters */
|
||||
lv_textarea_set_text(textarea, "A");
|
||||
TEST_ASSERT_EQUAL_STRING("O", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
|
||||
lv_textarea_add_char(textarea, 'B');
|
||||
TEST_ASSERT_EQUAL_STRING("OB", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
|
||||
/* setting show time hides characters */
|
||||
/* current behavior is to hide the characters upon setting the show time regardless of the value */
|
||||
lv_textarea_set_password_show_time(textarea, lv_textarea_get_password_show_time(textarea));
|
||||
TEST_ASSERT_EQUAL_STRING("OO", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
|
||||
lv_textarea_set_password_mode(textarea, false);
|
||||
TEST_ASSERT_EQUAL_STRING("AB", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
|
||||
/* enabling password mode hides characters */
|
||||
lv_textarea_set_password_mode(textarea, true);
|
||||
TEST_ASSERT_EQUAL_STRING("OO", lv_label_get_text(lv_textarea_get_label(textarea)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user