Drag a tileview to trigger a button event

Description

When the tileview control is at (0,0) or the end coordinates, it continues to pull towards (-1,0), in fact (-1,0) does not exist. If the position where the finger stopped last happens to be on a button, this The button will trigger a click event, and triggering will cause a lot of confusion

What MCU/Processor/Board and compiler are you using?

esp32

What do you experience?

What do you expect?

Don’t trigger button click event

Code to reproduce

Screenshot and/or video

Please fill the “Code to reproduce” section.

When I swipe, the tileview is not moving because it has reached the end, but the finger can easily stop on the button and trigger an event. I request that the button not be triggered, thank you.

void event_cb_test(lv_obj_t *obj, lv_event_t event)
{
    if (event == LV_EVENT_CLICKED)
    {
        printf("btn is clicked\n");
    }
}

void create()
{
    static lv_point_t valid_pos[] = {{0, 0}, {1, 0}};
    lv_obj_t *tileview = lv_tileview_create(lv_scr_act(), NULL);
    lv_tileview_set_valid_positions(tileview, valid_pos, 2);

    lv_obj_t *obj1 = lv_obj_create(tileview, NULL);
    lv_obj_set_size(obj1, lv_obj_get_width(tileview), lv_obj_get_height(tileview));
    lv_obj_set_pos(obj1, 0, 0);
    lv_tileview_add_element(tileview, obj1);
    lv_obj_t *btn = lv_btn_create(tileview, NULL);
    lv_obj_align(btn, obj1, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_event_cb(btn, event_cb_test);
    lv_tileview_add_element(tileview, btn);

    lv_obj_t *obj2 = lv_obj_create(tileview, NULL);
    lv_obj_set_size(obj2, lv_obj_get_width(tileview), lv_obj_get_height(tileview));
    lv_obj_set_pos(obj2, lv_obj_get_width(tileview), 0);
    lv_tileview_add_element(tileview, obj2);
    lv_obj_t *btn2 = lv_btn_create(tileview, NULL);
    lv_obj_align(btn2, obj2, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_event_cb(btn2, event_cb_test);
    lv_tileview_add_element(tileview, btn2);
}

Try this:

    lv_obj_set_protect(obj1, LV_PROTECT_PRESS_LOST);

Thank you,this is so cool,Now it works great

1 Like

Glad to hear that! :slight_smile:

Wait, there is another case, when there are many elements on obj1, the area exposed by obj1 is very small, and the situation of false triggering will still occur, that is, the start and end of the finger are on the element

Similarly, if there is only one element on obj1, but the element is large and almost covers obj1, then the start and end points of the finger are on the same element, then the event of this element will also be triggered. I propose to provide an api, When this api is set, it will no longer trigger its event when the hand moves over a distance on the element

Wait, there is another case, when there are many elements on obj1, the area exposed by obj1 is very small, and the situation of false triggering will still occur, that is, the start and end of the finger are on the element

It shouldn’t be possible. Once the tile view is dragged, it shouldn’t search for a new object while you drag it. So you can’t “activate” a new object while you drag the tileview.

  • Is it possible that you get a false (additional) click from your touchpad when you release it?
  • Can you reproduce it in the simulator? If you can you send a video and code?

This problem can only occur at the starting point (0,0) or the end of the coordinate, because the tileview does not move only at the vertex. The problem is that the finger does not touch the tileview itself at all. I give an example. On the vertex (0,0), there is a huge btn, the size is the same as (0,0), so I want to slide to (-1,0) with my finger, (-1,0) does not exist, so Tileview is motionless, so when I take my finger off the screen, I leave on btn, so I will trigger the btn event, and since I have never encountered the tileview, lv_obj_protect has no way to take effect.

I see. This behavior has already changed in dev-7.0. There the drag will be set regardless the object has moved or not. You can

  • wait for v7.0 (still some months)
  • try dev-7.0
  • compare lv_core/lv_indev.c in master and dev-7.0 to see the changes and apply them manually. The gist should be in indev_drag() where proc->types.pointer.drag_in_prog = 1; is set.

thank you!!!3000 times

1 Like

You are welcome! :slight_smile:

My English so pool,I can’t understand what’s your mean.