i think its continuation of question that was asked in topic
so ive faced the same question. seems with lv_obj_add_style i need to watch on styles to not to get memory leak if i want to change styles of some objects frequently?
why threre is no
lv_obj_set_style method that just overwrite 1st added style to object?
for example - i want my button to change color when pressed from red to green and back . so i need to add 2 styles and switch them somehow or i need to use local style.
i think it would be great to have option to set style without adding another pointer to pointer list of object
and on other hand - add method “lv_obj_switch_style(lv_obj_t *object,uint8_t style_number, LV_PART)”
To add a style for pressed state you should use the
lv_obj_add_style(btn, &style_pressed, LV_STATE_PRESSED);
no i am talking about switching styles
for example i want to switch style for button in pressed state ( LV_STATE_PRESSED)
and for example i will do it 100 times per hour.
so i am talking about method that will set style pressed as 1st pointer (not just adding another one)
hope u understand what i am trying to say.
lets create expample
i need to change font of label in button when it pressed that depends on 3rd-party variable.
so if variable for example is false i need to set style of pressed button to style 1
and if true i need to switch pressed button style to style2
how should i make it?
as i know if i use add style every time - i will get memory leak because pointers will be added every time to style pointers list and for a first point of view it will work,because last added style will be actual style
but in couple of hours there will be ton of pointers added to object style list?
I see now and I can suggest 2 things:
- The less elegant method: Use
lv_obj_remove_style to remove the style(s) you don’t need.
lv_obj_remove_style_all removes all styles so you can build it from scratch (not that internally the x, y, width, and height are also local style properties so they will be also removed with
- The pro method: Let’s say you want to add
true. You can add
style_red to the
LV_STATE_USER_1 and use
lv_obj_add/clear_state(obj, LV_STATE_USER_1) depending on
state in the