fix(label) consider base dir lv_label_get_letter_pos in special cases
related to https://github.com/lvgl/lvgl/issues/2712#issuecomment-953463193
This commit is contained in:
@@ -348,10 +348,11 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
|||||||
const char * bidi_txt;
|
const char * bidi_txt;
|
||||||
uint32_t visual_byte_pos;
|
uint32_t visual_byte_pos;
|
||||||
#if LV_USE_BIDI
|
#if LV_USE_BIDI
|
||||||
|
lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN);
|
||||||
char * mutable_bidi_txt = NULL;
|
char * mutable_bidi_txt = NULL;
|
||||||
/*Handle Bidi*/
|
/*Handle Bidi*/
|
||||||
if(new_line_start == byte_id) {
|
if(new_line_start == byte_id) {
|
||||||
visual_byte_pos = 0;
|
visual_byte_pos = base_dir == LV_BASE_DIR_RTL ? 0 : byte_id - line_start;
|
||||||
bidi_txt = &txt[line_start];
|
bidi_txt = &txt[line_start];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -359,7 +360,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
|||||||
|
|
||||||
bool is_rtl;
|
bool is_rtl;
|
||||||
uint32_t visual_char_pos = _lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start,
|
uint32_t visual_char_pos = _lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start,
|
||||||
lv_obj_get_style_base_dir(obj, LV_PART_MAIN), line_char_id, &is_rtl);
|
base_dir, line_char_id, &is_rtl);
|
||||||
bidi_txt = mutable_bidi_txt;
|
bidi_txt = mutable_bidi_txt;
|
||||||
if(is_rtl) visual_char_pos++;
|
if(is_rtl) visual_char_pos++;
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||||
static void lv_textarea_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
static void lv_textarea_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||||
static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
||||||
|
static void label_event_cb(lv_event_t * e);
|
||||||
static void cursor_blink_anim_cb(void * obj, int32_t show);
|
static void cursor_blink_anim_cb(void * obj, int32_t show);
|
||||||
static void pwd_char_hider_anim(void * obj, int32_t x);
|
static void pwd_char_hider_anim(void * obj, int32_t x);
|
||||||
static void pwd_char_hider_anim_ready(lv_anim_t * a);
|
static void pwd_char_hider_anim_ready(lv_anim_t * a);
|
||||||
@@ -822,6 +823,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
|
|||||||
ta->label = lv_label_create(obj);
|
ta->label = lv_label_create(obj);
|
||||||
lv_obj_set_width(ta->label, lv_pct(100));
|
lv_obj_set_width(ta->label, lv_pct(100));
|
||||||
lv_label_set_text(ta->label, "");
|
lv_label_set_text(ta->label, "");
|
||||||
|
lv_obj_add_event_cb(ta->label, label_event_cb, LV_EVENT_ALL, NULL);
|
||||||
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
|
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
|
||||||
lv_textarea_set_cursor_pos(obj, 0);
|
lv_textarea_set_cursor_pos(obj, 0);
|
||||||
|
|
||||||
@@ -856,27 +858,10 @@ static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
|||||||
|
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
lv_obj_t * obj = lv_event_get_target(e);
|
lv_obj_t * obj = lv_event_get_target(e);
|
||||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
|
||||||
|
|
||||||
if(code == LV_EVENT_STYLE_CHANGED) {
|
if(code == LV_EVENT_FOCUSED) {
|
||||||
if(ta->label) {
|
|
||||||
lv_label_set_text(ta->label, NULL);
|
|
||||||
refr_cursor_area(obj);
|
|
||||||
start_cursor_blink(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(code == LV_EVENT_FOCUSED) {
|
|
||||||
start_cursor_blink(obj);
|
start_cursor_blink(obj);
|
||||||
}
|
}
|
||||||
else if(code == LV_EVENT_SIZE_CHANGED) {
|
|
||||||
/*Set the label width according to the text area width*/
|
|
||||||
if(ta->label) {
|
|
||||||
lv_obj_set_pos(ta->label, 0, 0);
|
|
||||||
lv_label_set_text(ta->label, NULL); /*Refresh the label*/
|
|
||||||
|
|
||||||
refr_cursor_area(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(code == LV_EVENT_KEY) {
|
else if(code == LV_EVENT_KEY) {
|
||||||
uint32_t c = *((uint32_t *)lv_event_get_param(e)); /*uint32_t because can be UTF-8*/
|
uint32_t c = *((uint32_t *)lv_event_get_param(e)); /*uint32_t because can be UTF-8*/
|
||||||
if(c == LV_KEY_RIGHT)
|
if(c == LV_KEY_RIGHT)
|
||||||
@@ -913,6 +898,21 @@ static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void label_event_cb(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
|
lv_obj_t * label = lv_event_get_target(e);
|
||||||
|
lv_obj_t * ta = lv_obj_get_parent(label);
|
||||||
|
|
||||||
|
if(code == LV_EVENT_STYLE_CHANGED || code == LV_EVENT_SIZE_CHANGED) {
|
||||||
|
lv_label_set_text(label, NULL);
|
||||||
|
refr_cursor_area(ta);
|
||||||
|
start_cursor_blink(ta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to blink the cursor
|
* Called to blink the cursor
|
||||||
* @param ta pointer to a text area
|
* @param ta pointer to a text area
|
||||||
|
|||||||
Reference in New Issue
Block a user