Keep relative offset between pointer and dragged object identical
@@ -1028,6 +1028,7 @@ static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj)
static void indev_drag(lv_indev_proc_t * state)
{
lv_obj_t * drag_obj = state->types.pointer.act_obj;
+ bool drag_just_started = false;
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false && drag_obj != NULL) {
@@ -1052,6 +1053,7 @@ static void indev_drag(lv_indev_proc_t * state)
((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;
+ drag_just_started = true;
}
}
@@ -1072,12 +1074,23 @@ static void indev_drag(lv_indev_proc_t * state)
lv_coord_t act_x = lv_obj_get_x(drag_obj);
lv_coord_t act_y = lv_obj_get_y(drag_obj);
- if(allowed_dirs == LV_DRAG_DIR_ALL)
+ if(allowed_dirs == LV_DRAG_DIR_ALL) {
+ if(drag_just_started) {
+ act_x += state->types.pointer.drag_sum.x;
+ act_y += state->types.pointer.drag_sum.y;
+ }
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)
+ } else if(allowed_dirs & LV_DRAG_DIR_HOR) {
+ if(drag_just_started) {
+ act_x += state->types.pointer.drag_sum.x;
+ }
lv_obj_set_x(drag_obj, act_x + state->types.pointer.vect.x);
- else if(allowed_dirs & LV_DRAG_DIR_VER)
+ } else if(allowed_dirs & LV_DRAG_DIR_VER) {
+ if(drag_just_started) {
+ act_y += state->types.pointer.drag_sum.y;
+ }
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*/
