Hello,
I’m trying to get the default bg-color of a pressed button.
The example on line 35 in lvgl/src/lv_core/lv_obj_style_dec.h suggests that I could use lv_obj_get_style_local_bg_color() for this. But the compiler complains that no such function exists.
What am I missing here?
(cc @kisvegabor)
I think the example in that header file is wrong. As far as I know there has never been a way to do this for the local style.
lv_obj_get_style_local_bg_color
is really not not exists.
However, it seems you need lv_obj_get_style_bg_color
because it considers all the add styles and the local style too. If you need to get the final color of a state different than a current one you need to put the object manually into that state and disable style transitions.
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_state_t state_ori = btn->state;
btn->state = LV_STATE_PRESSED;
btn->style_list.skip_trans = 1;
lv_color_t color = lv_obj_get_style_bg_color(btn, LV_BTN_PART_MAIN);
btn->state = state_ori;
btn->style_list.skip_trans = 0;
So I have a button with a given color. The color indicates the current state of some real-world object. I’ configured the default state, the pressed state, and any other state I can possibly configure for this button to this color.
Now I’d like to open a popup-menu when this button is pressed and indicate this color in some way in this popup.
Unfortunately, when I press the button, the color changes to some other color which I’ve never set in any way. So my popup gets NOT the color I configured for the button for all the states I could imagine. Right after I’m done creating the popup, the button reverts to the configured color.
You probably tried this already, but on the off-chance that you didn’t… have you set the color for the (admittedly not intuitive) combination LV_STATE_PRESSED | LV_STATE_FOCUSED
?