mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-27 03:33:48 +08:00
lv_ta: pwd_mode added, lv_label:pwd_mode deleted
This commit is contained in:
parent
119c4b577b
commit
168bda2b8f
@ -123,7 +123,8 @@
|
||||
#define USE_LV_TA 1
|
||||
#if USE_LV_TA != 0
|
||||
#define LV_TA_MAX_LENGTH 256
|
||||
#define LV_TA_CUR_BLINK_TIME 400 /*ms*/
|
||||
#define LV_TA_CUR_BLINK_TIME 400 /*ms*/
|
||||
#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
|
||||
#endif
|
||||
|
||||
/*************************
|
||||
|
@ -313,18 +313,13 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_
|
||||
}
|
||||
}
|
||||
|
||||
char letter = txt[i];
|
||||
color_t color = style->ccolor;
|
||||
|
||||
if((flag & TXT_FLAG_PWD) != 0 && txt[i + 1] != '\0') letter = '*';
|
||||
if(cmd_state == CMD_STATE_IN) color = recolor;
|
||||
letter_fp(&pos, mask_p, font, letter, color, style->opa);
|
||||
letter_fp(&pos, mask_p, font, txt[i], color, style->opa);
|
||||
|
||||
pos.x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
|
||||
if((flag & TXT_FLAG_PWD) == 0 || txt[i + 1] == '\0') {
|
||||
pos.x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
} else {
|
||||
pos.x += (font_get_width(font, '*') >> FONT_ANTIALIAS) + style->letter_space;
|
||||
}
|
||||
}
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
|
@ -83,7 +83,6 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->txt = NULL;
|
||||
ext->static_txt = 0;
|
||||
ext->recolor = 0;
|
||||
ext->pwd = 0;
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
ext->long_mode = LV_LABEL_LONG_EXPAND;
|
||||
ext->offset.x = 0;
|
||||
@ -308,20 +307,6 @@ void lv_label_set_recolor(lv_obj_t * label, bool recolor)
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the password mode
|
||||
* @param label pointer to a label object
|
||||
* @param pwd true: enable password mode, false: disable
|
||||
*/
|
||||
void lv_label_set_pwd_mode(lv_obj_t * label, bool pwd)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
|
||||
ext->pwd = pwd == false ? 0 : 1;
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -331,7 +316,7 @@ void lv_label_set_pwd_mode(lv_obj_t * label, bool pwd)
|
||||
* @param label pointer to a label object
|
||||
* @return the text of the label
|
||||
*/
|
||||
const char * lv_label_get_text(lv_obj_t * label)
|
||||
char * lv_label_get_text(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
|
||||
@ -360,17 +345,6 @@ bool lv_label_get_recolor(lv_obj_t * label)
|
||||
return ext->recolor == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password mode
|
||||
* @param label pointer to a label object
|
||||
* @return true: password mode is enabled, false: disable
|
||||
*/
|
||||
bool lv_label_get_pwd_mode(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
return ext->pwd == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relative x and y coordinates of a letter
|
||||
* @param label pointer to a label object
|
||||
@ -391,7 +365,6 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
|
||||
txt_flag_t flag = TXT_FLAG_NONE;
|
||||
|
||||
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
|
||||
if(ext->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
/*If the width will be expanded the set the max length to very big */
|
||||
@ -424,8 +397,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
|
||||
continue; /*Skip the letter is it is part of a command*/
|
||||
}
|
||||
}
|
||||
if((flag & TXT_FLAG_PWD) == 0 || txt[i + 1] == '\0') x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
else x += (font_get_width(font, '*') >> FONT_ANTIALIAS) + style->letter_space;
|
||||
x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
|
||||
}
|
||||
|
||||
if(style->txt_align == LV_TXT_ALIGN_MID) {
|
||||
@ -460,7 +433,6 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
|
||||
txt_flag_t flag = TXT_FLAG_NONE;
|
||||
|
||||
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
|
||||
if(ext->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
/*If the width will be expanded set the max length to very big */
|
||||
@ -495,8 +467,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
|
||||
}
|
||||
}
|
||||
|
||||
if((flag & TXT_FLAG_PWD) == 0 || txt[i + 1] == '\0') x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
else x += (font_get_width(font, '*') >> FONT_ANTIALIAS) + style->letter_space;
|
||||
x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
|
||||
if(pos->x < x) break;
|
||||
}
|
||||
@ -533,7 +504,6 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
txt_flag_t flag = TXT_FLAG_NONE;
|
||||
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
|
||||
if(ext->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
if(strcmp("Folder1", ext->txt) == 0) {
|
||||
@ -575,7 +545,6 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
point_t size;
|
||||
txt_flag_t flag = TXT_FLAG_NONE;
|
||||
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
|
||||
if(ext->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
txt_get_size(&size, ext->txt, font, style->letter_space, style->line_space, max_w, flag);
|
||||
|
||||
|
@ -47,7 +47,6 @@ typedef struct
|
||||
point_t offset;
|
||||
uint8_t static_txt :1; /*Flag to indicate the text is static*/
|
||||
uint8_t recolor :1; /*Enable in-line letter re-coloring*/
|
||||
uint8_t pwd :1; /*Convert letters to '*' when draw*/
|
||||
uint8_t expand :1; /*Force expand size when solving line length (used by the library with LV_LABEL_LONG_ROLL)*/
|
||||
}lv_label_ext_t;
|
||||
|
||||
@ -128,7 +127,7 @@ void lv_label_set_pwd_mode(lv_obj_t * label, bool pwd);
|
||||
* @param label pointer to a label object
|
||||
* @return the text of the label
|
||||
*/
|
||||
const char * lv_label_get_text(lv_obj_t * label);
|
||||
char * lv_label_get_text(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the long mode of a label
|
||||
|
170
lv_objx/lv_ta.c
170
lv_objx/lv_ta.c
@ -26,6 +26,10 @@
|
||||
#define LV_TA_CUR_BLINK_TIME 400 /*ms*/
|
||||
#endif
|
||||
|
||||
#ifndef LV_TA_PWD_SHOW_TIME
|
||||
#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
|
||||
#endif
|
||||
|
||||
#define LV_TA_DEF_WIDTH (2 * LV_DPI)
|
||||
#define LV_TA_DEF_HEIGHT (1 * LV_DPI)
|
||||
|
||||
@ -38,7 +42,9 @@
|
||||
**********************/
|
||||
static bool lv_ta_design(lv_obj_t * ta, const area_t * mask, lv_design_mode_t mode);
|
||||
static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_ta_hide_cursor_anim(lv_obj_t * ta, uint8_t hide);
|
||||
static void cursor_blink_anim(lv_obj_t * ta, uint8_t hide);
|
||||
static void pwd_char_hider_anim(lv_obj_t * ta, uint8_t x);
|
||||
static void pwd_char_hider(lv_obj_t * ta);
|
||||
static void lv_ta_save_valid_cursor_x(lv_obj_t * ta);
|
||||
|
||||
/**********************
|
||||
@ -76,6 +82,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
dm_assert(ext);
|
||||
ext->cursor_show = 1;
|
||||
ext->cursor_state = 0;
|
||||
ext->pwd_mode = 0;
|
||||
ext->pwd_tmp = NULL;
|
||||
ext->cursor_pos = 0;
|
||||
ext->cursor_valid_x = 0;
|
||||
ext->label = NULL;
|
||||
@ -115,7 +123,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Create a cursor blinker animation*/
|
||||
anim_t a;
|
||||
a.var = new_ta;
|
||||
a.fp = (anim_fp_t)lv_ta_hide_cursor_anim;
|
||||
a.fp = (anim_fp_t)cursor_blink_anim;
|
||||
a.time = LV_TA_CUR_BLINK_TIME;
|
||||
a.act_time = 0;
|
||||
a.end_cb = NULL;
|
||||
@ -196,6 +204,9 @@ void lv_ta_add_char(lv_obj_t * ta, char c)
|
||||
|
||||
/*Test the new length: txt length + 1 (closing'\0') + 1 (c character)*/
|
||||
if((strlen(label_txt) + 2) > LV_TA_MAX_LENGTH) return;
|
||||
|
||||
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
||||
|
||||
char buf[LV_TA_MAX_LENGTH];
|
||||
|
||||
/*Insert the character*/
|
||||
@ -211,6 +222,24 @@ void lv_ta_add_char(lv_obj_t * ta, char c)
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
|
||||
if(ext->pwd_mode != 0) {
|
||||
anim_t a;
|
||||
a.var = ta;
|
||||
a.fp = (anim_fp_t)pwd_char_hider_anim;
|
||||
a.time = LV_TA_PWD_SHOW_TIME;
|
||||
a.act_time = 0;
|
||||
a.end_cb = (anim_cb_t)pwd_char_hider;
|
||||
a.start = 0;
|
||||
a.end = 1;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.path = anim_get_path(ANIM_PATH_STEP);
|
||||
anim_create(&a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,6 +258,8 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
/*Test the new length (+ 1 for the closing '\0')*/
|
||||
if((label_len + txt_len + 1) > LV_TA_MAX_LENGTH) return;
|
||||
|
||||
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
||||
|
||||
/*Insert the text*/
|
||||
char buf[LV_TA_MAX_LENGTH];
|
||||
|
||||
@ -244,6 +275,23 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
|
||||
if(ext->pwd_mode != 0) {
|
||||
anim_t a;
|
||||
a.var = ta;
|
||||
a.fp = (anim_fp_t)pwd_char_hider_anim;
|
||||
a.time = LV_TA_PWD_SHOW_TIME;
|
||||
a.act_time = 0;
|
||||
a.end_cb = (anim_cb_t)pwd_char_hider;
|
||||
a.start = 0;
|
||||
a.end = 1;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.path = anim_get_path(ANIM_PATH_STEP);
|
||||
anim_create(&a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,6 +307,23 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt)
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
|
||||
if(ext->pwd_mode != 0) {
|
||||
anim_t a;
|
||||
a.var = ta;
|
||||
a.fp = (anim_fp_t)pwd_char_hider_anim;
|
||||
a.time = LV_TA_PWD_SHOW_TIME;
|
||||
a.act_time = 0;
|
||||
a.end_cb = (anim_cb_t)pwd_char_hider;
|
||||
a.start = 0;
|
||||
a.end = 1;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.path = anim_get_path(ANIM_PATH_STEP);
|
||||
anim_create(&a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,7 +484,7 @@ void lv_ta_cursor_up(lv_obj_t * ta)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current cursor visibility.
|
||||
* Set the cursor visibility.
|
||||
* @param ta pointer to a text area object
|
||||
* @return show true: show the cursor and blink it, false: hide cursor
|
||||
*/
|
||||
@ -429,6 +494,38 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show)
|
||||
ext->cursor_show = show == false ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable password mode
|
||||
* @param ta ointer to a text area object
|
||||
* @param en true: enable, false: disable
|
||||
*/
|
||||
void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
|
||||
/*Pwd mode is now enabled*/
|
||||
if(ext->pwd_mode == 0 && en != false) {
|
||||
char * txt = lv_label_get_text(ext->label);
|
||||
uint16_t txt_len = strlen(txt);
|
||||
ext->pwd_tmp = dm_alloc(txt_len + 1);
|
||||
strcpy(ext->pwd_tmp, txt);
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < txt_len; i++) {
|
||||
txt[i] = '*'; /*All char to '*'*/
|
||||
}
|
||||
|
||||
lv_label_set_text(ext->label, NULL);
|
||||
}
|
||||
/*Pwd mode is now disabled*/
|
||||
else if(ext->pwd_mode == 1 && en == false) {
|
||||
lv_label_set_text(ext->label, ext->pwd_tmp);
|
||||
dm_free(ext->pwd_tmp);
|
||||
ext->pwd_tmp = NULL;
|
||||
}
|
||||
|
||||
ext->pwd_mode = en == false ? 0 : 1;
|
||||
}
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -441,7 +538,15 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show)
|
||||
const char * lv_ta_get_txt(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
return lv_label_get_text(ext->label);
|
||||
|
||||
const char * txt;
|
||||
if(ext->pwd_mode == 0) {
|
||||
txt = lv_label_get_text(ext->label);
|
||||
} else {
|
||||
txt = ext->pwd_tmp;
|
||||
}
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
|
||||
@ -479,6 +584,17 @@ bool lv_ta_get_cursor_show(lv_obj_t * ta)
|
||||
return ext->cursor_show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password mode
|
||||
* @param ta pointer to a text area object
|
||||
* @return true: password mode is enabled, false: disabled
|
||||
*/
|
||||
bool lv_ta_get_pwd_mode(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
return ext->pwd_mode;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -565,15 +681,51 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
|
||||
* @param ta pointer to a text area
|
||||
* @param hide 1: hide the cursor, 0: show it
|
||||
*/
|
||||
static void lv_ta_hide_cursor_anim(lv_obj_t * ta, uint8_t hide)
|
||||
static void cursor_blink_anim(lv_obj_t * ta, uint8_t hide)
|
||||
{
|
||||
lv_ta_ext_t * ta_ext = lv_obj_get_ext(ta);
|
||||
if(hide != ta_ext->cursor_state) {
|
||||
ta_ext->cursor_state = hide == 0 ? 0 : 1;
|
||||
if(ta_ext->cursor_show != 0) lv_obj_inv(ta);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
if(hide != ext->cursor_state) {
|
||||
ext->cursor_state = hide == 0 ? 0 : 1;
|
||||
if(ext->cursor_show != 0) lv_obj_inv(ta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dummy function to animate char hiding in pwd mode.
|
||||
* Does nothing, nut a function is required in car hiding anim.
|
||||
* (pwd_char_hider callback do the real job)
|
||||
* @param ta unused
|
||||
* @param x unused
|
||||
*/
|
||||
static void pwd_char_hider_anim(lv_obj_t * ta, uint8_t x)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all characters (convert them to '*')
|
||||
* @param ta: pointer to text area object
|
||||
*/
|
||||
static void pwd_char_hider(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
if(ext->pwd_mode != 0) {
|
||||
char * txt = lv_label_get_text(ext->label);
|
||||
int16_t txt_len = strlen(txt);
|
||||
bool refr = false;
|
||||
uint16_t i;
|
||||
for(i = 0; i < txt_len; i++) {
|
||||
if(txt[i] != '*') {
|
||||
txt[i] = '*';
|
||||
refr = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(refr != false) lv_label_set_text(ext->label, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the cursor x position as valid. It is important when jumping up/down to a shorter line
|
||||
* @param ta pointer to a text area object
|
||||
|
@ -40,9 +40,11 @@ typedef struct
|
||||
lv_page_ext_t page; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_obj_t * label; /*Label of the text area*/
|
||||
char * pwd_tmp; /*Used to store the original text in password mode*/
|
||||
cord_t cursor_valid_x; /*Used when stepping up/down in text area when stepping to a shorter line. (Handled by the library)*/
|
||||
uint16_t cursor_pos; /*The current cursor position (0: before 1. letter; 1: before 2. letter etc.)*/
|
||||
uint8_t cursor_show :1; /*Show or hide cursor */
|
||||
uint8_t pwd_mode :1; /*Replace characters with '*' */
|
||||
uint8_t cursor_state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/
|
||||
}lv_ta_ext_t;
|
||||
|
||||
@ -134,6 +136,13 @@ void lv_ta_cursor_up(lv_obj_t * ta);
|
||||
*/
|
||||
void lv_ta_set_cursor_show(lv_obj_t * ta, bool show);
|
||||
|
||||
/**
|
||||
* Enable/Disable password mode
|
||||
* @param ta ointer to a text area object
|
||||
* @param en true: enable, false: disable
|
||||
*/
|
||||
void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en);
|
||||
|
||||
/**
|
||||
* Get the text of the i the text area
|
||||
* @param ta obj pointer to a text area object
|
||||
@ -162,7 +171,12 @@ uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta);
|
||||
*/
|
||||
bool lv_ta_get_cursor_show(lv_obj_t * ta);
|
||||
|
||||
|
||||
/**
|
||||
* Get the password mode
|
||||
* @param ta pointer to a text area object
|
||||
* @return true: password mode is enabled, false: disabled
|
||||
*/
|
||||
bool lv_ta_get_pwd_mode(lv_obj_t * ta);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
Loading…
Reference in New Issue
Block a user