Merge pull request #1003 from littlevgl/obj_drag_dir

Enhance drag logic
This commit is contained in:
Gabor Kiss-Vamosi
2019-04-09 15:05:46 +02:00
committed by GitHub
3 changed files with 83 additions and 17 deletions

View File

@@ -1038,6 +1038,8 @@ static void indev_drag(lv_indev_proc_t * state)
if(lv_obj_get_drag(drag_obj) == false) return;
lv_drag_dir_t allowed_dirs = lv_obj_get_drag_dir(drag_obj);
/*Count the movement by drag*/
state->types.pointer.drag_sum.x += state->types.pointer.vect.x;
state->types.pointer.drag_sum.y += state->types.pointer.vect.y;
@@ -1045,8 +1047,10 @@ static void indev_drag(lv_indev_proc_t * state)
/*Enough move?*/
if(state->types.pointer.drag_limit_out == 0) {
/*If a move is greater then LV_DRAG_LIMIT then begin the drag*/
if(LV_MATH_ABS(state->types.pointer.drag_sum.x) >= indev_act->driver.drag_limit ||
LV_MATH_ABS(state->types.pointer.drag_sum.y) >= indev_act->driver.drag_limit) {
if(((allowed_dirs & LV_DRAG_DIR_HOR) &&
LV_MATH_ABS(state->types.pointer.drag_sum.x) >= indev_act->driver.drag_limit) ||
((allowed_dirs & LV_DRAG_DIR_VER) &&
LV_MATH_ABS(state->types.pointer.drag_sum.y) >= indev_act->driver.drag_limit)) {
state->types.pointer.drag_limit_out = 1;
}
}
@@ -1056,9 +1060,6 @@ static void indev_drag(lv_indev_proc_t * state)
/*Set new position if the vector is not zero*/
if(state->types.pointer.vect.x != 0 || state->types.pointer.vect.y != 0) {
/*Get the coordinates of the object and modify them*/
lv_coord_t act_x = lv_obj_get_x(drag_obj);
lv_coord_t act_y = lv_obj_get_y(drag_obj);
uint16_t inv_buf_size = lv_disp_get_inv_buf_size(
indev_act->driver.disp); /*Get the number of currently invalidated areas*/
@@ -1067,20 +1068,28 @@ static void indev_drag(lv_indev_proc_t * state)
lv_coord_t prev_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
lv_coord_t prev_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj));
lv_obj_set_pos(drag_obj, act_x + state->types.pointer.vect.x,
act_y + state->types.pointer.vect.y);
/*Get the coordinates of the object and modify them*/
lv_coord_t act_x = lv_obj_get_x(drag_obj);
lv_coord_t act_y = lv_obj_get_y(drag_obj);
/*Set the drag in progress flag if the object is really moved*/
if(drag_obj->coords.x1 != prev_x || drag_obj->coords.y1 != prev_y) {
if(state->types.pointer.drag_in_prog !=
0) { /*Send the drag begin signal on first move*/
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
if(state->reset_query != 0) return;
}
state->types.pointer.drag_in_prog = 1;
if(allowed_dirs == LV_DRAG_DIR_ALL)
lv_obj_set_pos(drag_obj, act_x + state->types.pointer.vect.x, act_y + state->types.pointer.vect.y);
else if(allowed_dirs & LV_DRAG_DIR_HOR)
lv_obj_set_x(drag_obj, act_x + state->types.pointer.vect.x);
else if(allowed_dirs & LV_DRAG_DIR_VER)
lv_obj_set_y(drag_obj, act_y + state->types.pointer.vect.y);
/*Set the drag in progress flag*/
/*Send the drag begin signal on first move*/
if(state->types.pointer.drag_in_prog == 0) {
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
if(state->reset_query != 0) return;
}
state->types.pointer.drag_in_prog = 1;
/*If the object didn't moved then clear the invalidated areas*/
else {
if(drag_obj->coords.x1 == prev_x && drag_obj->coords.y1 == prev_y) {
/*In a special case if the object is moved on a page and
* the scrollable has fit == true and the object is dragged of the page then
* while its coordinate is not changing only the parent's size is reduced */
@@ -1092,6 +1101,7 @@ static void indev_drag(lv_indev_proc_t * state)
new_inv_buf_size - inv_buf_size);
}
}
}
}
}
@@ -1123,6 +1133,8 @@ static void indev_drag_throw(lv_indev_proc_t * proc)
return;
}
lv_drag_dir_t allowed_dirs = lv_obj_get_drag_dir(drag_obj);
/*Reduce the vectors*/
proc->types.pointer.drag_throw_vect.x =
proc->types.pointer.drag_throw_vect.x * (100 - indev_act->driver.drag_throw) / 100;
@@ -1135,7 +1147,13 @@ static void indev_drag_throw(lv_indev_proc_t * proc)
lv_obj_get_coords(drag_obj, &coords_ori);
lv_coord_t act_x = lv_obj_get_x(drag_obj) + proc->types.pointer.drag_throw_vect.x;
lv_coord_t act_y = lv_obj_get_y(drag_obj) + proc->types.pointer.drag_throw_vect.y;
lv_obj_set_pos(drag_obj, act_x, act_y);
if(allowed_dirs == LV_DRAG_DIR_ALL)
lv_obj_set_pos(drag_obj, act_x, act_y);
else if(allowed_dirs & LV_DRAG_DIR_HOR)
lv_obj_set_x(drag_obj, act_x);
else if(allowed_dirs & LV_DRAG_DIR_VER)
lv_obj_set_y(drag_obj, act_y);
lv_area_t coord_new;
lv_obj_get_coords(drag_obj, &coord_new);