LV_COLOR_TRANSP, LV_TA_CURSOR_BLINK_TIME and LV_TA_PWD_SHOW_TIME run time configurable

This commit is contained in:
Gabor Kiss-Vamosi 2019-05-25 16:27:36 +02:00
parent 6bde219324
commit b0fffaa55b
7 changed files with 207 additions and 86 deletions

View File

@ -424,8 +424,8 @@ typedef void * lv_obj_user_data_t;
/*Text area (dependencies: lv_label, lv_page)*/
#define LV_USE_TA 1
#if LV_USE_TA != 0
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Table (dependencies: lv_label)*/

View File

@ -204,6 +204,8 @@
#define LV_IMG_CF_ALPHA 1
#endif
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
/*1: Add a `user_data` to drivers and objects*/
#ifndef LV_USE_USER_DATA
#define LV_USE_USER_DATA 1
@ -229,7 +231,6 @@
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
/* 1: Variable length array is supported*/
#ifndef LV_COMPILER_VLA_SUPPORTED
#define LV_COMPILER_VLA_SUPPORTED 1
@ -652,11 +653,11 @@
#define LV_USE_TA 1
#endif
#if LV_USE_TA != 0
#ifndef LV_TA_CURSOR_BLINK_TIME
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
#ifndef LV_TA_DEF_CURSOR_BLINK_TIME
# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
#endif
#ifndef LV_TA_PWD_SHOW_TIME
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#ifndef LV_TA_DEF_PWD_SHOW_TIME
# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
#endif

View File

@ -462,7 +462,6 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, const uint
/*In the other cases every pixel need to be checked one-by-one*/
else {
lv_color_t chroma_key_color = LV_COLOR_TRANSP;
lv_coord_t col;
lv_color_t last_img_px = LV_COLOR_BLACK;
lv_color_t recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa);
@ -493,7 +492,7 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, const uint
}
/*Handle chroma key*/
if(chroma_key && px_color.full == chroma_key_color.full) continue;
if(chroma_key && px_color.full == disp->driver.color_chroma_key.full) continue;
/*Re-color the pixel if required*/
if(recolor_opa != LV_OPA_TRANSP) {

View File

@ -61,6 +61,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver)
driver->ver_res = LV_VER_RES_MAX;
driver->buffer = NULL;
driver->rotated = 0;
driver->color_chroma_key = LV_COLOR_TRANSP;
#if LV_ANTIALIAS
driver->antialiasing = true;
@ -71,6 +72,10 @@ void lv_disp_drv_init(lv_disp_drv_t * driver)
driver->mem_fill_cb = NULL;
#endif
#if LV_USE_USER_DATA
driver->user_data = NULL;
#endif
driver->set_px_cb = NULL;
}

View File

@ -99,6 +99,10 @@ typedef struct _disp_drv_t
const lv_area_t * fill_area, lv_color_t color);
#endif
/*On CHROMA_KEYED images this color will be transparent.
* `LV_COLOR_TRANSP` by default. (lv_conf.h)*/
lv_color_t color_chroma_key;
#if LV_USE_USER_DATA
lv_disp_drv_user_data_t user_data;
#endif

View File

