2016-09-30 15:29:00 +02:00
|
|
|
/**
|
|
|
|
* @file lv_ta.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "lv_conf.h"
|
|
|
|
#if USE_LV_TA != 0
|
|
|
|
|
|
|
|
#include "lv_ta.h"
|
2017-08-23 14:39:09 +02:00
|
|
|
#include "../lv_obj/lv_group.h"
|
2016-10-04 09:45:39 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-08-23 14:39:09 +02:00
|
|
|
#include "misc/gfx/anim.h"
|
2017-10-05 11:29:21 +02:00
|
|
|
#include "misc/gfx/text.h"
|
2017-09-25 12:11:42 +02:00
|
|
|
#include "misc/math/math_base.h"
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2017-01-12 09:49:13 +01:00
|
|
|
/*Test configuration*/
|
|
|
|
|
|
|
|
#ifndef LV_TA_CUR_BLINK_TIME
|
2017-11-15 15:50:33 +01:00
|
|
|
#define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
|
2017-01-12 09:49:13 +01:00
|
|
|
#endif
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
#ifndef LV_TA_PWD_SHOW_TIME
|
|
|
|
#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
|
|
|
|
#endif
|
|
|
|
|
2017-06-26 14:08:29 +02:00
|
|
|
#define LV_TA_DEF_WIDTH (2 * LV_DPI)
|
|
|
|
#define LV_TA_DEF_HEIGHT (1 * LV_DPI)
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2016-10-07 11:15:46 +02:00
|
|
|
static bool lv_ta_design(lv_obj_t * ta, const area_t * mask, lv_design_mode_t mode);
|
2017-11-05 00:48:57 +01:00
|
|
|
static bool lv_ta_scrollable_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode);
|
2017-11-05 15:19:36 +01:00
|
|
|
static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param);
|
|
|
|
static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
2017-09-15 10:22:12 +02:00
|
|
|
static void cursor_blink_anim(lv_obj_t * ta, uint8_t show);
|
|
|
|
static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x);
|
2017-07-07 16:22:24 +02:00
|
|
|
static void pwd_char_hider(lv_obj_t * ta);
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_design_func_t ancestor_design;
|
|
|
|
static lv_design_func_t scrl_design;
|
|
|
|
static lv_signal_func_t ancestor_signal;
|
|
|
|
static lv_signal_func_t scrl_signal;
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a text area objects
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param par pointer to an object, it will be the parent of the new text area
|
|
|
|
* @param copy pointer to a text area object, if not NULL then the new object will be copied from it
|
2016-09-30 15:29:00 +02:00
|
|
|
* @return pointer to the created text area
|
|
|
|
*/
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
|
|
|
/*Create the ancestor object*/
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_obj_t * new_ta = lv_page_create(par, copy);
|
|
|
|
dm_assert(new_ta);
|
2017-11-05 00:48:57 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ta);
|
|
|
|
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ta);
|
|
|
|
if(scrl_signal == NULL) scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ta));
|
|
|
|
if(scrl_design == NULL) scrl_design = lv_obj_get_design_func(lv_page_get_scrl(new_ta));
|
2017-11-05 14:12:50 +01:00
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/*Allocate the object type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_allocate_ext_attr(new_ta, sizeof(lv_ta_ext_t));
|
2016-10-07 11:15:46 +02:00
|
|
|
dm_assert(ext);
|
2017-04-21 09:15:39 +02:00
|
|
|
ext->cursor_show = 1;
|
|
|
|
ext->cursor_state = 0;
|
2017-07-07 16:22:24 +02:00
|
|
|
ext->pwd_mode = 0;
|
|
|
|
ext->pwd_tmp = NULL;
|
2017-09-15 10:22:12 +02:00
|
|
|
ext->cursor_style = NULL;
|
2017-01-02 14:10:32 +01:00
|
|
|
ext->cursor_pos = 0;
|
2017-09-15 10:22:12 +02:00
|
|
|
ext->cursor_type = LV_TA_CURSOR_LINE;
|
2017-01-02 14:10:32 +01:00
|
|
|
ext->cursor_valid_x = 0;
|
|
|
|
ext->label = NULL;
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_set_signal_func(new_ta, lv_ta_signal);
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_obj_set_signal_func(lv_page_get_scrl(new_ta), lv_ta_scrollable_signal);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_set_design_func(new_ta, lv_ta_design);
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/*Init the new text area object*/
|
2016-10-07 11:15:46 +02:00
|
|
|
if(copy == NULL) {
|
|
|
|
ext->label = lv_label_create(new_ta, NULL);
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_obj_set_design_func(ext->page.scrl, lv_ta_scrollable_design);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2016-10-20 16:35:03 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
|
2017-10-30 17:11:56 +01:00
|
|
|
lv_label_set_text(ext->label, "Text area");
|
2016-12-18 22:07:03 +01:00
|
|
|
lv_obj_set_click(ext->label, false);
|
2017-01-02 15:00:21 +01:00
|
|
|
lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT);
|
2017-11-05 15:19:36 +01:00
|
|
|
lv_ta_set_sb_mode(new_ta, LV_PAGE_SB_MODE_DRAG);
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_page_set_style(new_ta, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight);
|
|
|
|
|
|
|
|
/*Set the default styles*/
|
|
|
|
lv_theme_t *th = lv_theme_get_current();
|
|
|
|
if(th) {
|
|
|
|
lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->ta.area);
|
|
|
|
lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->ta.sb);
|
|
|
|
} else {
|
|
|
|
lv_ta_set_style(new_ta, LV_TA_STYLE_BG, &lv_style_pretty);
|
|
|
|
}
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing object*/
|
|
|
|
else {
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_obj_set_design_func(ext->page.scrl, lv_ta_scrollable_design);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2016-10-07 11:15:46 +02:00
|
|
|
ext->label = lv_label_create(new_ta, copy_ext->label);
|
2017-06-07 12:38:43 +02:00
|
|
|
ext->cursor_show = copy_ext->cursor_show;
|
2017-07-28 14:26:51 +02:00
|
|
|
ext->pwd_mode = copy_ext->pwd_mode;
|
2017-11-05 14:12:50 +01:00
|
|
|
ext->cursor_style = copy_ext->cursor_style;
|
|
|
|
ext->cursor_pos = copy_ext->cursor_pos;
|
|
|
|
ext->cursor_valid_x = copy_ext->cursor_valid_x;
|
2017-10-02 16:50:34 +02:00
|
|
|
if(copy_ext->one_line) lv_ta_set_one_line(new_ta, true);
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_ta_set_style(new_ta, LV_TA_STYLE_CURSOR, lv_ta_get_style(copy, LV_TA_STYLE_CURSOR));
|
|
|
|
|
2017-01-08 13:06:41 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_ta);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
|
2016-12-15 10:31:30 +01:00
|
|
|
/*Create a cursor blinker animation*/
|
|
|
|
anim_t a;
|
|
|
|
a.var = new_ta;
|
2017-07-07 16:22:24 +02:00
|
|
|
a.fp = (anim_fp_t)cursor_blink_anim;
|
2017-11-15 15:50:33 +01:00
|
|
|
a.time = LV_TA_CURSOR_BLINK_TIME;
|
2016-12-15 10:31:30 +01:00
|
|
|
a.act_time = 0;
|
|
|
|
a.end_cb = NULL;
|
2017-09-15 10:22:12 +02:00
|
|
|
a.start = 1;
|
|
|
|
a.end = 0;
|
2016-12-15 10:31:30 +01:00
|
|
|
a.repeat = 1;
|
|
|
|
a.repeat_pause = 0;
|
|
|
|
a.playback = 1;
|
|
|
|
a.playback_pause = 0;
|
|
|
|
a.path = anim_get_path(ANIM_PATH_STEP);
|
|
|
|
anim_create(&a);
|
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
return new_ta;
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
|
|
|
* Insert a character to the current cursor position
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param ta pointer to a text area object
|
2017-11-05 14:12:50 +01:00
|
|
|
* @param c a character
|
2016-10-04 09:45:39 +02:00
|
|
|
*/
|
2017-11-05 14:12:50 +01:00
|
|
|
void lv_ta_add_char(lv_obj_t * ta, char c)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2016-10-01 00:25:10 +02:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
2017-09-22 13:58:01 +02:00
|
|
|
char letter_buf[2];
|
|
|
|
letter_buf[0] = c;
|
|
|
|
letter_buf[1] = '\0';
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2017-09-22 13:58:01 +02:00
|
|
|
lv_label_ins_text(ext->label, ext->cursor_pos, letter_buf); /*Insert the character*/
|
2016-10-01 00:25:10 +02:00
|
|
|
|
2017-09-22 13:58:01 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2017-09-22 13:58:01 +02:00
|
|
|
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */
|
|
|
|
dm_assert(ext->pwd_tmp);
|
|
|
|
txt_ins(ext->pwd_tmp, ext->cursor_pos, letter_buf);
|
2017-08-29 15:08:18 +02:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:08:18 +02:00
|
|
|
/*Move the cursor after the new character*/
|
|
|
|
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + 1);
|
2016-10-01 00:25:10 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
|
|
|
* Insert a text to the current cursor position
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param ta pointer to a text area object
|
2016-10-04 09:45:39 +02:00
|
|
|
* @param txt a '\0' terminated string to insert
|
|
|
|
*/
|
2016-10-07 11:15:46 +02:00
|
|
|
void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
2016-10-01 00:25:10 +02:00
|
|
|
{
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-05 14:12:50 +01:00
|
|
|
|
2017-01-02 15:00:21 +01:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
2017-01-02 15:00:21 +01:00
|
|
|
/*Insert the text*/
|
2016-10-01 00:25:10 +02:00
|
|
|
|
2017-09-22 13:58:01 +02:00
|
|
|
lv_label_ins_text(ext->label, ext->cursor_pos, txt);
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2017-11-05 14:12:50 +01:00
|
|
|
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + strlen(txt) + 1);
|
2017-08-29 15:08:18 +02:00
|
|
|
dm_assert(ext->pwd_tmp);
|
2017-09-22 13:58:01 +02:00
|
|
|
|
|
|
|
txt_ins(ext->pwd_tmp, ext->cursor_pos, txt);
|
2017-08-29 15:08:18 +02:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-08-29 15:08:18 +02:00
|
|
|
|
|
|
|
/*Move the cursor after the new text*/
|
2017-11-05 14:12:50 +01:00
|
|
|
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + txt_len(txt));
|
2016-10-01 00:25:10 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Delete a the left character from the current cursor position
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
|
|
|
void lv_ta_del_char(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
uint16_t cur_pos = ext->cursor_pos;
|
|
|
|
|
|
|
|
if(cur_pos == 0) return;
|
|
|
|
|
|
|
|
char * label_txt = lv_label_get_text(ext->label);
|
|
|
|
/*Delete a character*/
|
|
|
|
txt_cut(label_txt, ext->cursor_pos - 1, 1);
|
|
|
|
/*Refresh the label*/
|
|
|
|
lv_label_set_text(ext->label, label_txt);
|
|
|
|
|
|
|
|
/*Don't let 'width == 0' because cursor will not be visible*/
|
|
|
|
if(lv_obj_get_width(ext->label) == 0) {
|
|
|
|
lv_style_t * style = lv_obj_get_style(ext->label);
|
|
|
|
lv_obj_set_width(ext->label, style->line.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ext->pwd_mode != 0) {
|
|
|
|
#if TXT_UTF8 == 0
|
|
|
|
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, 1);
|
|
|
|
#else
|
|
|
|
uint32_t byte_pos = txt_utf8_get_byte_id(ext->pwd_tmp, ext->cursor_pos - 1);
|
|
|
|
txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, txt_utf8_size(label_txt[byte_pos]));
|
|
|
|
#endif
|
|
|
|
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1);
|
|
|
|
dm_assert(ext->pwd_tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Move the cursor to the place of the deleted character*/
|
|
|
|
lv_ta_set_cursor_pos(ta, ext->cursor_pos - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-12-15 10:31:30 +01:00
|
|
|
/**
|
2016-12-18 22:07:03 +01:00
|
|
|
* Set the text of a text area
|
2016-12-15 10:31:30 +01:00
|
|
|
* @param ta pointer to a text area
|
|
|
|
* @param txt pointer to the text
|
|
|
|
*/
|
|
|
|
void lv_ta_set_text(lv_obj_t * ta, const char * txt)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2016-12-15 10:31:30 +01:00
|
|
|
lv_label_set_text(ext->label, txt);
|
2017-11-05 14:12:50 +01:00
|
|
|
lv_ta_set_cursor_pos(ta, LV_TA_CURSOR_LAST);
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2017-08-16 11:28:04 +02:00
|
|
|
/*Don't let 'width == 0' because cursor will not be visible*/
|
|
|
|
if(lv_obj_get_width(ext->label) == 0) {
|
|
|
|
lv_style_t * style = lv_obj_get_style(ext->label);
|
2017-10-19 12:46:49 +02:00
|
|
|
lv_obj_set_width(ext->label, font_get_width(style->text.font, ' '));
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2017-08-29 15:08:18 +02:00
|
|
|
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(txt) + 1);
|
|
|
|
strcpy(ext->pwd_tmp, txt);
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-12-15 10:31:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
|
|
|
* Set the cursor position
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param obj pointer to a text area object
|
2016-10-04 09:45:39 +02:00
|
|
|
* @param pos the new cursor position in character index
|
2016-12-15 10:31:30 +01:00
|
|
|
* < 0 : index from the end of the text
|
2017-11-15 15:50:33 +01:00
|
|
|
* LV_TA_CURSOR_LAST: go after the last character
|
2016-10-04 09:45:39 +02:00
|
|
|
*/
|
2016-12-15 10:31:30 +01:00
|
|
|
void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
|
2016-10-01 00:25:10 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-05 15:19:36 +01:00
|
|
|
uint16_t len = txt_len(lv_label_get_text(ext->label));
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2017-09-22 09:52:53 +02:00
|
|
|
if(pos < 0) pos = len + pos;
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2017-11-05 14:12:50 +01:00
|
|
|
if(pos > len || pos == LV_TA_CURSOR_LAST) pos = len;
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
ext->cursor_pos = pos;
|
2016-10-04 09:45:39 +02:00
|
|
|
|
|
|
|
/*Position the label to make the cursor visible*/
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_obj_t * label_par = lv_obj_get_parent(ext->label);
|
2016-10-04 09:45:39 +02:00
|
|
|
point_t cur_pos;
|
2017-04-13 10:20:35 +02:00
|
|
|
lv_style_t * style = lv_obj_get_style(ta);
|
2017-10-19 12:46:49 +02:00
|
|
|
const font_t * font_p = style->text.font;
|
2016-12-30 21:44:41 +01:00
|
|
|
area_t label_cords;
|
|
|
|
area_t ta_cords;
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_label_get_letter_pos(ext->label, pos, &cur_pos);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_get_coords(ta, &ta_cords);
|
|
|
|
lv_obj_get_coords(ext->label, &label_cords);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
|
|
|
/*Check the top*/
|
2017-11-11 14:23:05 +01:00
|
|
|
cord_t font_h = font_get_height_scale(font_p);
|
2016-10-07 11:15:46 +02:00
|
|
|
if(lv_obj_get_y(label_par) + cur_pos.y < 0) {
|
2017-11-05 14:12:50 +01:00
|
|
|
lv_obj_set_y(label_par, - cur_pos.y + style->body.padding.ver);
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Check the bottom*/
|
2017-11-05 14:12:50 +01:00
|
|
|
if(label_cords.y1 + cur_pos.y + font_h + style->body.padding.ver > ta_cords.y2) {
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) +
|
2017-11-05 14:12:50 +01:00
|
|
|
font_h + 2 * style->body.padding.ver));
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
2017-08-16 11:28:04 +02:00
|
|
|
/*Check the left (use the font_h as general unit)*/
|
|
|
|
if(lv_obj_get_x(label_par) + cur_pos.x < font_h) {
|
|
|
|
lv_obj_set_x(label_par, - cur_pos.x + font_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Check the right (use the font_h as general unit)*/
|
2017-11-05 14:12:50 +01:00
|
|
|
if(label_cords.x1 + cur_pos.x + font_h + style->body.padding.hor > ta_cords.x2) {
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) +
|
2017-11-05 14:12:50 +01:00
|
|
|
font_h + 2 * style->body.padding.hor));
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2017-11-05 14:12:50 +01:00
|
|
|
ext->cursor_valid_x = cur_pos.x;
|
|
|
|
|
2017-09-22 09:52:53 +02:00
|
|
|
/*Reset cursor blink animation*/
|
2017-09-15 10:22:12 +02:00
|
|
|
anim_t a;
|
|
|
|
a.var = ta;
|
|
|
|
a.fp = (anim_fp_t)cursor_blink_anim;
|
2017-11-15 15:50:33 +01:00
|
|
|
a.time = LV_TA_CURSOR_BLINK_TIME;
|
2017-09-15 10:22:12 +02:00
|
|
|
a.act_time = 0;
|
|
|
|
a.end_cb = NULL;
|
|
|
|
a.start = 1;
|
|
|
|
a.end= 0;
|
|
|
|
a.repeat = 1;
|
|
|
|
a.repeat_pause = 0;
|
|
|
|
a.playback = 1;
|
|
|
|
a.playback_pause = 0;
|
|
|
|
a.path = anim_get_path(ANIM_PATH_STEP);
|
|
|
|
anim_create(&a);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(ta);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 09:15:39 +02:00
|
|
|
/**
|
2017-07-07 16:22:24 +02:00
|
|
|
* Set the cursor visibility.
|
2017-04-21 09:15:39 +02:00
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return show true: show the cursor and blink it, false: hide cursor
|
|
|
|
*/
|
|
|
|
void lv_ta_set_cursor_show(lv_obj_t * ta, bool show)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-04-21 09:15:39 +02:00
|
|
|
ext->cursor_show = show == false ? 0 : 1;
|
2017-08-23 14:19:42 +02:00
|
|
|
ext->cursor_state = 0;
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(ta);
|
2017-04-21 09:15:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
/**
|
|
|
|
* Set the cursor type.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param cur_type: element of 'lv_ta_cursor_type_t'
|
|
|
|
*/
|
|
|
|
void lv_ta_set_cursor_type(lv_obj_t * ta, lv_ta_cursor_type_t cur_type)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
ext->cursor_type = cur_type;
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
/**
|
|
|
|
* Enable/Disable password mode
|
2017-11-05 00:48:57 +01:00
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param pwd_en true: enable, false: disable
|
2017-07-07 16:22:24 +02:00
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
void lv_ta_set_pwd_mode(lv_obj_t * ta, bool pwd_en)
|
2017-07-07 16:22:24 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
|
|
|
|
/*Pwd mode is now enabled*/
|
2017-11-05 00:48:57 +01:00
|
|
|
if(ext->pwd_mode == 0 && pwd_en != false) {
|
2017-07-07 16:22:24 +02:00
|
|
|
char * txt = lv_label_get_text(ext->label);
|
2017-09-22 09:52:53 +02:00
|
|
|
uint16_t len = strlen(txt);
|
|
|
|
ext->pwd_tmp = dm_alloc(len + 1);
|
2017-07-07 16:22:24 +02:00
|
|
|
strcpy(ext->pwd_tmp, txt);
|
|
|
|
|
|
|
|
uint16_t i;
|
2017-09-22 09:52:53 +02:00
|
|
|
for(i = 0; i < len; i++) {
|
2017-07-07 16:22:24 +02:00
|
|
|
txt[i] = '*'; /*All char to '*'*/
|
|
|
|
}
|
2017-09-22 09:52:53 +02:00
|
|
|
txt[i] = '\0';
|
2017-07-07 16:22:24 +02:00
|
|
|
|
|
|
|
lv_label_set_text(ext->label, NULL);
|
|
|
|
}
|
|
|
|
/*Pwd mode is now disabled*/
|
2017-11-05 00:48:57 +01:00
|
|
|
else if(ext->pwd_mode == 1 && pwd_en == false) {
|
2017-07-07 16:22:24 +02:00
|
|
|
lv_label_set_text(ext->label, ext->pwd_tmp);
|
|
|
|
dm_free(ext->pwd_tmp);
|
|
|
|
ext->pwd_tmp = NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->pwd_mode = pwd_en == false ? 0 : 1;
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
2017-08-16 11:28:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure the text area to one line or back to normal
|
|
|
|
* @param ta pointer to a Text area object
|
|
|
|
* @param en true: one line, false: normal
|
|
|
|
*/
|
|
|
|
void lv_ta_set_one_line(lv_obj_t * ta, bool en)
|
|
|
|
{
|
|
|
|
if(en != false) {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_style_t * style_ta = lv_obj_get_style(ta);
|
2017-10-09 16:11:54 +02:00
|
|
|
lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta));
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_style_t * style_label = lv_obj_get_style(ext->label);
|
2017-11-11 14:23:05 +01:00
|
|
|
cord_t font_h = font_get_height_scale(style_label->text.font);
|
2017-08-16 11:28:04 +02:00
|
|
|
|
2017-10-02 16:50:34 +02:00
|
|
|
ext->one_line = 1;
|
2017-11-05 15:19:36 +01:00
|
|
|
lv_page_set_scrl_fit(ta, true, true);
|
2017-10-26 21:20:10 +02:00
|
|
|
lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND);
|
|
|
|
lv_label_set_no_break(ext->label, true);
|
2017-10-26 21:20:10 +02:00
|
|
|
lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver);
|
2017-08-16 11:28:04 +02:00
|
|
|
} else {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_style_t * style_ta = lv_obj_get_style(ta);
|
|
|
|
|
2017-10-02 16:50:34 +02:00
|
|
|
ext->one_line = 0;
|
2017-11-05 15:19:36 +01:00
|
|
|
lv_page_set_scrl_fit(ta, false, true);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_no_break(ext->label, false);
|
|
|
|
lv_obj_set_height(ta, LV_TA_DEF_HEIGHT);
|
2017-10-26 21:20:10 +02:00
|
|
|
lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver);
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set a style of a text area
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param ta pointer to a text area object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2017-11-15 15:50:33 +01:00
|
|
|
void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
switch (type) {
|
|
|
|
case LV_TA_STYLE_BG:
|
|
|
|
lv_page_set_style(ta, LV_PAGE_STYLE_BG, style);
|
|
|
|
break;
|
|
|
|
case LV_TA_STYLE_SB:
|
|
|
|
lv_page_set_style(ta, LV_PAGE_STYLE_SB, style);
|
|
|
|
break;
|
|
|
|
case LV_TA_STYLE_CURSOR:
|
|
|
|
ext->cursor_style = style;
|
|
|
|
lv_obj_refresh_ext_size(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/
|
|
|
|
break;
|
|
|
|
}
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
2017-06-13 14:49:41 +02:00
|
|
|
* Get the text of a text area
|
|
|
|
* @param ta pointer to a text area object
|
2016-10-04 09:45:39 +02:00
|
|
|
* @return pointer to the text
|
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
const char * lv_ta_get_text(lv_obj_t * ta)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
|
|
|
|
const char * txt;
|
|
|
|
if(ext->pwd_mode == 0) {
|
|
|
|
txt = lv_label_get_text(ext->label);
|
|
|
|
} else {
|
|
|
|
txt = ext->pwd_tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return txt;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 14:49:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the label of a text area
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return pointer to the label object
|
|
|
|
*/
|
|
|
|
lv_obj_t * lv_ta_get_label(lv_obj_t * ta)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-06-13 14:49:41 +02:00
|
|
|
return ext->label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
|
|
|
* Get the current cursor position in character index
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param ta pointer to a text area object
|
2016-10-04 09:45:39 +02:00
|
|
|
* @return the cursor position
|
|
|
|
*/
|
2016-10-07 11:15:46 +02:00
|
|
|
uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2016-10-07 11:15:46 +02:00
|
|
|
return ext->cursor_pos;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 09:15:39 +02:00
|
|
|
/**
|
|
|
|
* 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(lv_obj_t * ta)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-04-21 09:15:39 +02:00
|
|
|
return ext->cursor_show;
|
|
|
|
}
|
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
/**
|
|
|
|
* Get the current cursor type.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return element of 'lv_ta_cursor_type_t'
|
|
|
|
*/
|
|
|
|
lv_ta_cursor_type_t lv_ta_get_cursor_type(lv_obj_t * ta)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
return ext->cursor_type;
|
|
|
|
}
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
/**
|
2017-11-05 14:12:50 +01:00
|
|
|
* Get the password mode attribute
|
2017-07-07 16:22:24 +02:00
|
|
|
* @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)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-05 14:12:50 +01:00
|
|
|
return ext->pwd_mode == 0 ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the one line configuration attribute
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return true: one line configuration is enabled, false: disabled
|
|
|
|
*/
|
|
|
|
bool lv_ta_get_one_line(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
return ext->one_line == 0 ? false : true;
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Get a style of a text area
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
|
|
|
*/
|
|
|
|
lv_style_t * lv_ta_get_style(lv_obj_t *ta, lv_ta_style_t type)
|
|
|
|
{
|
|
|
|
lv_ta_ext_t *ext = lv_obj_get_ext_attr(ta);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LV_TA_STYLE_BG: return lv_page_get_style(ta, LV_PAGE_STYLE_BG);
|
|
|
|
case LV_TA_STYLE_SB: return lv_page_get_style(ta, LV_PAGE_STYLE_SB);
|
|
|
|
case LV_TA_STYLE_CURSOR: return ext->cursor_style; /*TODO in 'ext' all cursor attributes into a struct*/
|
|
|
|
default: return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*To avoid warning*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one character right
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
|
|
|
void lv_ta_cursor_right(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
uint16_t cp = lv_ta_get_cursor_pos(ta);
|
|
|
|
cp++;
|
|
|
|
lv_ta_set_cursor_pos(ta, cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one character left
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
|
|
|
void lv_ta_cursor_left(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
uint16_t cp = lv_ta_get_cursor_pos(ta);
|
|
|
|
if(cp > 0) {
|
|
|
|
cp--;
|
|
|
|
lv_ta_set_cursor_pos(ta, cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one line down
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
|
|
|
void lv_ta_cursor_down(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
point_t pos;
|
|
|
|
|
|
|
|
/*Get the position of the current letter*/
|
|
|
|
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
|
|
|
|
|
|
|
|
/*Increment the y with one line and keep the valid x*/
|
|
|
|
lv_style_t * label_style = lv_obj_get_style(ext->label);
|
|
|
|
const font_t * font_p = label_style->text.font;
|
|
|
|
cord_t font_h = font_get_height_scale(font_p);
|
|
|
|
pos.y += font_h + label_style->text.line_space + 1;
|
|
|
|
pos.x = ext->cursor_valid_x;
|
|
|
|
|
|
|
|
/*Do not go below the last line*/
|
|
|
|
if(pos.y < lv_obj_get_height(ext->label)) {
|
|
|
|
/*Get the letter index on the new cursor position and set it*/
|
|
|
|
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
|
|
|
|
|
|
|
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
|
|
|
|
lv_ta_set_cursor_pos(ta, new_cur_pos);
|
|
|
|
ext->cursor_valid_x = cur_valid_x_tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one line up
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
|
|
|
void lv_ta_cursor_up(lv_obj_t * ta)
|
|
|
|
{
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
point_t pos;
|
|
|
|
|
|
|
|
/*Get the position of the current letter*/
|
|
|
|
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
|
|
|
|
|
|
|
|
/*Decrement the y with one line and keep the valid x*/
|
|
|
|
lv_style_t * label_style = lv_obj_get_style(ext->label);
|
|
|
|
const font_t * font = label_style->text.font;
|
|
|
|
cord_t font_h = font_get_height_scale(font);
|
|
|
|
pos.y -= font_h + label_style->text.line_space - 1;
|
|
|
|
pos.x = ext->cursor_valid_x;
|
|
|
|
|
|
|
|
|
|
|
|
/*Get the letter index on the new cursor position and set it*/
|
|
|
|
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
|
|
|
cord_t cur_valid_x_tmp = ext->cursor_valid_x; /*Cursor position set overwrites the valid positon */
|
|
|
|
lv_ta_set_cursor_pos(ta, new_cur_pos);
|
|
|
|
ext->cursor_valid_x = cur_valid_x_tmp;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the text areas
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param ta pointer to an object
|
2016-09-30 15:29:00 +02:00
|
|
|
* @param mask the object will be drawn only in this area
|
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
2016-10-04 09:45:39 +02:00
|
|
|
* LV_DESIGN_DRAW_MAIN: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
2016-09-30 15:29:00 +02:00
|
|
|
* @param return true/false, depends on 'mode'
|
|
|
|
*/
|
2016-10-07 11:15:46 +02:00
|
|
|
static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mode)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
2017-11-05 00:48:57 +01:00
|
|
|
return ancestor_design(ta, masp, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
|
|
|
/*Draw the object*/
|
2017-11-05 00:48:57 +01:00
|
|
|
ancestor_design(ta, masp, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
|
|
|
} else if(mode == LV_DESIGN_DRAW_POST) {
|
2017-11-05 00:48:57 +01:00
|
|
|
ancestor_design(ta, masp, mode);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2016-10-04 15:29:52 +02:00
|
|
|
/**
|
2017-09-25 12:11:42 +02:00
|
|
|
* An extended scrollable design of the page. Calls the normal design function and draws a cursor.
|
2017-10-05 11:29:21 +02:00
|
|
|
* @param scrl pointer to the scrollable part of the Text area
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param mask the object will be drawn only in this area
|
2016-10-04 15:29:52 +02:00
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW_MAIN: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
|
|
|
* @return return true/false, depends on 'mode'
|
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
static bool lv_ta_scrollable_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
2017-11-05 00:48:57 +01:00
|
|
|
return scrl_design(scrl, mask, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
|
|
|
/*Draw the object*/
|
2017-11-05 00:48:57 +01:00
|
|
|
scrl_design(scrl, mask, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
} else if(mode == LV_DESIGN_DRAW_POST) {
|
2017-11-05 00:48:57 +01:00
|
|
|
scrl_design(scrl, mask, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
|
|
|
/*Draw the cursor too*/
|
2017-09-25 12:11:42 +02:00
|
|
|
lv_obj_t * ta = lv_obj_get_parent(scrl);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ta_ext = lv_obj_get_ext_attr(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_style_t * label_style = lv_obj_get_style(ta_ext->label);
|
2017-11-02 01:37:32 +01:00
|
|
|
if(ta_ext->cursor_show == 0 || ta_ext->cursor_state == 0 || label_style->body.opa == OPA_TRANSP) return true; /*The cursor is not visible now*/
|
2017-10-30 17:11:56 +01:00
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
|
|
|
|
lv_style_t cur_style;
|
|
|
|
if(ta_ext->cursor_style != NULL) {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_style_copy(&cur_style, ta_ext->cursor_style);
|
2017-09-15 10:22:12 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-09-25 12:11:42 +02:00
|
|
|
/*If cursor style is not specified then use the modified label style */
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_style_copy(&cur_style, label_style);
|
2017-10-19 12:46:49 +02:00
|
|
|
color_t ccolor_tmp = cur_style.text.color; /*Make letter color to cursor color*/
|
|
|
|
cur_style.text.color = cur_style.body.color_main; /*In block mode the letter color will be current background color*/
|
2017-10-18 16:07:19 +02:00
|
|
|
cur_style.body.color_main = ccolor_tmp;
|
2017-10-19 12:46:49 +02:00
|
|
|
cur_style.body.color_gradient = ccolor_tmp;
|
2017-10-20 10:17:02 +02:00
|
|
|
cur_style.body.border.color = ccolor_tmp;
|
|
|
|
cur_style.body.border.opa = OPA_COVER;
|
|
|
|
cur_style.body.border.width = 1 << LV_ANTIALIAS;
|
|
|
|
cur_style.body.shadow.width = 0;
|
2017-10-18 16:07:19 +02:00
|
|
|
cur_style.body.radius = 0;
|
|
|
|
cur_style.body.empty = 0;
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_style.body.padding.hor = 0;
|
|
|
|
cur_style.body.padding.ver = 0;
|
2017-10-20 10:17:02 +02:00
|
|
|
cur_style.line.width = 1 << LV_ANTIALIAS;
|
2017-11-02 01:37:32 +01:00
|
|
|
cur_style.body.opa = OPA_COVER;
|
2017-09-15 10:22:12 +02:00
|
|
|
}
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
|
|
|
|
const char * txt = lv_label_get_text(ta_ext->label);
|
2017-10-05 11:29:21 +02:00
|
|
|
uint32_t byte_pos;
|
|
|
|
#if TXT_UTF8 != 0
|
2017-11-05 14:12:50 +01:00
|
|
|
byte_pos = txt_utf8_get_byte_id(txt, cur_pos);
|
2017-10-05 11:29:21 +02:00
|
|
|
#else
|
|
|
|
byte_pos = cur_pos;
|
|
|
|
#endif
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-10-05 11:29:21 +02:00
|
|
|
uint32_t letter = txt_utf8_next(&txt[byte_pos], NULL);
|
2017-11-11 14:23:05 +01:00
|
|
|
cord_t letter_h = font_get_height_scale(label_style->text.font);
|
2017-10-05 11:29:21 +02:00
|
|
|
/*Set letter_w (set not 0 on non printable but valid chars)*/
|
2017-09-25 12:11:42 +02:00
|
|
|
cord_t letter_w;
|
2017-10-05 11:29:21 +02:00
|
|
|
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
2017-10-19 12:46:49 +02:00
|
|
|
letter_w = font_get_width(label_style->text.font, ' ');
|
2017-09-25 12:11:42 +02:00
|
|
|
} else {
|
2017-10-19 12:46:49 +02:00
|
|
|
letter_w = font_get_width(label_style->text.font, letter);
|
2017-09-25 12:11:42 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
point_t letter_pos;
|
2017-11-05 14:12:50 +01:00
|
|
|
lv_label_get_letter_pos(ta_ext->label, cur_pos, &letter_pos);
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2017-10-05 11:29:21 +02:00
|
|
|
/*If the cursor is out of the text (most right) draw it to the next line*/
|
2017-10-20 10:17:02 +02:00
|
|
|
if(letter_pos.x + ta_ext->label->coords.x1 + letter_w > ta_ext->label->coords.x2 && ta_ext->one_line == 0) {
|
2017-09-25 12:11:42 +02:00
|
|
|
letter_pos.x = 0;
|
2017-11-05 00:48:57 +01:00
|
|
|
letter_pos.y += letter_h + label_style->text.line_space;
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-10-05 11:29:21 +02:00
|
|
|
if(letter != '\0'){
|
|
|
|
byte_pos += txt_utf8_size(txt[byte_pos]);
|
|
|
|
letter = txt_utf8_next(&txt[byte_pos], NULL);
|
|
|
|
}
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-10-05 11:29:21 +02:00
|
|
|
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
2017-10-19 12:46:49 +02:00
|
|
|
letter_w = font_get_width(label_style->text.font, ' ');
|
2017-09-25 12:11:42 +02:00
|
|
|
} else {
|
2017-10-19 12:46:49 +02:00
|
|
|
letter_w = font_get_width(label_style->text.font, letter);
|
2017-09-25 12:11:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Draw he cursor according to the type*/
|
2017-09-15 10:22:12 +02:00
|
|
|
area_t cur_area;
|
|
|
|
if(ta_ext->cursor_type == LV_TA_CURSOR_LINE) {
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_area.x1 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor - (cur_style.line.width >> 1) - (cur_style.line.width & 0x1);
|
|
|
|
cur_area.y1 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver;
|
|
|
|
cur_area.x2 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor + (cur_style.line.width >> 1);
|
|
|
|
cur_area.y2 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver + letter_h;
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_draw_rect(&cur_area, mask, &cur_style);
|
|
|
|
} else if(ta_ext->cursor_type == LV_TA_CURSOR_BLOCK) {
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_area.x1 = letter_pos.x + ta_ext->label->coords.x1 - cur_style.body.padding.hor;
|
|
|
|
cur_area.y1 = letter_pos.y + ta_ext->label->coords.y1 - cur_style.body.padding.ver;
|
|
|
|
cur_area.x2 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor + letter_w;
|
|
|
|
cur_area.y2 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver + letter_h;
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_draw_rect(&cur_area, mask, &cur_style);
|
|
|
|
|
2017-09-22 09:52:53 +02:00
|
|
|
/*Get the current letter*/
|
|
|
|
#if TXT_UTF8 == 0
|
2017-09-15 10:22:12 +02:00
|
|
|
char letter_buf[2];
|
2017-10-30 17:11:56 +01:00
|
|
|
letter_buf[0] = txt[byte_pos];
|
2017-09-22 09:52:53 +02:00
|
|
|
letter_buf[1] = '\0';
|
|
|
|
#else
|
|
|
|
char letter_buf[8] = {0};
|
|
|
|
memcpy(letter_buf, &txt[byte_pos], txt_utf8_size(txt[byte_pos]));
|
|
|
|
#endif
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_area.x1 += cur_style.body.padding.hor;
|
|
|
|
cur_area.y1 += cur_style.body.padding.ver;
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_draw_label(&cur_area, mask, &cur_style, letter_buf, TXT_FLAG_NONE, 0);
|
|
|
|
|
|
|
|
} else if(ta_ext->cursor_type == LV_TA_CURSOR_OUTLINE) {
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_area.x1 = letter_pos.x + ta_ext->label->coords.x1 - cur_style.body.padding.hor;
|
|
|
|
cur_area.y1 = letter_pos.y + ta_ext->label->coords.y1 - cur_style.body.padding.ver;
|
|
|
|
cur_area.x2 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor + letter_w;
|
2017-11-05 14:12:50 +01:00
|
|
|
cur_area.y2 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver+ letter_h;
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-10-18 16:07:19 +02:00
|
|
|
cur_style.body.empty = 1;
|
2017-10-20 10:17:02 +02:00
|
|
|
if(cur_style.body.border.width == 0) cur_style.body.border.width = 1 << LV_ANTIALIAS; /*Be sure the border will be drawn*/
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_draw_rect(&cur_area, mask, &cur_style);
|
|
|
|
} else if(ta_ext->cursor_type == LV_TA_CURSOR_UNDERLINE) {
|
2017-10-26 21:20:10 +02:00
|
|
|
cur_area.x1 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor;
|
|
|
|
cur_area.y1 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver + letter_h - (cur_style.line.width >> 1);
|
|
|
|
cur_area.x2 = letter_pos.x + ta_ext->label->coords.x1 + cur_style.body.padding.hor + letter_w;
|
|
|
|
cur_area.y2 = letter_pos.y + ta_ext->label->coords.y1 + cur_style.body.padding.ver + letter_h + (cur_style.line.width >> 1) + (cur_style.line.width & 0x1);
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
lv_draw_rect(&cur_area, mask, &cur_style);
|
2016-10-07 11:15:46 +02:00
|
|
|
}
|
2017-09-15 10:22:12 +02:00
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 15:19:36 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the text area
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
2017-11-11 14:23:05 +01:00
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-11-05 15:19:36 +01:00
|
|
|
*/
|
|
|
|
static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(ta, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2017-11-05 15:19:36 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
if(ext->pwd_tmp != NULL) dm_free(ext->pwd_tmp);
|
|
|
|
|
|
|
|
/* (The created label will be deleted automatically) */
|
|
|
|
} else if(sign == LV_SIGNAL_STYLE_CHG) {
|
|
|
|
if(ext->label) {
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(ta);
|
|
|
|
lv_style_t * style_ta = lv_obj_get_style(ta);
|
|
|
|
lv_style_t * style_scrl = lv_obj_get_style(scrl);
|
|
|
|
if(ext->one_line) {
|
|
|
|
/*In one line mode refresh the Text Area height because 'vpad' can modify it*/
|
|
|
|
lv_style_t * style_label = lv_obj_get_style(ext->label);
|
2017-11-11 14:23:05 +01:00
|
|
|
cord_t font_h = font_get_height_scale(style_label->text.font);
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2);
|
|
|
|
} else {
|
|
|
|
/*In not one line mode refresh the Label width because 'hpad' can modify it*/
|
|
|
|
lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor);
|
|
|
|
lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the Label is in the correct position*/
|
|
|
|
}
|
|
|
|
lv_label_set_text(ext->label, NULL);
|
2017-11-05 15:19:36 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
|
|
|
} else if(sign == LV_SIGNAL_CORD_CHG) {
|
|
|
|
/*Set the label width according to the text area width*/
|
|
|
|
if(ext->label) {
|
|
|
|
if(lv_obj_get_width(ta) != area_get_width(param) ||
|
|
|
|
lv_obj_get_height(ta) != area_get_height(param)) {
|
2017-11-05 15:19:36 +01:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(ta);
|
|
|
|
lv_style_t * style_scrl = lv_obj_get_style(scrl);
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor);
|
|
|
|
lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver);
|
|
|
|
lv_label_set_text(ext->label, NULL); /*Refresh the label*/
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
|
|
|
else if (sign == LV_SIGNAL_CONTROLL) {
|
|
|
|
char c = *((char*)param);
|
|
|
|
if(c == LV_GROUP_KEY_RIGHT) {
|
|
|
|
lv_ta_cursor_right(ta);
|
|
|
|
} else if(c == LV_GROUP_KEY_LEFT) {
|
|
|
|
lv_ta_cursor_left(ta);
|
|
|
|
} else if(c == LV_GROUP_KEY_UP) {
|
|
|
|
lv_ta_cursor_up(ta);
|
|
|
|
} else if(c == LV_GROUP_KEY_DOWN) {
|
|
|
|
lv_ta_cursor_down(ta);
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal function of the scrollable part of the text area
|
|
|
|
* @param scrl pointer to scrollable part of a text area object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
2017-11-11 14:23:05 +01:00
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-11-05 15:19:36 +01:00
|
|
|
*/
|
|
|
|
static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = scrl_signal(scrl, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2017-11-05 15:19:36 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
|
|
|
|
/*Set ext. size because the cursor might be out of this object*/
|
|
|
|
lv_obj_t * ta = lv_obj_get_parent(scrl);
|
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
lv_style_t * style_label = lv_obj_get_style(ext->label);
|
2017-11-11 14:23:05 +01:00
|
|
|
cord_t font_h = font_get_height_scale(style_label->text.font);
|
2017-11-07 17:00:55 +01:00
|
|
|
scrl->ext_size = MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h);
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
2017-11-07 17:00:55 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
2016-12-15 10:31:30 +01:00
|
|
|
|
|
|
|
/**
|
2017-04-21 09:15:39 +02:00
|
|
|
* Called to blink the cursor
|
2016-12-15 10:31:30 +01:00
|
|
|
* @param ta pointer to a text area
|
2017-04-21 09:15:39 +02:00
|
|
|
* @param hide 1: hide the cursor, 0: show it
|
2016-12-15 10:31:30 +01:00
|
|
|
*/
|
2017-09-15 10:22:12 +02:00
|
|
|
static void cursor_blink_anim(lv_obj_t * ta, uint8_t show)
|
2016-12-15 10:31:30 +01:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
if(show != ext->cursor_state) {
|
|
|
|
ext->cursor_state = show == 0 ? 0 : 1;
|
2017-10-20 10:17:02 +02:00
|
|
|
if(ext->cursor_show != 0) lv_obj_invalidate(ta);
|
2016-12-18 22:07:03 +01:00
|
|
|
}
|
2016-12-15 10:31:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy function to animate char hiding in pwd mode.
|
2017-09-15 10:22:12 +02:00
|
|
|
* Does nothing, but a function is required in car hiding anim.
|
2017-07-07 16:22:24 +02:00
|
|
|
* (pwd_char_hider callback do the real job)
|
|
|
|
* @param ta unused
|
|
|
|
* @param x unused
|
|
|
|
*/
|
2017-09-15 10:22:12 +02:00
|
|
|
static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x)
|
2017-07-07 16:22:24 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide all characters (convert them to '*')
|
|
|
|
* @param ta: pointer to text area object
|
|
|
|
*/
|
|
|
|
static void pwd_char_hider(lv_obj_t * ta)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
|
|
|
char * txt = lv_label_get_text(ext->label);
|
2017-09-22 09:52:53 +02:00
|
|
|
int16_t len = txt_len(txt);
|
2017-07-07 16:22:24 +02:00
|
|
|
bool refr = false;
|
|
|
|
uint16_t i;
|
2017-09-22 13:58:01 +02:00
|
|
|
for(i = 0; i < len; i++) txt[i] = '*';
|
|
|
|
|
|
|
|
txt[i] = '\0';
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2017-09-22 13:58:01 +02:00
|
|
|
if(refr != false) lv_label_set_text(ext->label, txt);
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
#endif
|