Description
I’m trying to make an object fire a callback when clicked. This object contains labels and LED’s but so far I have been unsuccessful and this only seems to work on areas of the object that do not have LED’s or labels on them.
In the code below you can see I’ve enabled click for the object and defined a callback. This only works if I click the very bottom part of the object (CYL5 line - it’s empty now as opposed to the screenshot below).
I want to be able to click anything in the object (any label or LED) within the green lines to trigger the callback function.
What MCU/Processor/Board and compiler are you using?
Teensy 4.0 - Arduino IDE
What LVGL version are you using?
7.10.1
Code to reproduce
static lv_obj_t * gauge_cont;
static lv_obj_t * param_cont;
static lv_obj_t * ignition_cont;
LV_EVENT_CB_DECLARE(rstIgnitionVals);
void startScreen(){
//Create screen object
lv_obj_t * obj0 = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_width(obj0, 480);
lv_obj_set_height(obj0, 320);
lv_obj_set_x(obj0, 0);
lv_obj_set_y(obj0, 0);
lv_obj_clean_style_list(obj0, LV_OBJ_PART_MAIN);
lv_obj_add_style(obj0, LV_GAUGE_PART_NEEDLE, &style1);
//Left side gauge object
gauge_cont = lv_obj_create(obj0, NULL);
lv_obj_clean_style_list(gauge_cont, LV_OBJ_PART_MAIN);
lv_obj_set_x(gauge_cont, 0);
lv_obj_set_y(gauge_cont, 0);
lv_obj_set_width(gauge_cont, 320);
lv_obj_set_height(gauge_cont, 320);
//Right side param object
param_cont = lv_obj_create(obj0,NULL);
lv_obj_clean_style_list(param_cont, LV_OBJ_PART_MAIN);
lv_obj_set_x(param_cont, 280);
lv_obj_set_y(param_cont, 0);
lv_obj_set_width(param_cont, 200);
lv_obj_set_height(param_cont, 320);
lv_obj_set_click(param_cont, true);
//Bottom side ignition param object
ignition_cont = lv_obj_create(param_cont, NULL);
lv_obj_clean_style_list(ignition_cont, LV_OBJ_PART_MAIN);
lv_obj_set_x(ignition_cont, 30);
lv_obj_set_y(ignition_cont, 220);
lv_obj_set_width(ignition_cont, 170);
lv_obj_set_height(ignition_cont, 100);
lv_obj_set_click(ignition_cont, true);
lv_obj_set_event_cb(ignition_cont, rstIgnitionVals);
/*
A bunch more code creating labels and LED's all assigned to ignition_cont object
*/
}
LV_EVENT_CB_DECLARE(rstIgnitionVals){
//Resets some variables
};
Screenshot and/or video
Yellow is gauge_cont
Purple is param_cont
Green is ignition_cont - CYL5 label and inline objects are not in the actual code anymore and only clicking on that empty area at the bottom of the container triggers the callback.