How to drag and drop an image and check for collision

Hi everyone,

Is there a way to create an lvgl image, drag and drop it, and then when moving, check for collision with another image.
Seems no events are working for me :thinking:

lv_obj_t* img = lv_img_create(NULL);
lv_img_set_src(img, &my_image);
lv_obj_add_event_cb(img, do_something, LV_EVENT_PRESSING, NULL);

I don’t know if someone already tried to do something like this.
If possible I don’t want to use imgbtn which is slower than the img element (I’m using LittleFS for rendering)

Thanks a lot for help

Ok, I found that lv_obj_set_click as been moved to

  lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE);

Now, I’ve to see how make collision working ^^

Check with AABB collision detection in the image drag events.
(LVGL objects have x, y, AND x2, y2 fields, so use those instead of calculating (x+width), (y+height))

1 Like

Interesting, I thought there was something generic with LVGL, but I’ll try to play with it and create something generic, maybe it can be interesting for the Core :thinking: