Description
Absorbing (catching) an event of type LV_EVENT_PRESSING via an event handler causes the underlying object to be draggable inside the surrounding container. How can I prevent this behaviour ? Is there a function do deactivate dragging on an object ?
What MCU/Processor/Board and compiler are you using?
Linux (tested with SDL monitor.c and fbdev)
What LVGL version are you using?
Version 8.0
What do you want to achieve?
I want to draw pixels on a canvas, which works, but the dragging ruins the whole experience.
What have you tried so far?
Write an event handler on LV_EVENT_PRESSING, see below.
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
static void drawing_cb(lv_event_t* e){
lv_point_t p;
lv_area_t canvas_coords;
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* canv = (lv_obj_t*) lv_event_get_user_data(e);
lv_obj_get_coords(canv, &canvas_coords);
if(code == LV_EVENT_PRESSING) {
lv_indev_t *indev = lv_indev_get_act();
lv_indev_type_t indev_type = lv_indev_get_type(indev);
lv_canvas_set_px(canv, p.x-canvas_coords.x1, p.y-canvas_coords.y1, lv_color_black());
}
}
//...
lv_obj_t* draw_container = lv_obj_create(main_cont);
lv_obj_set_size(draw_container, draw_canv_width+100, draw_canv_height+100);
lv_obj_set_scrollbar_mode(draw_container, LV_SCROLLBAR_MODE_OFF);
lv_obj_align(draw_container, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_style(draw_container, &style_draw_container, 0);
lv_obj_t* draw_canv = lv_canvas_create(draw_container);
lv_canvas_set_buffer(draw_canv, scbuf, draw_canv_width, draw_canv_height, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED);
lv_obj_set_scrollbar_mode(draw_canv, LV_SCROLLBAR_MODE_OFF);
lv_obj_add_event_cb(draw_container, drawing_cb, LV_EVENT_PRESSING, draw_canv);
//...
Screenshot and/or video
Can provide a video later, but I think the problem is clear. Thanks for reading.