Important: unclear posts may not receive useful answers.
Description
I’m trying to use styles, but they don’t seem to work as expected. I created a page with a single object and no widgets, and I set the background color to red using a style. However, the background appears white. If I apply the style directly to the object instead of the page, it works correctly.
It seems like the issue that background opacity isn’t getting applied through style.
What MCU/Processor/Board and compiler are you using?
esp32-s3-n16r8
What LVGL version are you using?
v9.3
What do you want to achieve?
I want to utilize styles instead of copy-n-paste the same info across the objects
What have you tried so far?
- If I have the style params applied through styles = background is white
- if I have the style params in the object = background is red (as expected)
- if I have the style params applied through styles and in addition I add opacity to the object = background is red as expected
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:
style definition -
temp_obj_style = new lv_style_t();
lv_style_init(temp_obj_style);
lv_style_set_bg_color(temp_obj_style, lv_color_make(255, 0, 0));
lv_style_set_bg_opa(temp_obj_style, LV_OPA_COVER);
lv_style_set_border_width(temp_obj_style, 0);
page -
lv_obj_t_id_14 = lv_obj_create(temp_sensors_page->obj);
lv_theme_apply_obj(lv_obj_t_id_14);
lv_obj_add_style(lv_obj_t_id_14, temp_obj_style, LV_PART_MAIN);
lv_obj_set_style_bg_opa(lv_obj_t_id_14, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_height(lv_obj_t_id_14, 290, LV_PART_MAIN);
lv_obj_set_style_width(lv_obj_t_id_14, lv_pct(100), LV_PART_MAIN);
lv_obj_set_style_x(lv_obj_t_id_14, 0, LV_PART_MAIN);
lv_obj_set_style_y(lv_obj_t_id_14, 30, LV_PART_MAIN);
removing the following line from the page will go back to white background:
lv_obj_set_style_bg_opa(lv_obj_t_id_14, LV_OPA_COVER, LV_PART_MAIN);
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.