From 86b34460dd80d6c3e35d903a6ee29ab943137704 Mon Sep 17 00:00:00 2001 From: MiSimon Date: Fri, 1 Feb 2019 23:53:09 +0100 Subject: [PATCH] Added POS1 and END support to lv_ta --- lv_core/lv_group.h | 2 ++ lv_objx/lv_ta.c | 19 ++++++++++++++----- lv_objx/lv_ta.h | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index 6be9b5cca..7aac83d60 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -36,6 +36,8 @@ extern "C" { #define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/ #define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/ #define LV_GROUP_KEY_PREV 11 /*0x0B, '*/ +#define LV_GROUP_KEY_POS1 2 /*0x02, STX*/ +#define LV_GROUP_KEY_END 3 /*0x03, ETX*/ #if USE_LV_GROUP != 0 /********************** diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 69c12ce03..f6d3a4614 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -351,6 +351,17 @@ void lv_ta_del_char(lv_obj_t * ta) lv_ta_set_cursor_pos(ta, ext->cursor.pos - 1); } +/** + * Delete the right character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char_forward(lv_obj_t * ta) +{ + uint16_t cp = lv_ta_get_cursor_pos(ta); + lv_ta_set_cursor_pos(ta, cp + 1); + if(cp != lv_ta_get_cursor_pos(ta)) lv_ta_del_char(ta); +} + /*===================== * Setter functions *====================*/ @@ -1051,11 +1062,9 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) else if(c == LV_GROUP_KEY_UP) lv_ta_cursor_up(ta); else if(c == LV_GROUP_KEY_DOWN) lv_ta_cursor_down(ta); else if(c == LV_GROUP_KEY_BACKSPACE) lv_ta_del_char(ta); - else if(c == LV_GROUP_KEY_DEL) { - uint16_t cp = lv_ta_get_cursor_pos(ta); - lv_ta_set_cursor_pos(ta, cp + 1); - if(cp != lv_ta_get_cursor_pos(ta)) lv_ta_del_char(ta); - } + else if(c == LV_GROUP_KEY_DEL) lv_ta_del_char_forward(ta); + else if(c == LV_GROUP_KEY_POS1) lv_ta_set_cursor_pos(ta, 0); + else if(c == LV_GROUP_KEY_END) lv_ta_set_cursor_pos(ta, LV_TA_CURSOR_LAST); else { lv_ta_add_char(ta, c); } diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 3227873a7..dd38cc857 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -122,6 +122,12 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt); */ void lv_ta_del_char(lv_obj_t * ta); +/** + * Delete the right character from the current cursor position + * @param ta pointer to a text area object + */ +void lv_ta_del_char_forward(lv_obj_t * ta); + /*===================== * Setter functions *====================*/