@ -22,12 +22,12 @@
*********************/
/*Test configuration*/
#ifndef LV_TA_CURSOR_BLINK_TIME
#define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
#ifndef LV_TA_DEF_CURSOR_BLINK_TIME
#define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
#endif
#ifndef LV_TA_PWD_SHOW_TIME
#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#ifndef LV_TA_DEF_PWD_SHOW_TIME
#define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
#define LV_TA_DEF_WIDTH (2 * LV_DPI)
@ -102,9 +102,11 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy)
ext->cursor.state = 1;
ext->pwd_mode = 0;
ext->pwd_tmp = NULL;
ext->pwd_show_time = LV_TA_DEF_PWD_SHOW_TIME;
ext->accapted_chars = NULL;
ext->max_length = 0;
ext->cursor.style = NULL;
ext->cursor.blink_time = LV_TA_DEF_CURSOR_BLINK_TIME;
ext->cursor.pos = 0;
ext->cursor.type = LV_CURSOR_LINE;
ext->cursor.valid_x = 0;
@ -113,6 +115,11 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy)
ext->label = NULL;
ext->placeholder = NULL;
#if LV_USE_ANIMATION
ext->pwd_show_time = 0;
ext->cursor.blink_time = 0;
#endif
lv_obj_set_signal_cb(new_ta, lv_ta_signal);
lv_obj_set_signal_cb(lv_page_get_scrl(new_ta), lv_ta_scrollable_signal);
lv_obj_set_design_cb(new_ta, lv_ta_design);
@ -162,21 +169,23 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy)
}
#if LV_USE_ANIMATION
/*Create a cursor blinker animation*/
lv_anim_t a;
a.var = new_ta;
a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim;
a.time = LV_TA_CURSOR_BLINK_TIME;
a.act_time = 0;
a.ready_cb = NULL;
a.start = 1;
a.end = 0;
a.repeat = 1;
a.repeat_pause = 0;
a.playback = 1;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
if(ext->cursor.blink_time) {
/*Create a cursor blinker animation*/
lv_anim_t a;
a.var = new_ta;
a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim;
a.time = ext->cursor.blink_time;
a.act_time = 0;
a.ready_cb = NULL;
a.start = 1;
a.end = 0;
a.repeat = 1;
a.repeat_pause = 0;
a.playback = 1;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
}
#endif
LV_LOG_INFO("text area created");
@ -246,12 +255,12 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c)
lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, (const char *)letter_buf);
#if LV_USE_ANIMATION && LV_TA_PWD_SHOW_TIME > 0
#if LV_USE_ANIMATION
/*Auto hide characters*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim;
a.time = LV_TA_PWD_SHOW_TIME;
a.time = ext->pwd_show_time;
a.act_time = 0;
a.ready_cb = pwd_char_hider_anim_ready;
a.start = 0;
@ -262,6 +271,7 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c)
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
#else
pwd_char_hider(ta);
#endif
@ -326,22 +336,22 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, txt);
#if LV_USE_ANIMATION && LV_TA_PWD_SHOW_TIME > 0
/*Auto hide characters*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim;
a.time = LV_TA_PWD_SHOW_TIME;
a.act_time = 0;
a.ready_cb = pwd_char_hider_anim_ready;
a.start = 0;
a.end = 1;
a.repeat = 0;
a.repeat_pause = 0;
a.playback = 0;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
#if LV_USE_ANIMATION
/*Auto hide characters*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim;
a.time = ext->pwd_show_time;
a.act_time = 0;
a.ready_cb = pwd_char_hider_anim_ready;
a.start = 0;
a.end = 1;
a.repeat = 0;
a.repeat_pause = 0;
a.playback = 0;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
#else
pwd_char_hider(ta);
#endif
@ -466,22 +476,22 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt)
if(ext->pwd_tmp == NULL) return;
strcpy(ext->pwd_tmp, txt);
#if LV_USE_ANIMATION && LV_TA_PWD_SHOW_TIME > 0
/*Auto hide characters*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim;
a.time = LV_TA_PWD_SHOW_TIME;
a.act_time = 0;
a.ready_cb = pwd_char_hider_anim_ready;
a.start = 0;
a.end = 1;
a.repeat = 0;
a.repeat_pause = 0;
a.playback = 0;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
#if LV_USE_ANIMATION
/*Auto hide characters*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim;
a.time = ext->pwd_show_time;
a.act_time = 0;
a.ready_cb = pwd_char_hider_anim_ready;
a.start = 0;
a.end = 1;
a.repeat = 0;
a.repeat_pause = 0;
a.playback = 0;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
#else
pwd_char_hider(ta);
#endif
@ -573,21 +583,23 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
ext->cursor.valid_x = cur_pos.x;
#if LV_USE_ANIMATION
/*Reset cursor blink animation*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim;
a.time = LV_TA_CURSOR_BLINK_TIME;
a.act_time = 0;
a.ready_cb = NULL;
a.start = 1;
a.end = 0;
a.repeat = 1;
a.repeat_pause = 0;
a.playback = 1;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
if(ext->cursor.blink_time) {
/*Reset cursor blink animation*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim;
a.time = ext->cursor.blink_time;
a.act_time = 0;
a.ready_cb = NULL;
a.start = 1;
a.end = 0;
a.repeat = 1;
a.repeat_pause = 0;
a.playback = 1;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
}
#endif
refr_cursor_area(ta);
@ -809,6 +821,60 @@ void lv_ta_set_text_sel(lv_obj_t * ta, bool en)
#endif
}
/**
* Set how long show the password before changing it to '*'
* @param ta pointer to Text area
* @param time show time in milliseconds. 0: hide immediately.
*/
void lv_ta_set_pwd_show_time(lv_obj_t * ta, uint16_t time)
{
#if LV_USE_ANIMATION == 0
time = 0;
#endif
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
ext->pwd_show_time = time;
}
/**
* Set cursor blink animation time
* @param ta pointer to Text area
* @param time blink period. 0: disable blinking
*/
void lv_ta_set_cursor_blink_time(lv_obj_t * ta, uint16_t time)
{
#if LV_USE_ANIMATION == 0
time = 0;
#endif
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
ext->cursor.blink_time = time;
#if LV_USE_ANIMATION
if(ext->cursor.blink_time) {
/*Reset cursor blink animation*/
lv_anim_t a;
a.var = ta;
a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim;
a.time = ext->cursor.blink_time;
a.act_time = 0;
a.ready_cb = NULL;
a.start = 1;
a.end = 0;
a.repeat = 1;
a.repeat_pause = 0;
a.playback = 1;
a.playback_pause = 0;
a.path_cb = lv_anim_path_step;
lv_anim_create(&a);
} else {
ext->cursor.state = 1;
}
#else
ext->cursor.state = 1;
#endif
}
/*=====================
* Getter functions
*====================*/
@ -989,6 +1055,29 @@ bool lv_ta_get_text_sel_en(lv_obj_t * ta)
#endif
}
/**
* Set how long show the password before changing it to '*'
* @param ta pointer to Text area
* @return show time in milliseconds. 0: hide immediately.
*/
uint16_t lv_ta_get_pwd_show_time(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
return ext->pwd_show_time;
}
/**
* Set cursor blink animation time
* @param ta pointer to Text area
* @return time blink period. 0: disable blinking
*/
uint16_t lv_ta_get_cursor_blink_time(lv_obj_t * ta)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
return ext->cursor.blink_time;
}
/*=====================
* Other functions
*====================*/

