Canvas not consuming events - objects below can be triggered?

HI !

I’m a little bit confused about how canvas is handling events.

To implement a touch panel calibration function I like to cover the current screen with a canvas and draw some cross marks on it the user must hit for calibration.

But obviously the callbacks of the elements behind the canvas are triggered also if they are hit. Contrarily if I use an other object type (e.g. a container (lv_obj_cont_create) or even the base object lv_obj_create) the events are “consumed” by the this top most object as expected.

for example, this simple base object is consuming all events (objects below will not be triggered):

static lv_obj_t* canvas;

canvas = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(canvas, LV_HOR_RES, LV_VER_RES);
lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0);

but not for canvas:

static lv_obj_t* canvas;
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(LV_HOR_RES_MAX, LV_VER_RES_MAX)];

canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_obj_set_size(canvas, LV_HOR_RES_MAX, LV_VER_RES_MAX);
lv_canvas_set_buffer(canvas, cbuf, LV_HOR_RES, LV_VER_RES, LV_IMG_CF_TRUE_COLOR);
lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0);
lv_canvas_fill_bg(canvas, LV_COLOR_GREEN, LV_OPA_COVER);

Bug or feature ? :smiley:

Best regards,
Michael.

Canvases are derived from images, which by default do not consume input events. If you want it to be able to, call lv_obj_set_click(canvas, true) on the newly created canvas.

Thanks for clarification.

Now this makes sense, because the callback of the canvas wasn’t working at all :wink:

Maybe the documentation should state that.
Reading the doc implies an active event behavior for me …

Contribution is welcome :slight_smile:
Can you send a Pull request on the docs to clarify it?

done (to the best of my knowledge)

I can’t see it here: https://github.com/lvgl/docs/pulls
See some hints here: https://github.com/lvgl/docs#fix-typos-add-missing-parts

Oh - sorry. Indeed there is no PR visible in lvgl/doc.

I tried to follow the editing process - at the end there was an automatic fork of the repo and a new branch patch-1 created …

But obviously the PR must be triggered manually from the forked repo …

Merged, thank you!