Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(label) consider base dir lv_label_get_letter_pos in special cases
related to #2712 (comment)
  • Loading branch information
kisvegabor committed Oct 28, 2021
1 parent 7425850 commit 6df5122
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/widgets/lv_label.c
Expand Up @@ -348,18 +348,19 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
const char * bidi_txt;
uint32_t visual_byte_pos;
#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;
/*Handle Bidi*/
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];
}
else {
uint32_t line_char_id = _lv_txt_encoded_get_char_id(&txt[line_start], byte_id - line_start);

bool is_rtl;
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;
if(is_rtl) visual_char_pos++;

Expand Down
36 changes: 18 additions & 18 deletions src/widgets/lv_textarea.c
Expand Up @@ -45,6 +45,7 @@
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_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 pwd_char_hider_anim(void * obj, int32_t x);
static void pwd_char_hider_anim_ready(lv_anim_t * a);
Expand Down Expand Up @@ -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);
lv_obj_set_width(ta->label, lv_pct(100));
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_textarea_set_cursor_pos(obj, 0);

Expand Down Expand Up @@ -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_obj_t * obj = lv_event_get_target(e);
lv_textarea_t * ta = (lv_textarea_t *)obj;

if(code == LV_EVENT_STYLE_CHANGED) {
if(ta->label) {
lv_label_set_text(ta->label, NULL);
refr_cursor_area(obj);
start_cursor_blink(obj);
}
}
else if(code == LV_EVENT_FOCUSED) {
if(code == LV_EVENT_FOCUSED) {
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) {
uint32_t c = *((uint32_t *)lv_event_get_param(e)); /*uint32_t because can be UTF-8*/
if(c == LV_KEY_RIGHT)
Expand Down Expand Up @@ -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
* @param ta pointer to a text area
Expand Down

0 comments on commit 6df5122

Please sign in to comment.