2016-09-30 15:29:00 +02:00
|
|
|
/**
|
|
|
|
* @file lv_ta.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-09-30 15:29:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2020-02-14 12:44:15 +01:00
|
|
|
#include "lv_textarea.h"
|
2020-02-14 12:36:44 +01:00
|
|
|
#if LV_USE_TEXTAREA != 0
|
|
|
|
|
2019-03-20 05:46:21 +01:00
|
|
|
#include <string.h>
|
2020-06-08 13:10:43 +02:00
|
|
|
#include "../lv_misc/lv_debug.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2018-12-30 15:02:16 +01:00
|
|
|
#include "../lv_core/lv_refr.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-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
2017-11-26 23:57:39 +01:00
|
|
|
#include "../lv_misc/lv_txt.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_math.h"
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-02-25 09:15:56 +01:00
|
|
|
#define LV_OBJX_NAME "lv_textarea"
|
2017-01-12 09:49:13 +01:00
|
|
|
|
2019-09-26 10:51:54 +02:00
|
|
|
/*Test configuration*/
|
2020-02-14 12:36:44 +01:00
|
|
|
#ifndef LV_TEXTAREA_DEF_CURSOR_BLINK_TIME
|
2020-02-26 19:48:27 +01:00
|
|
|
#define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
|
2017-01-12 09:49:13 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#ifndef LV_TEXTAREA_DEF_PWD_SHOW_TIME
|
2020-02-26 19:48:27 +01:00
|
|
|
#define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/
|
2017-07-07 16:22:24 +02:00
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#define LV_TEXTAREA_DEF_WIDTH (2 * LV_DPI)
|
|
|
|
#define LV_TEXTAREA_DEF_HEIGHT (1 * LV_DPI)
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2020-02-17 16:04:16 +01:00
|
|
|
#define LV_TEXTAREA_PWD_BULLET_UNICODE 0x2022
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_textarea_design(lv_obj_t * ta, const lv_area_t * clip_area, lv_design_mode_t mode);
|
2020-02-26 19:48:27 +01:00
|
|
|
static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area,
|
|
|
|
lv_design_mode_t mode);
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param);
|
|
|
|
static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
|
|
|
static lv_style_list_t * lv_textarea_get_style(lv_obj_t * ta, uint8_t part);
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2020-02-26 19:48:27 +01:00
|
|
|
static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show);
|
|
|
|
static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x);
|
|
|
|
static void pwd_char_hider_anim_ready(lv_anim_t * a);
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-07-07 16:22:24 +02:00
|
|
|
static void pwd_char_hider(lv_obj_t * ta);
|
2018-08-04 08:46:44 +02:00
|
|
|
static bool char_is_accepted(lv_obj_t * ta, uint32_t c);
|
2018-12-30 15:02:16 +01:00
|
|
|
static void refr_cursor_area(lv_obj_t * ta);
|
2019-06-06 06:05:40 +02:00
|
|
|
static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_indev_t * click_source);
|
2020-07-22 16:28:03 +02:00
|
|
|
static lv_res_t insert_handler(lv_obj_t * ta, const char * txt);
|
2016-09-30 15:29:00 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_design_cb_t ancestor_design;
|
|
|
|
static lv_design_cb_t scrl_design;
|
|
|
|
static lv_signal_cb_t ancestor_signal;
|
|
|
|
static lv_signal_cb_t scrl_signal;
|
2019-03-20 05:46:21 +01:00
|
|
|
static const char * ta_insert_replace;
|
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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("text area create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/*Create the ancestor object*/
|
2020-02-13 06:56:14 +01:00
|
|
|
lv_obj_t * ta = lv_page_create(par, copy);
|
|
|
|
LV_ASSERT_MEM(ta);
|
|
|
|
if(ta == NULL) return NULL;
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2020-02-13 06:56:14 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(ta);
|
|
|
|
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(ta);
|
2020-06-16 12:03:32 +02:00
|
|
|
if(scrl_signal == NULL) scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrollable(ta));
|
|
|
|
if(scrl_design == NULL) scrl_design = lv_obj_get_design_cb(lv_page_get_scrollable(ta));
|
2017-11-05 14:12:50 +01:00
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/*Allocate the object type specific extended data*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_allocate_ext_attr(ta, sizeof(lv_textarea_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-02-13 06:56:14 +01:00
|
|
|
lv_obj_del(ta);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->pwd_mode = 0;
|
|
|
|
ext->pwd_tmp = NULL;
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->pwd_show_time = LV_TEXTAREA_DEF_PWD_SHOW_TIME;
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->accapted_chars = NULL;
|
|
|
|
ext->max_length = 0;
|
2020-01-10 11:10:07 +01:00
|
|
|
ext->cursor.state = 1;
|
|
|
|
ext->cursor.hidden = 0;
|
2020-02-14 12:36:44 +01:00
|
|
|
ext->cursor.blink_time = LV_TEXTAREA_DEF_CURSOR_BLINK_TIME;
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->cursor.pos = 0;
|
2019-06-14 16:04:15 +02:00
|
|
|
ext->cursor.click_pos = 1;
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->cursor.valid_x = 0;
|
|
|
|
ext->one_line = 0;
|
2019-06-16 14:41:58 -04:00
|
|
|
#if LV_LABEL_TEXT_SEL
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->text_sel_en = 0;
|
2019-06-16 14:41:58 -04:00
|
|
|
#endif
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->label = NULL;
|
2020-02-25 09:15:56 +01:00
|
|
|
ext->placeholder_txt = NULL;
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_init(&ext->cursor.style);
|
2020-02-25 09:15:56 +01:00
|
|
|
lv_style_list_init(&ext->style_placeholder);
|
2020-01-07 23:43:57 +01:00
|
|
|
|
2019-05-31 08:48:36 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->pwd_show_time = 0;
|
2019-05-25 16:27:36 +02:00
|
|
|
ext->cursor.blink_time = 0;
|
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_signal_cb(ta, lv_textarea_signal);
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_obj_set_signal_cb(lv_page_get_scrollable(ta), lv_textarea_scrollable_signal);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_design_cb(ta, lv_textarea_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) {
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_page_set_scrollable_fit2(ta, LV_FIT_PARENT, LV_FIT_TIGHT);
|
2019-02-24 06:24:36 +01:00
|
|
|
|
2020-02-13 06:56:14 +01:00
|
|
|
ext->label = lv_label_create(ta, NULL);
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_design_cb(ext->page.scrl, lv_textarea_scrollable_design);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_text(ext->label, "Text area");
|
|
|
|
lv_obj_set_click(ext->label, false);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_size(ta, LV_TEXTAREA_DEF_WIDTH, LV_TEXTAREA_DEF_HEIGHT);
|
2020-07-27 17:46:06 +02:00
|
|
|
lv_textarea_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_DRAG);
|
2020-02-13 06:56:14 +01:00
|
|
|
|
2020-04-21 11:36:05 +02:00
|
|
|
lv_obj_reset_style_list(ta, LV_PAGE_PART_SCROLLABLE);
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_theme_apply(ta, LV_THEME_TEXTAREA);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing object*/
|
|
|
|
else {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_design_cb(ext->page.scrl, lv_textarea_scrollable_design);
|
|
|
|
lv_textarea_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2020-02-13 06:56:14 +01:00
|
|
|
ext->label = lv_label_create(ta, copy_ext->label);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->pwd_mode = copy_ext->pwd_mode;
|
|
|
|
ext->accapted_chars = copy_ext->accapted_chars;
|
|
|
|
ext->max_length = copy_ext->max_length;
|
|
|
|
ext->cursor.pos = copy_ext->cursor.pos;
|
|
|
|
ext->cursor.valid_x = copy_ext->cursor.valid_x;
|
2020-02-15 00:33:26 +01:00
|
|
|
ext->cursor.hidden = copy_ext->cursor.hidden;
|
2019-09-20 16:31:12 +02:00
|
|
|
|
2020-02-13 06:56:14 +01:00
|
|
|
lv_style_list_copy(&ext->cursor.style, ©_ext->cursor.style);
|
2020-02-25 09:15:56 +01:00
|
|
|
lv_style_list_copy(&ext->style_placeholder, ©_ext->style_placeholder);
|
2020-02-13 06:56:14 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
if(ext->pwd_mode != 0) pwd_char_hider(ta);
|
2019-09-20 16:31:12 +02:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
if(copy_ext->placeholder_txt) {
|
|
|
|
lv_textarea_set_placeholder_text(ta, copy_ext->placeholder_txt);
|
|
|
|
}
|
2019-09-20 16:31:12 +02:00
|
|
|
|
|
|
|
if(copy_ext->pwd_tmp) {
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t len = _lv_mem_get_size(copy_ext->pwd_tmp);
|
2019-09-20 16:31:12 +02:00
|
|
|
ext->pwd_tmp = lv_mem_alloc(len);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2019-09-20 16:31:12 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return NULL;
|
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_memcpy(ext->pwd_tmp, copy_ext->pwd_tmp, len);
|
2019-09-20 16:31:12 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
if(copy_ext->one_line) lv_textarea_set_one_line(ta, true);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-01-08 13:06:41 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2020-08-02 11:36:27 +02:00
|
|
|
lv_obj_refresh_style(ta, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
2017-11-27 17:48:54 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-05-25 16:27:36 +02:00
|
|
|
if(ext->cursor.blink_time) {
|
|
|
|
/*Create a cursor blinker animation*/
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
lv_anim_t a;
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)cursor_blink_anim);
|
|
|
|
lv_anim_set_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_playback_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_values(&a, 0, 1);
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_set_path(&a, &path);
|
|
|
|
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_start(&a);
|
2019-05-25 16:27:36 +02:00
|
|
|
}
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("text area created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2020-02-13 06:56:14 +01:00
|
|
|
return 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
|
|
|
/**
|
2018-08-09 23:37:00 +02:00
|
|
|
* Insert a character to the current cursor position.
|
2020-06-29 20:46:49 +02:00
|
|
|
* To add a wide char, e.g. 'Á' use `_lv_txt_encoded_conv_wc('Á')`
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param ta pointer to a text area object
|
2018-08-09 23:37:00 +02:00
|
|
|
* @param c a character (e.g. 'a')
|
2016-10-04 09:45:39 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_add_char(lv_obj_t * ta, uint32_t c)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2016-10-01 00:25:10 +02:00
|
|
|
|
2020-07-07 09:36:59 +02:00
|
|
|
const char * letter_buf;
|
2020-07-01 10:08:45 -03:00
|
|
|
|
|
|
|
uint32_t u32_buf[2];
|
|
|
|
u32_buf[0] = c;
|
|
|
|
u32_buf[1] = 0;
|
2020-07-07 09:36:59 +02:00
|
|
|
|
|
|
|
letter_buf = (char *)&u32_buf;
|
2020-07-01 10:08:45 -03:00
|
|
|
|
|
|
|
#if LV_BIG_ENDIAN_SYSTEM
|
2020-07-07 09:36:59 +02:00
|
|
|
if(c != 0) while(*letter_buf == 0) ++letter_buf;
|
2020-07-01 10:08:45 -03:00
|
|
|
#endif
|
2019-03-20 05:46:21 +01:00
|
|
|
|
2020-07-22 16:28:03 +02:00
|
|
|
lv_res_t res = insert_handler(ta, letter_buf);
|
|
|
|
if(res != LV_RES_OK) return;
|
2020-08-04 10:07:29 +02:00
|
|
|
|
2019-01-28 08:55:57 +01:00
|
|
|
if(ext->one_line && (c == '\n' || c == '\r')) {
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("Text area: line break ignored in one-line mode");
|
|
|
|
return;
|
2018-07-25 19:36:53 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t c_uni = _lv_txt_encoded_next((const char *)&c, NULL);
|
2018-08-09 23:37:00 +02:00
|
|
|
|
|
|
|
if(char_is_accepted(ta, c_uni) == false) {
|
2019-04-04 07:15:40 +02:00
|
|
|
LV_LOG_INFO("Character is no accepted by the text area (too long text or not in the "
|
|
|
|
"accepted list)");
|
2018-10-05 17:22:49 +02:00
|
|
|
return;
|
2018-08-04 08:46:44 +02:00
|
|
|
}
|
2020-08-04 10:07:29 +02:00
|
|
|
|
2018-08-04 08:46:44 +02:00
|
|
|
|
2019-06-06 23:44:30 +02:00
|
|
|
/*If a new line was added it shouldn't show edge flash effect*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool edge_flash_en = lv_textarea_get_edge_flash(ta);
|
|
|
|
lv_textarea_set_edge_flash(ta, false);
|
2018-11-24 20:31:06 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
/*If the textarea is empty, invalidate it to hide the placeholder*/
|
|
|
|
if(ext->placeholder_txt) {
|
|
|
|
const char * txt = lv_label_get_text(ext->label);
|
|
|
|
if(txt[0] == '\0') lv_obj_invalidate(ta);
|
|
|
|
}
|
|
|
|
|
2020-07-01 10:08:45 -03:00
|
|
|
lv_label_ins_text(ext->label, ext->cursor.pos, letter_buf); /*Insert the character*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta); /*Clear selection*/
|
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
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2018-09-25 23:33:17 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return;
|
2018-07-25 14:43:46 +02:00
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, (const char *)letter_buf);
|
2017-08-29 15:08:18 +02:00
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-27 17:48:54 +01:00
|
|
|
/*Auto hide characters*/
|
2020-09-11 14:25:33 +02:00
|
|
|
if(ext->pwd_show_time == 0) {
|
|
|
|
pwd_char_hider(ta);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
|
|
|
lv_anim_t a;
|
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)pwd_char_hider_anim);
|
|
|
|
lv_anim_set_time(&a, ext->pwd_show_time);
|
|
|
|
lv_anim_set_values(&a, 0, 1);
|
|
|
|
lv_anim_set_path(&a, &path);
|
|
|
|
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
|
|
|
|
lv_anim_start(&a);
|
2020-09-15 11:14:32 +02:00
|
|
|
}
|
2019-05-25 16:27:36 +02:00
|
|
|
|
2018-08-04 09:04:37 +02:00
|
|
|
#else
|
|
|
|
pwd_char_hider(ta);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 15:08:18 +02:00
|
|
|
/*Move the cursor after the new character*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, lv_textarea_get_cursor_pos(ta) + 1);
|
2018-11-24 20:31:06 +01:00
|
|
|
|
|
|
|
/*Revert the original edge flash state*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_edge_flash(ta, edge_flash_en);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2019-03-20 05:46:21 +01:00
|
|
|
lv_event_send(ta, LV_EVENT_VALUE_CHANGED, NULL);
|
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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_add_text(lv_obj_t * ta, const char * txt)
|
2016-10-01 00:25:10 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_NULL(txt);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-05 14:12:50 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
2018-07-25 21:52:50 +02:00
|
|
|
|
2018-08-09 23:37:00 +02:00
|
|
|
/*Add the character one-by-one if not all characters are accepted or there is character limit.*/
|
2020-02-14 12:36:44 +01:00
|
|
|
if(lv_textarea_get_accepted_chars(ta) || lv_textarea_get_max_length(ta)) {
|
2018-10-05 17:22:49 +02:00
|
|
|
uint32_t i = 0;
|
|
|
|
while(txt[i] != '\0') {
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t c = _lv_txt_encoded_next(txt, &i);
|
|
|
|
lv_textarea_add_char(ta, _lv_txt_unicode_to_encoded(c));
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
|
|
|
return;
|
2018-08-04 08:46:44 +02:00
|
|
|
}
|
2020-08-04 10:07:29 +02:00
|
|
|
|
2020-07-22 16:28:03 +02:00
|
|
|
lv_res_t res = insert_handler(ta, txt);
|
|
|
|
if(res != LV_RES_OK) return;
|
|
|
|
|
2019-06-06 23:44:30 +02:00
|
|
|
/*If a new line was added it shouldn't show edge flash effect*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool edge_flash_en = lv_textarea_get_edge_flash(ta);
|
|
|
|
lv_textarea_set_edge_flash(ta, false);
|
2018-11-24 20:31:06 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
/*If the textarea is empty, invalidate it to hide the placeholder*/
|
|
|
|
if(ext->placeholder_txt) {
|
2020-03-10 08:34:07 +01:00
|
|
|
const char * txt_act = lv_label_get_text(ext->label);
|
|
|
|
if(txt_act[0] == '\0') lv_obj_invalidate(ta);
|
2020-02-25 09:15:56 +01:00
|
|
|
}
|
|
|
|
|
2018-08-04 08:46:44 +02:00
|
|
|
/*Insert the text*/
|
2017-11-17 15:43:08 +01:00
|
|
|
lv_label_ins_text(ext->label, ext->cursor.pos, txt);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta);
|
2018-07-25 19:36:53 +02:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2017-11-23 21:28:36 +01:00
|
|
|
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + strlen(txt) + 1);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return;
|
2017-09-22 13:58:01 +02:00
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, txt);
|
2017-08-29 15:08:18 +02:00
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
/*Auto hide characters*/
|
2020-09-11 14:25:33 +02:00
|
|
|
if(ext->pwd_show_time == 0) {
|
|
|
|
pwd_char_hider(ta);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
|
|
|
lv_anim_t a;
|
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)pwd_char_hider_anim);
|
|
|
|
lv_anim_set_time(&a, ext->pwd_show_time);
|
|
|
|
lv_anim_set_values(&a, 0, 1);
|
|
|
|
lv_anim_set_path(&a, &path);
|
|
|
|
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
|
|
|
|
lv_anim_start(&a);
|
2020-09-15 11:14:32 +02:00
|
|
|
}
|
2018-08-04 09:04:37 +02:00
|
|
|
#else
|
|
|
|
pwd_char_hider(ta);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
2017-08-29 15:08:18 +02:00
|
|
|
|
|
|
|
/*Move the cursor after the new text*/
|
2020-05-13 14:11:16 +02:00
|
|
|
lv_textarea_set_cursor_pos(ta, lv_textarea_get_cursor_pos(ta) + _lv_txt_get_encoded_length(txt));
|
2018-11-24 20:31:06 +01:00
|
|
|
|
|
|
|
/*Revert the original edge flash state*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_edge_flash(ta, edge_flash_en);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2019-03-20 05:46:21 +01:00
|
|
|
lv_event_send(ta, LV_EVENT_VALUE_CHANGED, NULL);
|
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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_del_char(lv_obj_t * ta)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t cur_pos = ext->cursor.pos;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
if(cur_pos == 0) return;
|
|
|
|
|
2019-04-08 14:36:20 +02:00
|
|
|
char del_buf[2] = {LV_KEY_DEL, '\0'};
|
2019-03-20 05:46:21 +01:00
|
|
|
|
2020-07-22 16:28:03 +02:00
|
|
|
lv_res_t res = insert_handler(ta, del_buf);
|
|
|
|
if(res != LV_RES_OK) return;
|
2019-03-20 05:46:21 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
char * label_txt = lv_label_get_text(ext->label);
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Delete a character*/
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_txt_cut(label_txt, ext->cursor.pos - 1, 1);
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Refresh the label*/
|
|
|
|
lv_label_set_text(ext->label, label_txt);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
|
|
|
|
/*If the textarea became empty, invalidate it to hide the placeholder*/
|
|
|
|
if(ext->placeholder_txt) {
|
|
|
|
const char * txt = lv_label_get_text(ext->label);
|
|
|
|
if(txt[0] == '\0') lv_obj_invalidate(ta);
|
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Don't let 'width == 0' because cursor will not be visible*/
|
|
|
|
if(lv_obj_get_width(ext->label) == 0) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t border_width = lv_obj_get_style_border_width(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_obj_set_width(ext->label, border_width == 0 ? 1 : border_width);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ext->pwd_mode != 0) {
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t byte_pos = _lv_txt_encoded_get_byte_id(ext->pwd_tmp, ext->cursor.pos - 1);
|
2020-06-08 13:23:41 +02:00
|
|
|
_lv_txt_cut(ext->pwd_tmp, ext->cursor.pos - 1, _lv_txt_encoded_size(&ext->pwd_tmp[byte_pos]));
|
2019-03-28 06:11:50 +01:00
|
|
|
|
2017-11-23 21:28:36 +01:00
|
|
|
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Move the cursor to the place of the deleted character*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, ext->cursor.pos - 1);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2019-03-19 06:30:05 +01:00
|
|
|
lv_event_send(ta, LV_EVENT_VALUE_CHANGED, NULL);
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2019-02-01 23:53:09 +01:00
|
|
|
/**
|
|
|
|
* Delete the right character from the current cursor position
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_del_char_forward(lv_obj_t * ta)
|
2019-02-01 23:53:09 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t cp = lv_textarea_get_cursor_pos(ta);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, cp + 1);
|
|
|
|
if(cp != lv_textarea_get_cursor_pos(ta)) lv_textarea_del_char(ta);
|
2019-02-01 23:53:09 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* 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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_text(lv_obj_t * ta, const char * txt)
|
2016-12-15 10:31:30 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_NULL(txt);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2019-03-27 17:22:44 -04:00
|
|
|
/*Clear the existing selection*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta);
|
2019-03-27 17:22:44 -04:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
/*Add the character one-by-one if not all characters are accepted or there is character limit.*/
|
2020-02-14 12:36:44 +01:00
|
|
|
if(lv_textarea_get_accepted_chars(ta) || lv_textarea_get_max_length(ta)) {
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_label_set_text(ext->label, "");
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, LV_TEXTAREA_CURSOR_LAST);
|
2020-01-11 16:02:23 +01:00
|
|
|
if(ext->pwd_mode != 0) {
|
|
|
|
ext->pwd_tmp[0] = '\0'; /*Clear the password too*/
|
|
|
|
}
|
2018-10-05 17:22:49 +02:00
|
|
|
uint32_t i = 0;
|
|
|
|
while(txt[i] != '\0') {
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t c = _lv_txt_encoded_next(txt, &i);
|
|
|
|
lv_textarea_add_char(ta, _lv_txt_unicode_to_encoded(c));
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_label_set_text(ext->label, txt);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, LV_TEXTAREA_CURSOR_LAST);
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2018-08-09 23:37:00 +02:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
|
|
|
|
/*If the textarea is empty, invalidate it to hide the placeholder*/
|
|
|
|
if(ext->placeholder_txt) {
|
2020-03-10 08:34:07 +01:00
|
|
|
const char * txt_act = lv_label_get_text(ext->label);
|
|
|
|
if(txt_act[0] == '\0') lv_obj_invalidate(ta);
|
2020-02-25 09:15:56 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:37:00 +02:00
|
|
|
/*Don't let 'width == 0' because the cursor will not be visible*/
|
2018-06-19 09:49:58 +02:00
|
|
|
if(lv_obj_get_width(ext->label) == 0) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t border_width = lv_obj_get_style_border_width(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_obj_set_width(ext->label, border_width == 0 ? 1 : border_width);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2017-08-16 11:28:04 +02:00
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2017-11-23 21:28:36 +01:00
|
|
|
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(txt) + 1);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2018-07-25 14:43:46 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return;
|
2017-08-29 15:08:18 +02:00
|
|
|
strcpy(ext->pwd_tmp, txt);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
/*Auto hide characters*/
|
2020-09-11 14:25:33 +02:00
|
|
|
if(ext->pwd_show_time == 0) {
|
|
|
|
pwd_char_hider(ta);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
|
|
|
lv_anim_t a;
|
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)pwd_char_hider_anim);
|
|
|
|
lv_anim_set_time(&a, ext->pwd_show_time);
|
|
|
|
lv_anim_set_values(&a, 0, 1);
|
|
|
|
lv_anim_set_path(&a, &path);
|
|
|
|
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
|
|
|
|
lv_anim_start(&a);
|
2020-09-15 11:14:32 +02:00
|
|
|
}
|
2018-08-04 09:04:37 +02:00
|
|
|
#else
|
|
|
|
pwd_char_hider(ta);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2019-03-20 05:46:21 +01:00
|
|
|
lv_event_send(ta, LV_EVENT_VALUE_CHANGED, NULL);
|
2019-02-02 01:26:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-25 09:15:56 +01:00
|
|
|
* Set the placeholder_txt text of a text area
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param ta pointer to a text area
|
|
|
|
* @param txt pointer to the text
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_placeholder_text(lv_obj_t * ta, const char * txt)
|
2019-02-02 01:26:52 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_NULL(txt);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
size_t txt_len = strlen(txt);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
if(txt_len == 0) {
|
|
|
|
if(ext->placeholder_txt) {
|
|
|
|
lv_mem_free(ext->placeholder_txt);
|
|
|
|
ext->placeholder_txt = NULL;
|
2019-02-03 01:33:21 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-14 17:03:25 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
/*Allocate memory for the placeholder_txt text*/
|
|
|
|
if(ext->placeholder_txt == NULL) {
|
|
|
|
ext->placeholder_txt = lv_mem_alloc(txt_len + 1);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-25 09:15:56 +01:00
|
|
|
ext->placeholder_txt = lv_mem_realloc(ext->placeholder_txt, txt_len + 1);
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
}
|
|
|
|
LV_ASSERT_MEM(ext->placeholder_txt);
|
|
|
|
if(ext->placeholder_txt == NULL) {
|
|
|
|
LV_LOG_ERROR("lv_textarea_set_placeholder_text: couldn't allocate memory for placeholder");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(ext->placeholder_txt, txt);
|
|
|
|
}
|
2019-11-02 21:34:41 +01:00
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
lv_obj_invalidate(ta);
|
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
|
2020-02-14 12:36:44 +01:00
|
|
|
* LV_TEXTAREA_CURSOR_LAST: go after the last character
|
2016-10-04 09:45:39 +02:00
|
|
|
*/
|
2020-06-01 17:51:47 +01:00
|
|
|
void lv_textarea_set_cursor_pos(lv_obj_t * ta, int32_t pos)
|
2016-10-01 00:25:10 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-06-01 22:56:10 +02:00
|
|
|
if((uint32_t)ext->cursor.pos == (uint32_t)pos) return;
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t len = _lv_txt_get_encoded_length(lv_label_get_text(ext->label));
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(pos < 0) pos = len + pos;
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2020-06-01 22:56:10 +02:00
|
|
|
if(pos > (int32_t)len || pos == LV_TEXTAREA_CURSOR_LAST) pos = len;
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->cursor.pos = pos;
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Position the label to make the cursor visible*/
|
|
|
|
lv_obj_t * label_par = lv_obj_get_parent(ext->label);
|
|
|
|
lv_point_t cur_pos;
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_BG);
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_area_t label_cords;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_area_t ta_cords;
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_label_get_letter_pos(ext->label, pos, &cur_pos);
|
|
|
|
lv_obj_get_coords(ta, &ta_cords);
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_get_coords(ext->label, &label_cords);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Check the top*/
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2018-06-19 09:49:58 +02:00
|
|
|
if(lv_obj_get_y(label_par) + cur_pos.y < 0) {
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_y(label_par, -cur_pos.y + top);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Check the bottom*/
|
2020-01-03 11:06:11 +01:00
|
|
|
if(label_cords.y1 + cur_pos.y + font_h + bottom > ta_cords.y2) {
|
|
|
|
lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + font_h + top + bottom));
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
/*Check the left (use the font_h as general unit)*/
|
2017-08-16 11:28:04 +02:00
|
|
|
if(lv_obj_get_x(label_par) + cur_pos.x < font_h) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_set_x(label_par, -cur_pos.x + font_h);
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_BG);
|
2017-08-16 11:28:04 +02:00
|
|
|
/*Check the right (use the font_h as general unit)*/
|
2020-01-03 11:06:11 +01:00
|
|
|
if(label_cords.x1 + cur_pos.x + font_h + right > ta_cords.x2) {
|
|
|
|
lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) + font_h + left + right));
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
2016-09-30 15:29:00 +02:00
|
|
|
|
2017-11-17 15:43:08 +01:00
|
|
|
ext->cursor.valid_x = cur_pos.x;
|
2017-11-05 14:12:50 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-05-25 16:27:36 +02:00
|
|
|
if(ext->cursor.blink_time) {
|
|
|
|
/*Reset cursor blink animation*/
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
lv_anim_t a;
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)cursor_blink_anim);
|
|
|
|
lv_anim_set_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_playback_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_values(&a, 1, 0);
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_set_path(&a, &path);
|
|
|
|
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_start(&a);
|
2019-05-25 16:27:36 +02:00
|
|
|
}
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-09-15 10:22:12 +02:00
|
|
|
|
2018-12-30 15:02:16 +01:00
|
|
|
refr_cursor_area(ta);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
/**
|
2020-01-10 06:52:57 +01:00
|
|
|
* Hide/Unhide the cursor.
|
2017-09-15 10:22:12 +02:00
|
|
|
* @param ta pointer to a text area object
|
2020-01-10 06:52:57 +01:00
|
|
|
* @param hide: true: hide the cursor
|
2017-09-15 10:22:12 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_cursor_hidden(lv_obj_t * ta, bool hide)
|
2017-09-15 10:22:12 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2020-01-10 06:52:57 +01:00
|
|
|
ext->cursor.hidden = hide ? 1 : 0;
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
refr_cursor_area(ta);
|
2017-09-15 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 16:04:15 +02:00
|
|
|
/**
|
|
|
|
* Enable/Disable the positioning of the the cursor by clicking the text on the text area.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param en true: enable click positions; false: disable
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_cursor_click_pos(lv_obj_t * ta, bool en)
|
2019-06-14 16:04:15 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-06-14 16:04:15 +02:00
|
|
|
ext->cursor.click_pos = en ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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
|
2018-12-22 19:45:55 +01:00
|
|
|
* @param en true: enable, false: disable
|
2017-07-07 16:22:24 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_pwd_mode(lv_obj_t * ta, bool en)
|
2017-07-07 16:22:24 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-12-22 19:45:55 +01:00
|
|
|
if(ext->pwd_mode == en) return;
|
2017-07-07 16:22:24 +02:00
|
|
|
|
|
|
|
/*Pwd mode is now enabled*/
|
2018-12-22 19:45:55 +01:00
|
|
|
if(ext->pwd_mode == 0 && en != false) {
|
2019-04-04 07:15:40 +02:00
|
|
|
char * txt = lv_label_get_text(ext->label);
|
2019-12-02 12:20:01 +01:00
|
|
|
size_t len = strlen(txt);
|
2017-11-23 21:28:36 +01:00
|
|
|
ext->pwd_tmp = lv_mem_alloc(len + 1);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext->pwd_tmp);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext->pwd_tmp == NULL) return;
|
|
|
|
|
2017-07-07 16:22:24 +02:00
|
|
|
strcpy(ext->pwd_tmp, txt);
|
|
|
|
|
2020-02-17 16:04:16 +01:00
|
|
|
pwd_char_hider(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
/*Pwd mode is now disabled*/
|
2018-12-22 19:45:55 +01:00
|
|
|
else if(ext->pwd_mode == 1 && en == false) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_clear_selection(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
lv_label_set_text(ext->label, ext->pwd_tmp);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_mem_free(ext->pwd_tmp);
|
2017-07-07 16:22:24 +02:00
|
|
|
ext->pwd_tmp = NULL;
|
|
|
|
}
|
|
|
|
|
2018-12-22 19:45:55 +01:00
|
|
|
ext->pwd_mode = en == false ? 0 : 1;
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
refr_cursor_area(ta);
|
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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_one_line(lv_obj_t * ta, bool en)
|
2017-08-16 11:28:04 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->one_line == en) return;
|
2020-02-05 10:01:44 -05:00
|
|
|
lv_label_align_t old_align = lv_label_get_align(ext->label);
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2018-09-25 16:21:31 +02:00
|
|
|
if(en) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_BG);
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2017-08-16 11:28:04 +02:00
|
|
|
|
2017-10-02 16:50:34 +02:00
|
|
|
ext->one_line = 1;
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_page_set_scrollable_fit2(ta, LV_FIT_MAX, LV_FIT_PARENT);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_height(ta, font_h + top + bottom);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND);
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_obj_set_pos(lv_page_get_scrollable(ta), left, top);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_BG);
|
2017-10-02 16:50:34 +02:00
|
|
|
ext->one_line = 0;
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_page_set_scrollable_fit2(ta, LV_FIT_PARENT, LV_FIT_TIGHT);
|
2017-08-16 11:28:04 +02:00
|
|
|
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
|
2019-02-03 01:33:21 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_height(ta, LV_TEXTAREA_DEF_HEIGHT);
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_obj_set_pos(lv_page_get_scrollable(ta), left, top);
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
2018-12-30 15:02:16 +01:00
|
|
|
|
2020-02-04 08:16:41 -05:00
|
|
|
/* `refr_cursor_area` is called at the end of lv_ta_set_text_align */
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_textarea_set_text_align(ta, old_align);
|
2017-08-16 11:28:04 +02:00
|
|
|
}
|
|
|
|
|
2018-09-25 16:21:31 +02:00
|
|
|
/**
|
|
|
|
* Set the alignment of the text area.
|
|
|
|
* In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`.
|
|
|
|
* This function should be called if the size of text area changes.
|
|
|
|
* @param ta pointer to a text are object
|
|
|
|
* @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT)
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_text_align(lv_obj_t * ta, lv_label_align_t align)
|
2018-09-25 16:21:31 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
|
|
|
lv_obj_t * label = lv_textarea_get_label(ta);
|
2018-09-25 16:21:31 +02:00
|
|
|
if(!ext->one_line) {
|
|
|
|
lv_label_set_align(label, align);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-09-25 16:21:31 +02:00
|
|
|
/*Normal left align. Just let the text expand*/
|
|
|
|
if(align == LV_LABEL_ALIGN_LEFT) {
|
|
|
|
lv_label_set_long_mode(label, LV_LABEL_LONG_EXPAND);
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_page_set_scrollable_fit2(ta, LV_FIT_MAX, LV_FIT_PARENT);
|
2018-09-25 16:21:31 +02:00
|
|
|
lv_label_set_align(label, align);
|
|
|
|
}
|
|
|
|
/*Else use fix label width equal to the Text area width*/
|
|
|
|
else {
|
|
|
|
lv_label_set_long_mode(label, LV_LABEL_LONG_CROP);
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_set_width(label, lv_page_get_width_fit(ta));
|
2020-03-17 07:15:56 +01:00
|
|
|
lv_label_set_align(label, align);
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_page_set_scrollable_fit2(ta, LV_FIT_PARENT, LV_FIT_PARENT);
|
2018-09-25 16:21:31 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
refr_cursor_area(ta);
|
2018-09-25 16:21:31 +02:00
|
|
|
}
|
2018-08-04 08:46:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a list of characters. Only these characters will be accepted by the text area
|
|
|
|
* @param ta pointer to Text Area
|
|
|
|
* @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789"
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_accepted_chars(lv_obj_t * ta, const char * list)
|
2018-08-04 08:46:44 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-08-04 08:46:44 +02:00
|
|
|
|
|
|
|
ext->accapted_chars = list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set max length of a Text Area.
|
|
|
|
* @param ta pointer to Text Area
|
2020-02-14 12:36:44 +01:00
|
|
|
* @param num the maximal number of characters can be added (`lv_textarea_set_text` ignores it)
|
2018-08-04 08:46:44 +02:00
|
|
|
*/
|
2020-06-01 17:51:47 +01:00
|
|
|
void lv_textarea_set_max_length(lv_obj_t * ta, uint32_t num)
|
2018-08-04 08:46:44 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-08-04 08:46:44 +02:00
|
|
|
|
|
|
|
ext->max_length = num;
|
|
|
|
}
|
|
|
|
|
2019-03-20 05:46:21 +01:00
|
|
|
/**
|
|
|
|
* In `LV_EVENT_INSERT` the text which planned to be inserted can be replaced by an other text.
|
|
|
|
* It can be used to add automatic formatting to the text area.
|
|
|
|
* @param ta pointer to a text area.
|
|
|
|
* @param txt pointer to a new string to insert. If `""` no text will be added.
|
2019-04-04 07:15:40 +02:00
|
|
|
* The variable must be live after the `event_cb` exists. (Should be `global` or
|
|
|
|
* `static`)
|
2019-03-20 05:46:21 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_insert_replace(lv_obj_t * ta, const char * txt)
|
2019-03-20 05:46:21 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
(void)ta; /*Unused*/
|
2019-03-20 05:46:21 +01:00
|
|
|
ta_insert_replace = txt;
|
|
|
|
}
|
|
|
|
|
2019-03-27 19:17:48 -04:00
|
|
|
/**
|
|
|
|
* Enable/disable selection mode.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @param en true or false to enable/disable selection mode
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_text_sel(lv_obj_t * ta, bool en)
|
2019-04-04 07:15:40 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-04-18 07:11:43 +02:00
|
|
|
#if LV_LABEL_TEXT_SEL
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-04-18 07:11:43 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->text_sel_en = en;
|
2019-04-18 06:45:45 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
if(!en) lv_textarea_clear_selection(ta);
|
2019-04-18 07:11:43 +02:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)ta; /*Unused*/
|
|
|
|
(void)en; /*Unused*/
|
2019-04-18 07:11:43 +02:00
|
|
|
#endif
|
2019-03-27 19:17:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_pwd_show_time(lv_obj_t * ta, uint16_t time)
|
2019-05-25 16:27:36 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
|
|
|
time = 0;
|
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-05-25 16:27:36 +02:00
|
|
|
ext->pwd_show_time = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cursor blink animation time
|
|
|
|
* @param ta pointer to Text area
|
|
|
|
* @param time blink period. 0: disable blinking
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_set_cursor_blink_time(lv_obj_t * ta, uint16_t time)
|
2019-05-25 16:27:36 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
#if LV_USE_ANIMATION == 0
|
|
|
|
time = 0;
|
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-05-25 16:27:36 +02:00
|
|
|
ext->cursor.blink_time = time;
|
|
|
|
|
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
if(ext->cursor.blink_time) {
|
|
|
|
/*Reset cursor blink animation*/
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_path_t path;
|
|
|
|
lv_anim_path_init(&path);
|
|
|
|
lv_anim_path_set_cb(&path, lv_anim_path_step);
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
lv_anim_t a;
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_init(&a);
|
|
|
|
lv_anim_set_var(&a, ta);
|
|
|
|
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)cursor_blink_anim);
|
|
|
|
lv_anim_set_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_playback_time(&a, ext->cursor.blink_time);
|
|
|
|
lv_anim_set_values(&a, 1, 0);
|
2020-04-27 11:51:18 +02:00
|
|
|
lv_anim_set_path(&a, &path);
|
2020-02-19 06:18:24 +01:00
|
|
|
lv_anim_start(&a);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-01-30 05:41:24 +01:00
|
|
|
lv_anim_del(ta, (lv_anim_exec_xcb_t)cursor_blink_anim);
|
2019-05-25 16:27:36 +02:00
|
|
|
ext->cursor.state = 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ext->cursor.state = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
2018-08-04 08:46:44 +02:00
|
|
|
* Get the text of a text area. In password mode it gives the real text (not '*'s).
|
2017-06-13 14:49:41 +02:00
|
|
|
* @param ta pointer to a text area object
|
2016-10-04 09:45:39 +02:00
|
|
|
* @return pointer to the text
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_textarea_get_text(const lv_obj_t * ta)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
const char * txt;
|
|
|
|
if(ext->pwd_mode == 0) {
|
|
|
|
txt = lv_label_get_text(ext->label);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
txt = ext->pwd_tmp;
|
|
|
|
}
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
return txt;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-02 01:26:52 +01:00
|
|
|
/**
|
2020-02-25 09:15:56 +01:00
|
|
|
* Get the placeholder_txt text of a text area
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return pointer to the text
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_textarea_get_placeholder_text(lv_obj_t * ta)
|
2019-02-02 01:26:52 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-02-25 09:15:56 +01:00
|
|
|
if(ext->placeholder_txt) return ext->placeholder_txt;
|
|
|
|
else return "";
|
2019-02-02 01:26:52 +01: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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_t * lv_textarea_get_label(const lv_obj_t * ta)
|
2017-06-13 14:49:41 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_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
|
|
|
|
*/
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t lv_textarea_get_cursor_pos(const lv_obj_t * ta)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-06-19 09:49:58 +02:00
|
|
|
return ext->cursor.pos;
|
2017-04-21 09:15:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 10:22:12 +02:00
|
|
|
/**
|
2020-01-10 06:52:57 +01:00
|
|
|
* Get whether the cursor is hidden or not
|
2017-09-15 10:22:12 +02:00
|
|
|
* @param ta pointer to a text area object
|
2020-01-10 06:52:57 +01:00
|
|
|
* @return true: the cursor is hidden
|
2017-09-15 10:22:12 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_get_cursor_hidden(const lv_obj_t * ta)
|
2017-09-15 10:22:12 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-01-10 06:52:57 +01:00
|
|
|
return ext->cursor.hidden ? true : false;
|
2017-09-15 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 16:04:15 +02:00
|
|
|
/**
|
|
|
|
* Get whether the cursor click positioning is enabled or not.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return true: enable click positions; false: disable
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_get_cursor_click_pos(lv_obj_t * ta)
|
2019-06-14 16:04:15 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-06-14 16:04:15 +02:00
|
|
|
return ext->cursor.click_pos ? true : false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_get_pwd_mode(const lv_obj_t * ta)
|
2017-07-07 16:22:24 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_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
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_get_one_line(const lv_obj_t * ta)
|
2017-11-05 14:12:50 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-05 14:12:50 +01:00
|
|
|
return ext->one_line == 0 ? false : true;
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
|
2018-08-04 08:46:44 +02:00
|
|
|
/**
|
|
|
|
* Get a list of accepted characters.
|
|
|
|
* @param ta pointer to Text Area
|
|
|
|
* @return list of accented characters.
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_textarea_get_accepted_chars(lv_obj_t * ta)
|
2018-08-04 08:46:44 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-08-04 08:46:44 +02:00
|
|
|
|
|
|
|
return ext->accapted_chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set max length of a Text Area.
|
|
|
|
* @param ta pointer to Text Area
|
|
|
|
* @return the maximal number of characters to be add
|
|
|
|
*/
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t lv_textarea_get_max_length(lv_obj_t * ta)
|
2018-08-04 08:46:44 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-10-05 17:22:49 +02:00
|
|
|
return ext->max_length;
|
2018-08-04 08:46:44 +02:00
|
|
|
}
|
|
|
|
|
2019-03-27 18:36:57 -04:00
|
|
|
/**
|
|
|
|
* Find whether text is selected or not.
|
|
|
|
* @param ta Text area object
|
|
|
|
* @return whether text is selected or not
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_text_is_selected(const lv_obj_t * ta)
|
2019-04-04 07:15:40 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-04-18 07:11:43 +02:00
|
|
|
#if LV_LABEL_TEXT_SEL
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-04-18 07:11:43 +02:00
|
|
|
|
2019-10-30 10:16:06 +01:00
|
|
|
if((lv_label_get_text_sel_start(ext->label) == LV_DRAW_LABEL_NO_TXT_SEL ||
|
|
|
|
lv_label_get_text_sel_end(ext->label) == LV_DRAW_LABEL_NO_TXT_SEL)) {
|
2019-04-18 07:11:43 +02:00
|
|
|
return true;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-04-18 07:11:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)ta; /*Unused*/
|
2019-04-18 07:11:43 +02:00
|
|
|
return false;
|
|
|
|
#endif
|
2019-03-27 18:36:57 -04:00
|
|
|
}
|
|
|
|
|
2019-03-27 19:17:48 -04:00
|
|
|
/**
|
|
|
|
* Find whether selection mode is enabled.
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
* @return true: selection mode is enabled, false: disabled
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_textarea_get_text_sel_en(lv_obj_t * ta)
|
2019-04-04 07:15:40 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-04-18 07:11:43 +02:00
|
|
|
#if LV_LABEL_TEXT_SEL
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-04-18 06:45:45 +02:00
|
|
|
return ext->text_sel_en;
|
2019-04-18 07:11:43 +02:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)ta; /*Unused*/
|
2019-04-18 07:11:43 +02:00
|
|
|
return false;
|
|
|
|
#endif
|
2019-03-27 19:17:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-25 16:27:36 +02:00
|
|
|
/**
|
|
|
|
* Set how long show the password before changing it to '*'
|
|
|
|
* @param ta pointer to Text area
|
|
|
|
* @return show time in milliseconds. 0: hide immediately.
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_textarea_get_pwd_show_time(lv_obj_t * ta)
|
2019-05-25 16:27:36 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-05-25 16:27:36 +02:00
|
|
|
|
|
|
|
return ext->pwd_show_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cursor blink animation time
|
|
|
|
* @param ta pointer to Text area
|
|
|
|
* @return time blink period. 0: disable blinking
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_textarea_get_cursor_blink_time(lv_obj_t * ta)
|
2019-05-25 16:27:36 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-05-25 16:27:36 +02:00
|
|
|
return ext->cursor.blink_time;
|
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
2019-03-27 17:22:44 -04:00
|
|
|
/**
|
|
|
|
* Clear the selection on the text area.
|
|
|
|
* @param ta Text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_clear_selection(lv_obj_t * ta)
|
2019-04-04 07:15:40 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2019-04-18 07:11:43 +02:00
|
|
|
#if LV_LABEL_TEXT_SEL
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-04-04 07:15:40 +02:00
|
|
|
|
2019-10-30 10:16:06 +01:00
|
|
|
if(lv_label_get_text_sel_start(ext->label) != LV_DRAW_LABEL_NO_TXT_SEL ||
|
|
|
|
lv_label_get_text_sel_end(ext->label) != LV_DRAW_LABEL_NO_TXT_SEL) {
|
|
|
|
lv_label_set_text_sel_start(ext->label, LV_DRAW_LABEL_NO_TXT_SEL);
|
|
|
|
lv_label_set_text_sel_end(ext->label, LV_DRAW_LABEL_NO_TXT_SEL);
|
2019-04-04 07:15:40 +02:00
|
|
|
}
|
2019-04-18 07:11:43 +02:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)ta; /*Unused*/
|
2019-04-18 07:11:43 +02:00
|
|
|
#endif
|
2019-03-27 17:22:44 -04:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Move the cursor one character right
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_cursor_right(lv_obj_t * ta)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t cp = lv_textarea_get_cursor_pos(ta);
|
2017-11-15 15:50:33 +01:00
|
|
|
cp++;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, cp);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one character left
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_cursor_left(lv_obj_t * ta)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t cp = lv_textarea_get_cursor_pos(ta);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(cp > 0) {
|
2017-11-15 15:50:33 +01:00
|
|
|
cp--;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, cp);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one line down
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_cursor_down(lv_obj_t * ta)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_point_t pos;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*Get the position of the current letter*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_label_get_letter_pos(ext->label, lv_textarea_get_cursor_pos(ta), &pos);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*Increment the y with one line and keep the valid x*/
|
2020-01-03 11:06:11 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_BG);
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
|
|
|
pos.y += font_h + line_space + 1;
|
2017-11-17 15:43:08 +01:00
|
|
|
pos.x = ext->cursor.valid_x;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*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*/
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2020-06-15 17:12:48 +03:00
|
|
|
lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid position */
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, new_cur_pos);
|
2017-11-17 15:43:08 +01:00
|
|
|
ext->cursor.valid_x = cur_valid_x_tmp;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor one line up
|
|
|
|
* @param ta pointer to a text area object
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_textarea_cursor_up(lv_obj_t * ta)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_point_t pos;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*Get the position of the current letter*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_label_get_letter_pos(ext->label, lv_textarea_get_cursor_pos(ta), &pos);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*Decrement the y with one line and keep the valid x*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_BG);
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2020-01-03 11:06:11 +01:00
|
|
|
pos.y -= font_h + line_space - 1;
|
2017-11-17 15:43:08 +01:00
|
|
|
pos.x = ext->cursor.valid_x;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
|
|
|
/*Get the letter index on the new cursor position and set it*/
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid position */
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, new_cur_pos);
|
2017-11-17 15:43:08 +01:00
|
|
|
ext->cursor.valid_x = cur_valid_x_tmp;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
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
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2016-09-30 15:29:00 +02:00
|
|
|
* @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
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2016-09-30 15:29:00 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_textarea_design(lv_obj_t * ta, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2016-09-30 15:29:00 +02:00
|
|
|
{
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
2019-09-06 19:53:39 +02:00
|
|
|
return ancestor_design(ta, clip_area, mode);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Draw the object*/
|
2019-09-06 19:53:39 +02:00
|
|
|
ancestor_design(ta, clip_area, mode);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2019-09-06 19:53:39 +02:00
|
|
|
ancestor_design(ta, clip_area, mode);
|
2016-09-30 15:29:00 +02:00
|
|
|
}
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
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
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area 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'
|
|
|
|
*/
|
2020-02-26 19:48:27 +01:00
|
|
|
static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area,
|
|
|
|
lv_design_mode_t mode)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
2019-09-06 19:53:39 +02:00
|
|
|
return scrl_design(scrl, clip_area, mode);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Draw the object*/
|
2019-09-06 19:53:39 +02:00
|
|
|
scrl_design(scrl, clip_area, mode);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
2019-09-06 19:53:39 +02:00
|
|
|
scrl_design(scrl, clip_area, mode);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * ta = lv_obj_get_parent(scrl);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-02-25 09:15:56 +01:00
|
|
|
const char * txt = lv_label_get_text(ext->label);
|
|
|
|
|
|
|
|
/*Draw the place holder*/
|
|
|
|
if(txt[0] == '\0' && ext->placeholder_txt && ext->placeholder_txt[0] != 0) {
|
|
|
|
lv_draw_label_dsc_t ph_dsc;
|
|
|
|
lv_draw_label_dsc_init(&ph_dsc);
|
|
|
|
lv_obj_init_draw_label_dsc(ta, LV_TEXTAREA_PART_PLACEHOLDER, &ph_dsc);
|
|
|
|
switch(lv_label_get_align(ext->label)) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_LABEL_ALIGN_CENTER:
|
|
|
|
ph_dsc.flag |= LV_TXT_FLAG_CENTER;
|
|
|
|
break;
|
|
|
|
case LV_LABEL_ALIGN_RIGHT:
|
|
|
|
ph_dsc.flag |= LV_TXT_FLAG_RIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-02-25 09:15:56 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:12:06 +02:00
|
|
|
if(ext->one_line) ph_dsc.flag |= LV_TXT_FLAG_EXPAND;
|
|
|
|
|
2020-02-25 09:15:56 +01:00
|
|
|
lv_draw_label(&scrl->coords, clip_area, &ph_dsc, ext->placeholder_txt, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Draw the cursor*/
|
2018-12-30 15:02:16 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
if(ext->cursor.hidden || ext->cursor.state == 0) {
|
2020-01-10 06:52:57 +01:00
|
|
|
return LV_DESIGN_RES_OK; /*The cursor is not visible now*/
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2017-10-30 17:11:56 +01:00
|
|
|
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_draw_rect_dsc_t cur_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&cur_dsc);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_init_draw_rect_dsc(ta, LV_TEXTAREA_PART_CURSOR, &cur_dsc);
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2018-12-30 15:02:16 +01:00
|
|
|
/*Draw he cursor according to the type*/
|
|
|
|
lv_area_t cur_area;
|
|
|
|
lv_area_copy(&cur_area, &ext->cursor.area);
|
2017-09-25 12:11:42 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
cur_area.x1 += ext->label->coords.x1;
|
|
|
|
cur_area.y1 += ext->label->coords.y1;
|
|
|
|
cur_area.x2 += ext->label->coords.x1;
|
|
|
|
cur_area.y2 += ext->label->coords.y1;
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-01-10 06:52:57 +01:00
|
|
|
lv_draw_rect(&cur_area, clip_area, &cur_dsc);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-01-10 06:52:57 +01:00
|
|
|
char letter_buf[8] = {0};
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], _lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos]));
|
2019-03-28 06:11:50 +01:00
|
|
|
|
2020-01-10 06:52:57 +01:00
|
|
|
if(cur_dsc.bg_opa == LV_OPA_COVER) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-01-03 11:06:11 +01:00
|
|
|
cur_area.x1 += left;
|
|
|
|
cur_area.y1 += top;
|
|
|
|
|
|
|
|
lv_draw_label_dsc_t cur_label_dsc;
|
|
|
|
lv_draw_label_dsc_init(&cur_label_dsc);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_init_draw_label_dsc(ta, LV_TEXTAREA_PART_CURSOR, &cur_label_dsc);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_draw_label(&cur_area, clip_area, &cur_label_dsc, letter_buf, NULL);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
|
2017-11-05 15:19:36 +01:00
|
|
|
{
|
|
|
|
lv_res_t res;
|
2020-01-03 11:06:11 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_get_style_info_t * info = param;
|
2020-02-14 12:36:44 +01:00
|
|
|
info->result = lv_textarea_get_style(ta, info->part);
|
2020-01-07 23:43:57 +01:00
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(ta, sign, param);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
2020-02-25 09:15:56 +01:00
|
|
|
return ancestor_signal(ta, sign, param);
|
2020-01-03 11:06:11 +01:00
|
|
|
}
|
2017-11-05 15:19:36 +01:00
|
|
|
|
|
|
|
/* 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;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-11-05 15:19:36 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
2017-11-23 21:28:36 +01:00
|
|
|
if(ext->pwd_tmp != NULL) lv_mem_free(ext->pwd_tmp);
|
2020-02-25 09:15:56 +01:00
|
|
|
if(ext->placeholder_txt != NULL) lv_mem_free(ext->placeholder_txt);
|
|
|
|
|
|
|
|
ext->pwd_tmp = NULL;
|
|
|
|
ext->placeholder_txt = NULL;
|
2020-02-15 02:30:20 +01:00
|
|
|
|
2020-02-21 16:33:42 +01:00
|
|
|
lv_obj_clean_style_list(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-02-25 09:15:56 +01:00
|
|
|
lv_obj_clean_style_list(ta, LV_TEXTAREA_PART_PLACEHOLDER);
|
|
|
|
|
|
|
|
/* (The created label will be deleted automatically) */
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2017-11-07 17:00:55 +01:00
|
|
|
if(ext->label) {
|
|
|
|
if(ext->one_line) {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_BG);
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2020-01-03 11:06:11 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
/*In one line mode refresh the Text Area height because 'vpad' can modify it*/
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
2019-11-15 15:23:38 +01:00
|
|
|
lv_obj_set_height(ext->label, font_h);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_height(ta, font_h + top + bottom);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-11-07 17:00:55 +01:00
|
|
|
/*In not one line mode refresh the Label width because 'hpad' can modify it*/
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_set_width(ext->label, lv_page_get_width_fit(ta));
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_pos(ext->label, 0, 0); /*Be sure the Label is in the correct position*/
|
2019-02-02 01:26:52 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
|
|
|
lv_label_set_text(ext->label, NULL);
|
2020-01-03 11:06:11 +01:00
|
|
|
refr_cursor_area(ta);
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_COORD_CHG) {
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Set the label width according to the text area width*/
|
|
|
|
if(ext->label) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_width(ta) != lv_area_get_width(param) || lv_obj_get_height(ta) != lv_area_get_height(param)) {
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_set_width(ext->label, lv_page_get_width_fit(ta));
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_pos(ext->label, 0, 0);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_label_set_text(ext->label, NULL); /*Refresh the label*/
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
refr_cursor_area(ta);
|
2017-11-05 15:19:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_CONTROL) {
|
2020-06-28 12:13:39 +08:00
|
|
|
#if LV_USE_GROUP
|
2019-04-04 07:15:40 +02:00
|
|
|
uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
|
2019-04-08 14:36:20 +02:00
|
|
|
if(c == LV_KEY_RIGHT)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_cursor_right(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_LEFT)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_cursor_left(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_UP)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_cursor_up(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_DOWN)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_cursor_down(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_BACKSPACE)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_del_char(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_DEL)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_del_char_forward(ta);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_HOME)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, 0);
|
2019-04-08 14:36:20 +02:00
|
|
|
else if(c == LV_KEY_END)
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_set_cursor_pos(ta, LV_TEXTAREA_CURSOR_LAST);
|
2020-09-03 14:08:04 +02:00
|
|
|
else if(c == LV_KEY_ENTER && lv_textarea_get_one_line(ta))
|
|
|
|
lv_event_send(ta, LV_EVENT_APPLY, NULL);
|
2017-11-19 19:28:45 +01:00
|
|
|
else {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_add_char(ta, c);
|
2017-11-19 19:28:45 +01:00
|
|
|
}
|
2020-06-28 12:13:39 +08:00
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
2020-06-28 12:13:39 +08:00
|
|
|
#if LV_USE_GROUP
|
2018-10-05 17:22:49 +02:00
|
|
|
bool * editable = (bool *)param;
|
2019-04-04 07:15:40 +02:00
|
|
|
*editable = true;
|
2020-06-28 12:13:39 +08:00
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESS_LOST ||
|
|
|
|
sign == LV_SIGNAL_RELEASED) {
|
2019-04-04 07:15:40 +02:00
|
|
|
update_cursor_position_on_click(ta, sign, (lv_indev_t *)param);
|
2019-02-02 05:11:18 +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
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
2017-11-05 15:19:36 +01:00
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = scrl_signal(scrl, sign, param);
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, "");
|
2017-11-05 15:19:36 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * ta = lv_obj_get_parent(scrl);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-03-06 22:59:58 +01:00
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
2017-11-07 17:00:55 +01:00
|
|
|
/*Set ext. size because the cursor might be out of this object*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_BG);
|
2020-02-15 00:33:26 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(font);
|
|
|
|
scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, line_space + font_h);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_COORD_CHG) {
|
2019-02-27 10:55:39 +01:00
|
|
|
/*Set the label width according to the text area width*/
|
|
|
|
if(ext->label) {
|
2019-06-27 07:16:15 +02:00
|
|
|
if(lv_obj_get_width(scrl) != lv_area_get_width(param) ||
|
|
|
|
lv_obj_get_height(scrl) != lv_area_get_height(param)) {
|
2019-03-06 22:59:58 +01:00
|
|
|
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_set_width(ext->label, lv_page_get_width_fit(ta));
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_obj_set_pos(ext->label, 0, 0);
|
2019-02-27 10:55:39 +01:00
|
|
|
|
2020-01-10 18:16:20 +01:00
|
|
|
lv_label_set_text(ext->label, NULL); /*Refresh the label*/
|
2019-02-27 10:55:39 +01:00
|
|
|
refr_cursor_area(ta);
|
|
|
|
}
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2019-02-27 10:55:39 +01:00
|
|
|
}
|
2020-01-10 18:16:20 +01:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESS_LOST ||
|
|
|
|
sign == LV_SIGNAL_RELEASED) {
|
2019-03-27 16:39:37 -04:00
|
|
|
update_cursor_position_on_click(ta, sign, (lv_indev_t *)param);
|
2018-09-29 10:43:53 +08:00
|
|
|
}
|
2019-02-02 00:19:18 +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
|
|
|
|
2020-01-03 11:06:11 +01:00
|
|
|
/**
|
|
|
|
* Get the style descriptor of a part of the object
|
|
|
|
* @param page pointer the object
|
2020-02-14 12:36:44 +01:00
|
|
|
* @param part the part from `lv_textarea_part_t`. (LV_TEXTAREA_PART_...)
|
2020-01-03 11:06:11 +01:00
|
|
|
* @return pointer to the style descriptor of the specified part
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_style_list_t * lv_textarea_get_style(lv_obj_t * ta, uint8_t part)
|
2020-01-03 11:06:11 +01:00
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(ta, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2020-01-03 11:06:11 +01:00
|
|
|
|
|
|
|
switch(part) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_TEXTAREA_PART_BG:
|
|
|
|
style_dsc_p = &ta->style_list;
|
|
|
|
break;
|
2020-05-12 21:29:16 +02:00
|
|
|
case LV_TEXTAREA_PART_SCROLLBAR:
|
2020-02-26 19:48:27 +01:00
|
|
|
style_dsc_p = &ext->page.scrlbar.style;
|
|
|
|
break;
|
|
|
|
case LV_TEXTAREA_PART_CURSOR:
|
|
|
|
style_dsc_p = &ext->cursor.style;
|
|
|
|
break;
|
2020-01-03 11:06:11 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_TEXTAREA_PART_EDGE_FLASH:
|
|
|
|
style_dsc_p = &ext->page.edge_flash.style;
|
|
|
|
break;
|
2020-01-03 11:06:11 +01:00
|
|
|
#endif
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_TEXTAREA_PART_PLACEHOLDER:
|
|
|
|
style_dsc_p = &ext->style_placeholder;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
2020-01-03 11:06:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2018-01-16 11:54:35 +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
|
|
|
*/
|
2019-05-20 09:22:09 -07:00
|
|
|
static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show)
|
2016-12-15 10:31:30 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-06-19 09:49:58 +02:00
|
|
|
if(show != ext->cursor.state) {
|
2017-11-17 15:43:08 +01:00
|
|
|
ext->cursor.state = show == 0 ? 0 : 1;
|
2020-01-10 06:52:57 +01:00
|
|
|
if(ext->cursor.hidden == 0) {
|
2018-12-30 15:02:16 +01:00
|
|
|
lv_area_t area_tmp;
|
|
|
|
lv_area_copy(&area_tmp, &ext->cursor.area);
|
|
|
|
area_tmp.x1 += ext->label->coords.x1;
|
|
|
|
area_tmp.y1 += ext->label->coords.y1;
|
|
|
|
area_tmp.x2 += ext->label->coords.x1;
|
|
|
|
area_tmp.y2 += ext->label->coords.y1;
|
2020-01-20 14:47:05 +01:00
|
|
|
lv_obj_invalidate_area(ta, &area_tmp);
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
2018-06-19 09:49:58 +02: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
|
|
|
|
*/
|
2019-05-20 09:22:09 -07:00
|
|
|
static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x)
|
2017-07-07 16:22:24 +02:00
|
|
|
{
|
2017-12-02 20:43:50 +01:00
|
|
|
(void)ta;
|
|
|
|
(void)x;
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 12:04:02 +02:00
|
|
|
/**
|
|
|
|
* Call when an animation is ready to convert all characters to '*'
|
|
|
|
* @param a pointer to the animation
|
|
|
|
*/
|
|
|
|
static void pwd_char_hider_anim_ready(lv_anim_t * a)
|
|
|
|
{
|
|
|
|
lv_obj_t * ta = a->var;
|
|
|
|
pwd_char_hider(ta);
|
|
|
|
}
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-05-08 12:04:02 +02:00
|
|
|
|
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)
|
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2017-07-07 16:22:24 +02:00
|
|
|
if(ext->pwd_mode != 0) {
|
2019-04-04 07:15:40 +02:00
|
|
|
char * txt = lv_label_get_text(ext->label);
|
2020-06-01 17:51:47 +01:00
|
|
|
int32_t enc_len = _lv_txt_get_encoded_length(txt);
|
2020-02-17 16:04:16 +01:00
|
|
|
if(enc_len == 0) return;
|
|
|
|
|
|
|
|
/*If the textarea's font has "bullet" character use it else fallback to "*"*/
|
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_font_glyph_dsc_t g;
|
|
|
|
bool has_bullet;
|
|
|
|
has_bullet = lv_font_get_glyph_dsc(font, &g, LV_TEXTAREA_PWD_BULLET_UNICODE, 0);
|
|
|
|
const char * bullet;
|
2020-04-06 14:23:57 +02:00
|
|
|
if(has_bullet) bullet = LV_SYMBOL_BULLET;
|
2020-02-17 16:04:16 +01:00
|
|
|
else bullet = "*";
|
|
|
|
|
|
|
|
size_t bullet_len = strlen(bullet);
|
2020-05-13 14:11:16 +02:00
|
|
|
char * txt_tmp = _lv_mem_buf_get(enc_len * bullet_len + 1);
|
2020-06-01 22:56:10 +02:00
|
|
|
int32_t i;
|
2020-02-17 16:04:16 +01:00
|
|
|
for(i = 0; i < enc_len; i++) {
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_memcpy(&txt_tmp[i * bullet_len], bullet, bullet_len);
|
2018-04-14 22:06:13 +02:00
|
|
|
}
|
2017-09-22 13:58:01 +02:00
|
|
|
|
2020-02-17 16:04:16 +01:00
|
|
|
txt_tmp[i * bullet_len] = '\0';
|
2017-07-07 16:22:24 +02:00
|
|
|
|
2020-02-17 16:04:16 +01:00
|
|
|
lv_label_set_text(ext->label, txt_tmp);
|
2020-05-13 14:11:16 +02:00
|
|
|
_lv_mem_buf_release(txt_tmp);
|
2017-07-07 16:22:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:37:00 +02:00
|
|
|
/**
|
|
|
|
* Test an unicode character if it is accepted or not. Checks max length and accepted char list.
|
|
|
|
* @param ta pointer to a test area object
|
|
|
|
* @param c an unicode character
|
2020-06-15 17:12:48 +03:00
|
|
|
* @return true: accepted; false: rejected
|
2018-08-09 23:37:00 +02:00
|
|
|
*/
|
2018-08-04 08:46:44 +02:00
|
|
|
static bool char_is_accepted(lv_obj_t * ta, uint32_t c)
|
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2018-10-05 17:22:49 +02:00
|
|
|
|
|
|
|
/*If no restriction accept it*/
|
|
|
|
if(ext->accapted_chars == NULL && ext->max_length == 0) return true;
|
|
|
|
|
|
|
|
/*Too many characters?*/
|
2020-05-13 14:11:16 +02:00
|
|
|
if(ext->max_length > 0 && _lv_txt_get_encoded_length(lv_textarea_get_text(ta)) >= ext->max_length) {
|
2018-10-05 17:22:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Accepted character?*/
|
|
|
|
if(ext->accapted_chars) {
|
|
|
|
uint32_t i = 0;
|
2020-02-25 15:32:35 +01:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
while(ext->accapted_chars[i] != '\0') {
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t a = _lv_txt_encoded_next(ext->accapted_chars, &i);
|
2018-10-05 17:22:49 +02:00
|
|
|
if(a == c) return true; /*Accepted*/
|
|
|
|
}
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
return false; /*The character wasn't in the list*/
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-04-04 07:15:40 +02:00
|
|
|
return true; /*If the accepted char list in not specified the accept the character*/
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2018-08-04 08:46:44 +02:00
|
|
|
}
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void refr_cursor_area(lv_obj_t * ta)
|
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-06-14 16:04:15 +02:00
|
|
|
|
2020-03-05 15:39:11 +01:00
|
|
|
const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG);
|
|
|
|
lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TEXTAREA_PART_BG);
|
2018-12-30 15:02:16 +01:00
|
|
|
|
2020-06-01 17:51:47 +01:00
|
|
|
uint32_t cur_pos = lv_textarea_get_cursor_pos(ta);
|
2018-12-30 15:02:16 +01:00
|
|
|
const char * txt = lv_label_get_text(ext->label);
|
2019-03-28 06:11:50 +01:00
|
|
|
|
2018-12-30 15:02:16 +01:00
|
|
|
uint32_t byte_pos;
|
2020-05-13 14:11:16 +02:00
|
|
|
byte_pos = _lv_txt_encoded_get_byte_id(txt, cur_pos);
|
2019-03-28 06:11:50 +01:00
|
|
|
|
2020-05-13 14:11:16 +02:00
|
|
|
uint32_t letter = _lv_txt_encoded_next(&txt[byte_pos], NULL);
|
2018-12-30 15:02:16 +01:00
|
|
|
|
2020-01-03 11:06:11 +01:00
|
|
|
lv_coord_t letter_h = lv_font_get_line_height(font);
|
2019-05-01 16:43:32 +02:00
|
|
|
|
2018-12-30 15:02:16 +01:00
|
|
|
/*Set letter_w (set not 0 on non printable but valid chars)*/
|
|
|
|
lv_coord_t letter_w;
|
|
|
|
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
2020-01-03 11:06:11 +01:00
|
|
|
letter_w = lv_font_get_glyph_width(font, ' ', '\0');
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-05-01 16:43:32 +02:00
|
|
|
/*`letter_next` parameter is '\0' to ignore kerning*/
|
2020-01-03 11:06:11 +01:00
|
|
|
letter_w = lv_font_get_glyph_width(font, letter, '\0');
|
2018-12-30 15:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lv_point_t letter_pos;
|
|
|
|
lv_label_get_letter_pos(ext->label, cur_pos, &letter_pos);
|
|
|
|
|
|
|
|
/*If the cursor is out of the text (most right) draw it to the next line*/
|
2019-06-06 06:05:40 +02:00
|
|
|
if(letter_pos.x + ext->label->coords.x1 + letter_w > ext->label->coords.x2 && ext->one_line == 0 &&
|
|
|
|
lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) {
|
2018-12-30 15:02:16 +01:00
|
|
|
letter_pos.x = 0;
|
2020-01-03 11:06:11 +01:00
|
|
|
letter_pos.y += letter_h + line_space;
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
if(letter != '\0') {
|
2020-05-13 14:11:16 +02:00
|
|
|
byte_pos += _lv_txt_encoded_size(&txt[byte_pos]);
|
|
|
|
letter = _lv_txt_encoded_next(&txt[byte_pos], NULL);
|
2018-12-30 15:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
2020-01-03 11:06:11 +01:00
|
|
|
letter_w = lv_font_get_glyph_width(font, ' ', '\0');
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-01-03 11:06:11 +01:00
|
|
|
letter_w = lv_font_get_glyph_width(font, letter, '\0');
|
2018-12-30 15:02:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Save the byte position. It is required to draw `LV_CURSOR_BLOCK`*/
|
|
|
|
ext->cursor.txt_byte_pos = byte_pos;
|
|
|
|
|
2020-01-03 11:06:11 +01:00
|
|
|
/*Calculate the cursor according to its type*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_CURSOR);
|
|
|
|
lv_style_int_t bottom = lv_obj_get_style_pad_bottom(ta, LV_TEXTAREA_PART_CURSOR);
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-02-20 05:08:03 +01:00
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(ta, LV_TEXTAREA_PART_CURSOR);
|
2020-01-03 11:06:11 +01:00
|
|
|
|
2018-12-30 15:02:16 +01:00
|
|
|
lv_area_t cur_area;
|
2020-01-10 06:52:57 +01:00
|
|
|
cur_area.x1 = letter_pos.x - left;
|
|
|
|
cur_area.y1 = letter_pos.y - top;
|
|
|
|
cur_area.x2 = letter_pos.x + right + letter_w;
|
|
|
|
cur_area.y2 = letter_pos.y + bottom + letter_h;
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
/*Save the new area*/
|
|
|
|
lv_area_t area_tmp;
|
|
|
|
lv_area_copy(&area_tmp, &ext->cursor.area);
|
|
|
|
area_tmp.x1 += ext->label->coords.x1;
|
|
|
|
area_tmp.y1 += ext->label->coords.y1;
|
|
|
|
area_tmp.x2 += ext->label->coords.x1;
|
|
|
|
area_tmp.y2 += ext->label->coords.y1;
|
2020-01-20 14:47:05 +01:00
|
|
|
lv_obj_invalidate_area(ta, &area_tmp);
|
2018-12-30 15:02:16 +01:00
|
|
|
|
|
|
|
lv_area_copy(&ext->cursor.area, &cur_area);
|
|
|
|
|
|
|
|
lv_area_copy(&area_tmp, &ext->cursor.area);
|
|
|
|
area_tmp.x1 += ext->label->coords.x1;
|
|
|
|
area_tmp.y1 += ext->label->coords.y1;
|
|
|
|
area_tmp.x2 += ext->label->coords.x1;
|
|
|
|
area_tmp.y2 += ext->label->coords.y1;
|
2020-01-20 14:47:05 +01:00
|
|
|
lv_obj_invalidate_area(ta, &area_tmp);
|
2018-12-30 15:02:16 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_indev_t * click_source)
|
2019-02-02 22:59:28 +01:00
|
|
|
{
|
2019-06-14 16:04:15 +02:00
|
|
|
|
2019-03-12 14:29:37 +01:00
|
|
|
if(click_source == NULL) return;
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t * ext = lv_obj_get_ext_attr(ta);
|
2019-06-14 16:04:15 +02:00
|
|
|
if(ext->cursor.click_pos == 0) return;
|
2020-01-10 06:52:57 +01:00
|
|
|
if(ext->cursor.hidden) return;
|
2019-06-14 16:04:15 +02:00
|
|
|
|
2019-03-12 14:29:37 +01:00
|
|
|
if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD ||
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_get_type(click_source) == LV_INDEV_TYPE_ENCODER) {
|
2019-03-12 14:29:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-02 22:59:28 +01:00
|
|
|
lv_area_t label_coords;
|
|
|
|
lv_obj_get_coords(ext->label, &label_coords);
|
|
|
|
|
2019-03-27 19:11:04 -04:00
|
|
|
lv_point_t point_act, vect_act;
|
2019-02-20 17:08:38 +01:00
|
|
|
lv_indev_get_point(click_source, &point_act);
|
2019-03-27 19:11:04 -04:00
|
|
|
lv_indev_get_vect(click_source, &vect_act);
|
|
|
|
|
2019-02-20 17:08:38 +01:00
|
|
|
if(point_act.x < 0 || point_act.y < 0) return; /*Ignore event from keypad*/
|
2019-10-11 12:01:58 +02:00
|
|
|
lv_point_t rel_pos;
|
|
|
|
rel_pos.x = point_act.x - label_coords.x1;
|
|
|
|
rel_pos.y = point_act.y - label_coords.y1;
|
2019-02-02 22:59:28 +01:00
|
|
|
|
|
|
|
lv_coord_t label_width = lv_obj_get_width(ext->label);
|
|
|
|
|
2019-10-11 12:01:58 +02:00
|
|
|
uint16_t char_id_at_click;
|
2019-04-18 07:11:43 +02:00
|
|
|
|
|
|
|
#if LV_LABEL_TEXT_SEL
|
|
|
|
lv_label_ext_t * ext_label = lv_obj_get_ext_attr(ext->label);
|
|
|
|
bool click_outside_label;
|
2019-02-02 22:59:28 +01:00
|
|
|
/*Check if the click happened on the left side of the area outside the label*/
|
2019-10-11 12:01:58 +02:00
|
|
|
if(rel_pos.x < 0) {
|
|
|
|
char_id_at_click = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
click_outside_label = true;
|
2019-02-02 22:59:28 +01:00
|
|
|
}
|
|
|
|
/*Check if the click happened on the right side of the area outside the label*/
|
2019-10-11 12:01:58 +02:00
|
|
|
else if(rel_pos.x >= label_width) {
|
2020-02-14 12:36:44 +01:00
|
|
|
char_id_at_click = LV_TEXTAREA_CURSOR_LAST;
|
2019-04-04 07:15:40 +02:00
|
|
|
click_outside_label = true;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-10-11 12:01:58 +02:00
|
|
|
char_id_at_click = lv_label_get_letter_on(ext->label, &rel_pos);
|
|
|
|
click_outside_label = !lv_label_is_char_under_pos(ext->label, &rel_pos);
|
2019-02-02 22:59:28 +01:00
|
|
|
}
|
|
|
|
|
2019-04-18 06:45:45 +02:00
|
|
|
if(ext->text_sel_en) {
|
|
|
|
if(!ext->text_sel_in_prog && !click_outside_label && sign == LV_SIGNAL_PRESSED) {
|
|
|
|
/*Input device just went down. Store the selection start position*/
|
2020-01-03 11:06:11 +01:00
|
|
|
ext->sel_start = char_id_at_click;
|
|
|
|
ext->sel_end = LV_LABEL_TEXT_SEL_OFF;
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->text_sel_in_prog = 1;
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_obj_set_drag(lv_page_get_scrollable(ta), false);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->text_sel_in_prog && sign == LV_SIGNAL_PRESSING) {
|
2019-04-18 06:45:45 +02:00
|
|
|
/*Input device may be moving. Store the end position */
|
2020-01-03 11:06:11 +01:00
|
|
|
ext->sel_end = char_id_at_click;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->text_sel_in_prog && (sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED)) {
|
2019-04-18 06:45:45 +02:00
|
|
|
/*Input device is released. Check if anything was selected.*/
|
2020-06-16 12:03:32 +02:00
|
|
|
lv_obj_set_drag(lv_page_get_scrollable(ta), true);
|
2019-04-18 06:45:45 +02:00
|
|
|
}
|
2019-03-27 16:39:37 -04:00
|
|
|
}
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
if(ext->text_sel_in_prog || sign == LV_SIGNAL_PRESSED) lv_textarea_set_cursor_pos(ta, char_id_at_click);
|
2019-03-27 19:11:04 -04:00
|
|
|
|
2019-04-18 06:45:45 +02:00
|
|
|
if(ext->text_sel_in_prog) {
|
2019-04-04 07:15:40 +02:00
|
|
|
/*If the selected area has changed then update the real values and*/
|
2019-04-14 09:47:45 -07:00
|
|
|
|
2019-10-11 12:01:58 +02:00
|
|
|
/*Invalidate the text area.*/
|
2020-01-03 11:06:11 +01:00
|
|
|
if(ext->sel_start > ext->sel_end) {
|
|
|
|
if(ext_label->sel_start != ext->sel_end || ext_label->sel_end != ext->sel_start) {
|
|
|
|
ext_label->sel_start = ext->sel_end;
|
|
|
|
ext_label->sel_end = ext->sel_start;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_invalidate(ta);
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(ext->sel_start < ext->sel_end) {
|
2020-01-03 11:06:11 +01:00
|
|
|
if(ext_label->sel_start != ext->sel_start || ext_label->sel_end != ext->sel_end) {
|
|
|
|
ext_label->sel_start = ext->sel_start;
|
|
|
|
ext_label->sel_end = ext->sel_end;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_invalidate(ta);
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-01-03 11:06:11 +01:00
|
|
|
if(ext_label->sel_start != LV_DRAW_LABEL_NO_TXT_SEL || ext_label->sel_end != LV_DRAW_LABEL_NO_TXT_SEL) {
|
|
|
|
ext_label->sel_start = LV_DRAW_LABEL_NO_TXT_SEL;
|
|
|
|
ext_label->sel_end = LV_DRAW_LABEL_NO_TXT_SEL;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_invalidate(ta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*Finish selection if necessary */
|
|
|
|
if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED) {
|
2019-04-18 06:45:45 +02:00
|
|
|
ext->text_sel_in_prog = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
}
|
2019-03-27 16:39:37 -04:00
|
|
|
}
|
2019-04-18 07:11:43 +02:00
|
|
|
#else
|
|
|
|
/*Check if the click happened on the left side of the area outside the label*/
|
2019-10-11 12:01:58 +02:00
|
|
|
if(rel_pos.x < 0) {
|
|
|
|
char_id_at_click = 0;
|
2019-04-18 07:11:43 +02:00
|
|
|
}
|
|
|
|
/*Check if the click happened on the right side of the area outside the label*/
|
2019-10-11 12:01:58 +02:00
|
|
|
else if(rel_pos.x >= label_width) {
|
2020-02-14 12:36:44 +01:00
|
|
|
char_id_at_click = LV_TEXTAREA_CURSOR_LAST;
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-10-11 12:01:58 +02:00
|
|
|
char_id_at_click = lv_label_get_letter_on(ext->label, &rel_pos);
|
2019-04-18 07:11:43 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
if(sign == LV_SIGNAL_PRESSED) lv_textarea_set_cursor_pos(ta, char_id_at_click);
|
2019-04-18 07:11:43 +02:00
|
|
|
#endif
|
2019-02-02 22:59:28 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 16:28:03 +02:00
|
|
|
static lv_res_t insert_handler(lv_obj_t * ta, const char * txt)
|
|
|
|
{
|
|
|
|
ta_insert_replace = NULL;
|
|
|
|
lv_event_send(ta, LV_EVENT_INSERT, txt);
|
|
|
|
if(ta_insert_replace) {
|
|
|
|
if(ta_insert_replace[0] == '\0') return LV_RES_INV; /*Drop this text*/
|
|
|
|
|
|
|
|
/*Add the replaced text directly it's different from the original*/
|
|
|
|
if(strcmp(ta_insert_replace, txt)) {
|
|
|
|
lv_textarea_add_text(ta, ta_insert_replace);
|
|
|
|
return LV_RES_INV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:29:00 +02:00
|
|
|
#endif
|