Transparent button or obj on top of other elements

Description

I am using LVGL v7 for a project that only needs some maintenance and I want to place a transparent element such as a button or plain obj to be able to use it as “touch region”. I have however noticed that the transparent style crashes my code.

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

ESP32

What LVGL version are you using?

LVGL v7

What do you want to achieve?

I want to place a “touch region” on top of my current elements to avoid identifying manual x,y coordinates. My goal is to have a transparent button/obj that allows me to listen for touch events

What have you tried so far?

I have made 2 approaches:
1.

lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);  // Create a button object
lv_obj_set_pos(btn, 10, 10);                          // Set its position
lv_obj_set_size(btn, 100, 50);                        // Set its size

lv_obj_set_event_cb(btn, button_event_handler);       // Assign the event callback

lv_style_t style_btn_transp;                          // Declare a new style

lv_style_init(&style_btn_transp);                     // Initialize the style
lv_style_set_bg_opa(&style_btn_transp, LV_STATE_DEFAULT, LV_OPA_TRANSP);   // Set background opacity to transparent
lv_style_set_border_width(&style_btn_transp, LV_STATE_DEFAULT, 0);         // No border

lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn_transp);  // Set the new style to the button
lv_obj_t * touch_area = lv_obj_create(parent, NULL);
lv_obj_set_pos(touch_area, x, y);
lv_obj_set_size(touch_area, width, height);
lv_obj_set_click(touch_area, true);
lv_obj_set_event_cb(touch_area, touch_area_event_handler);

lv_style_t style_transp;
lv_style_init(&style_transp);
lv_style_set_bg_opa(&style_transp, LV_STATE_DEFAULT, LV_OPA_TRANSP);   // Set background opacity to transparent
lv_style_set_border_width(&style_transp, LV_STATE_DEFAULT, 0);         // No border
lv_obj_add_style(touch_area, LV_OBJ_PART_MAIN, &style_transp);         // Set the new style to the object

this is my current widget structure:
±---------------+
| lv_scr_act |
±---------------+
|
v
±---------------+
| tileview |
±---------------+
/ |
v v v
±------------+ ±--------+ ±------------------+
| image | | button | | transparent elem. |
±------------+ ±--------+ ±------------------+

The code runs well when in either approach I do not set the transparency, and finally this is the error from the stack trace I get:

0x401d42bd: get_style_prop at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_style.c:1083

0x401d42bd: get_style_prop_id at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_style.c:1095

0x401d42bd: get_property_index at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_style.c:1008

0x401d42bd: _lv_style_get_int at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_style.c:520

0x4010962e: _lv_style_list_get_int at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_style.c:768

0x40105489: _lv_obj_get_style_int at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:2653

0x401067b8: lv_obj_get_style_radius at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj_style_dec.h:79

0x401067b8: lv_obj_init_draw_rect_dsc at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:3351

0x401071f6: style_snapshot at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:4771

0x40107467: lv_obj_set_state at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:1713

0x401076a3: lv_obj_add_state at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:1812

0x40107971: lv_obj_signal at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_obj.c:3997

0x4011dba2: lv_cont_signal at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_widgets/lv_cont.c:268

0x4011cc0b: lv_btn_signal at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_widgets/lv_btn.c:267

0x401288c6: indev_proc_press at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_indev.c:955

0x40128b8e: indev_pointer_proc at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_indev.c:440

0x40128cc1: _lv_indev_read_task at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_core/lv_indev.c:110

0x40115655: lv_task_exec at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_misc/lv_task.c:386

0x40115760: lv_task_handler at /Users/xyz/Documents/Arduino/libraries/lvgl/src/lv_misc/lv_task.c:134

0x400db2f4: loop() at /Users/xyz/my-lvgl/src/Blink.cpp:3167

0x4013b5c5: loopTask(void*) at /Users/xyz/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50

0x4008d3f5: vPortTaskWrapper at /Users/xyz/.platformio/packages/framework-espidf@3.40404.0/components/freertos/port/xtensa/port.c:142

Thanx for any help!

Styles are stored in variables. Style variables should be , global or dynamically allocated

Thanx!, that was the solution, defining styles as global