Skip to content

Commit 4007834

Browse files
committed
minor fixes
1 parent b44da3c commit 4007834

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

lv_core/lv_indev.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ bool lv_indev_is_dragging(const lv_indev_t * indev)
212212
*/
213213
void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point)
214214
{
215+
if(indev == NULL) {
216+
point->x = 0;
217+
point->y = 0;
218+
return;
219+
}
220+
215221
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
216222
point->x = 0;
217223
point->y = 0;
@@ -461,11 +467,15 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
461467
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
462468

463469
if(editable) {
464-
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
470+
if(i->group->obj_ll.head != i->group->obj_ll.tail)
471+
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
472+
else if(focused)
473+
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
465474
}
466475
/*If not editable then just send a long press signal*/
467476
else {
468-
if(focused) focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
477+
if(focused)
478+
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
469479
}
470480
i->proc.long_pr_sent = 1;
471481
}
@@ -482,7 +492,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
482492
}
483493
/*An object is being edited and the button is releases. Just send enter */
484494
else if(i->group->editing) {
485-
if(!i->proc.long_pr_sent) lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); /*Ignore long pressed enter release because it comes from mode switch*/
495+
if(!i->proc.long_pr_sent || i->group->obj_ll.head == i->group->obj_ll.tail)
496+
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); /*Ignore long pressed enter release because it comes from mode switch*/
486497
}
487498
/*If the focused object is editable and now in navigate mode then enter edit mode*/
488499
else if(editable && !i->group->editing && !i->proc.long_pr_sent) {
@@ -574,7 +585,10 @@ static void indev_proc_press(lv_indev_proc_t * proc)
574585
if(proc->reset_query != 0) return;
575586
}
576587

577-
if(pr_obj != NULL) {
588+
proc->act_obj = pr_obj; /*Save the pressed object*/
589+
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
590+
591+
if(proc->act_obj != NULL) {
578592
/* Save the time when the obj pressed.
579593
* It is necessary to count the long press time.*/
580594
proc->pr_timestamp = lv_tick_get();
@@ -583,9 +597,11 @@ static void indev_proc_press(lv_indev_proc_t * proc)
583597
proc->drag_in_prog = 0;
584598
proc->drag_sum.x = 0;
585599
proc->drag_sum.y = 0;
600+
proc->vect.x = 0;
601+
proc->vect.y = 0;
586602

587603
/*Search for 'top' attribute*/
588-
lv_obj_t * i = pr_obj;
604+
lv_obj_t * i = proc->act_obj;
589605
lv_obj_t * last_top = NULL;
590606
while(i != NULL) {
591607
if(i->top != 0) last_top = i;
@@ -601,14 +617,11 @@ static void indev_proc_press(lv_indev_proc_t * proc)
601617
}
602618

603619
/*Send a signal about the press*/
604-
pr_obj->signal_func(pr_obj, LV_SIGNAL_PRESSED, indev_act);
620+
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSED, indev_act);
605621
if(proc->reset_query != 0) return;
606622
}
607623
}
608624

609-
proc->act_obj = pr_obj; /*Save the pressed object*/
610-
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
611-
612625
/*Calculate the vector*/
613626
proc->vect.x = proc->act_point.x - proc->last_point.x;
614627
proc->vect.y = proc->act_point.y - proc->last_point.y;
@@ -885,14 +898,19 @@ static void indev_drag_throw(lv_indev_proc_t * state)
885898

886899
if(state->vect.x != 0 ||
887900
state->vect.y != 0) {
888-
/*Get the coordinates and modify them*/
901+
/*Get the coordinates and modify them*/
902+
lv_area_t coords_ori;
903+
lv_obj_get_coords(drag_obj, &coords_ori);
889904
lv_coord_t act_x = lv_obj_get_x(drag_obj) + state->vect.x;
890905
lv_coord_t act_y = lv_obj_get_y(drag_obj) + state->vect.y;
891906
lv_obj_set_pos(drag_obj, act_x, act_y);
892907

908+
lv_area_t coord_new;
909+
lv_obj_get_coords(drag_obj, &coord_new);
910+
893911
/*If non of the coordinates are changed then do not continue throwing*/
894-
if((lv_obj_get_x(drag_obj) != act_x || state->vect.x == 0) &&
895-
(lv_obj_get_y(drag_obj) != act_y || state->vect.y == 0)) {
912+
if((coords_ori.x1 == coord_new.x1 || state->vect.x == 0) &&
913+
(coords_ori.y1 == coord_new.y1 || state->vect.y == 0)) {
896914
state->drag_in_prog = 0;
897915
state->vect.x = 0;
898916
state->vect.y = 0;

lv_core/lv_obj.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,13 @@ lv_res_t lv_obj_del(lv_obj_t * obj)
360360
void lv_obj_clean(lv_obj_t * obj)
361361
{
362362
lv_obj_t * child = lv_obj_get_child(obj, NULL);
363-
363+
lv_obj_t * child_next;
364364
while(child) {
365+
/* Read the next child before deleting the current
366+
* because the next couldn't be read from a deleted (invalid) node*/
367+
child_next = lv_obj_get_child(obj, child);
365368
lv_obj_del(child);
366-
child = lv_obj_get_child(obj, child);
369+
child = child_next;
367370
}
368371
}
369372

0 commit comments

Comments
 (0)