1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

removed code duplication

This commit is contained in:
MiSimon 2019-02-02 22:59:28 +01:00
parent cfe0c14e56
commit 43b20179ed

View File

@ -53,6 +53,7 @@ static void pwd_char_hider(lv_obj_t * ta);
static bool char_is_accepted(lv_obj_t * ta, uint32_t c); static bool char_is_accepted(lv_obj_t * ta, uint32_t c);
static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res); static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res);
static void refr_cursor_area(lv_obj_t * ta); static void refr_cursor_area(lv_obj_t * ta);
static void update_cursor_position_on_click(lv_obj_t * ta, lv_indev_t * click_source);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -1092,28 +1093,7 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
#endif #endif
} }
else if(sign == LV_SIGNAL_PRESSED) { else if(sign == LV_SIGNAL_PRESSED) {
lv_indev_t * indev = (lv_indev_t *)param; update_cursor_position_on_click(ta, (lv_indev_t *) param);
lv_area_t label_coords;
uint16_t index_of_char_at_position;
lv_obj_get_coords(ext->label, &label_coords);
lv_point_t relative_position;
relative_position.x = indev->proc.act_point.x - label_coords.x1;
relative_position.y = indev->proc.act_point.y - label_coords.y1;
lv_coord_t label_width = lv_obj_get_width(ext->label);
/*Check if the click happened on the left side of the area outside the label*/
if (relative_position.x < label_width / 2) {
index_of_char_at_position = 0;
}
/*Check if the click happened on the right side of the area outside the label*/
else if (relative_position.x >= label_width / 2) {
index_of_char_at_position = LV_TA_CURSOR_LAST;
}
lv_ta_set_cursor_pos(ta, index_of_char_at_position);
} }
return res; return res;
} }
@ -1142,33 +1122,7 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void
scrl->ext_size = LV_MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h); scrl->ext_size = LV_MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h);
} }
else if(sign == LV_SIGNAL_PRESSED) { else if(sign == LV_SIGNAL_PRESSED) {
lv_indev_t * indev = (lv_indev_t *)param; update_cursor_position_on_click(ta, (lv_indev_t *)param);
lv_area_t label_coords;
uint16_t index_of_char_at_position;
lv_obj_get_coords(ext->label, &label_coords);
lv_point_t relative_position;
relative_position.x = indev->proc.act_point.x - label_coords.x1;
relative_position.y = indev->proc.act_point.y - label_coords.y1;
lv_coord_t label_width = lv_obj_get_width(ext->label);
/*Check if the click happened on the left side of the area outside the label*/
if (relative_position.x < 0) {
index_of_char_at_position = 0;
}
/*Check if the click happened on the right side of the area outside the label*/
else if (relative_position.x >= label_width) {
index_of_char_at_position = LV_TA_CURSOR_LAST;
}
else {
index_of_char_at_position = lv_label_get_letter_on(ext->label, &relative_position);
}
lv_ta_set_cursor_pos(ta, index_of_char_at_position);
} }
@ -1399,4 +1353,34 @@ static void refr_cursor_area(lv_obj_t * ta)
lv_inv_area(&area_tmp); lv_inv_area(&area_tmp);
} }
static void update_cursor_position_on_click(lv_obj_t * ta, lv_indev_t * click_source)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
lv_area_t label_coords;
uint16_t index_of_char_at_position;
lv_obj_get_coords(ext->label, &label_coords);
lv_point_t relative_position;
relative_position.x = click_source->proc.act_point.x - label_coords.x1;
relative_position.y = click_source->proc.act_point.y - label_coords.y1;
lv_coord_t label_width = lv_obj_get_width(ext->label);
/*Check if the click happened on the left side of the area outside the label*/
if (relative_position.x < 0) {
index_of_char_at_position = 0;
}
/*Check if the click happened on the right side of the area outside the label*/
else if (relative_position.x >= label_width) {
index_of_char_at_position = LV_TA_CURSOR_LAST;
}
else {
index_of_char_at_position = lv_label_get_letter_on(ext->label, &relative_position);
}
lv_ta_set_cursor_pos(ta, index_of_char_at_position);
}
#endif #endif