View File

@ -63,8 +63,7 @@ typedef struct
char * pwd_tmp; /*Used to store the original text in password mode*/
const char * accapted_chars; /*Only these characters will be accepted. NULL: accept all*/
uint16_t max_length; /*The max. number of characters. 0: no limit*/
uint8_t pwd_mode : 1; /*Replace characters with '*' */
uint8_t one_line : 1; /*One line mode (ignore line breaks)*/
uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*' */
struct
{
const lv_style_t * style; /* Style of the cursor (NULL to use label's style)*/
@ -72,6 +71,7 @@ typedef struct
* (Used by the library)*/
uint16_t pos; /* The current cursor position
* (0: before 1st letter; 1: before 2nd letter ...)*/
uint16_t blink_time; /*Blink period*/
lv_area_t area; /* Cursor area relative to the Text Area*/
uint16_t txt_byte_pos; /* Byte index of the letter after (on) the cursor*/
lv_cursor_type_t type : 4; /* Shape of the cursor*/
@ -83,6 +83,8 @@ typedef struct
uint8_t text_sel_in_prog : 1; /*User is in process of selecting */
uint8_t text_sel_en : 1; /*Text can be selected on this text area*/
#endif
uint8_t pwd_mode : 1; /*Replace characters with '*' */
uint8_t one_line : 1; /*One line mode (ignore line breaks)*/
} lv_ta_ext_t;
enum {
@ -264,6 +266,20 @@ void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, const lv_style_t * style
*/
void lv_ta_set_text_sel(lv_obj_t * ta, bool en);
/**
* Set how long show the password before changing it to '*'
* @param ta pointer to Text area
* @param time show time in milliseconds. 0: hide immediately.
*/
void lv_ta_set_pwd_show_time(lv_obj_t * ta, uint16_t time);
/**
* Set cursor blink animation time
* @param ta pointer to Text area
* @param time blink period. 0: disable blinking
*/
void lv_ta_set_cursor_blink_time(lv_obj_t * ta, uint16_t time);
/*=====================
* Getter functions
*====================*/
@ -296,13 +312,6 @@ lv_obj_t * lv_ta_get_label(const lv_obj_t * ta);
*/
uint16_t lv_ta_get_cursor_pos(const lv_obj_t * ta);
/**
* Get the current cursor visibility.
* @param ta pointer to a text area object
* @return true: the cursor is drawn, false: the cursor is hidden
*/
// bool lv_ta_get_cursor_show(const lv_obj_t * ta);
/**
* Get the current cursor type.
* @param ta pointer to a text area object
@ -390,6 +399,20 @@ bool lv_ta_text_is_selected(const lv_obj_t * ta);
*/
bool lv_ta_get_text_sel_en(lv_obj_t * ta);
/**
* Set how long show the password before changing it to '*'
* @param ta pointer to Text area
* @return show time in milliseconds. 0: hide immediately.
*/
uint16_t lv_ta_get_pwd_show_time(lv_obj_t * ta);
/**
* Set cursor blink animation time
* @param ta pointer to Text area
* @return time blink period. 0: disable blinking
*/
uint16_t lv_ta_get_cursor_blink_time(lv_obj_t * ta);
/*=====================
* Other functions
*====================*/