I have a container , with a picture that changes color when I push a button. This works fine in Arduino IDE/esp32 with : _ui_state_modify(ui_Container1, LV_STATE_USER_1, _UI_MODIFY_STATE_TOGGLE);
But I want to go back to my default setting without pressing the button again, but after a defined time.
I tried to put lv_obj_set_style_bg_img_src(ui_Container1, &ui_img_doorbell_groen_20x20n_png, LV_PART_MAIN | LV_STATE_DEFAULT); , but this is not working.
You can use _ui_state_modify() in the timed callback too, to change/toggle the original state back I guess. (But maybe I don’t get correctly what you want to achieve, because in the first part you say you change to the ‘color’ of USER_1 state , but in the second part you want to change back to an original image.)
Anyway, after you change to USER_1 state, it overrides the DEFAULT state, that’s why you don’t see a change, as the widget is still in USER_1 state. So to change the image in USER_1 state (if you want that), the last LV_STATE_DEFAULT should be changed to LV_STATE_USER_1 to see any change at that state.
Hi, thank you for your feedback.
Sorry for the confusing… I have 2 images, both different color, so when I said change color, it really was the image.
When I use the exported files, I still have the problem that my event is not working in Arduino ide with esp32-2432s028. Nothing happens when I push the button.
Only _ui_state_modify(ui_Container1, LV_STATE_USER_1, _UI_MODIFY_STATE_ADD);
lv_img_set_src(ui_Image1, &ui_img_bell_rood20x20n_png); that I put in arduino loop, gave a change from default green image to red image. But adding a delay of 1sec (up to 5 tried) and then _ui_state_modify(ui_Container1, LV_STATE_DEFAULT, _UI_MODIFY_STATE_ADD); even made the application not change from green to red in the first place.
I am sorry, but do not understand the second part : after you change to USER_1 state, it overrides the DEFAULT state, that’s why you don’t see a change, as the widget is still in USER_1 state…my default is green image, if I go to red image (user1), it should show red …isn;t it ?
Can you advise what I have to do to :
Be able to use the squareline exported files in arduino IDE /confirm that the button pressed should work in arduino, just as in your simulator./or what to do to make it work.
what do I need to do in the event section to go from green image to red image on pressed, and from red image to green image on release button1 ? (I changed in the mean time from just image instead of image in a container).
Note : In the exported squareline files, in the loop, there is no lv_task_handler();. from chatgpt, I learned that this is required to process GUI events…is that correct ? If correct, is there a reason why it is not put into the .ino file ?
thanks and regards
Ludo
-The button event that toggles USER_1 state should work in Arduino if it works in SquareLine Studio. (It’s just not pit into ui_events.c, but ui.c)
-I think you should read the ‘States’ section in LVGL document about objects, that explains in details that there can be more states enabled, DEFAULT is the state, and other states can override it until they’re removed. So you should remove LV_STATE_USER_1 to get the original red color/image back.
-Presence of lv_task_handler in he loop is required for LVGL to process events, update graphic when needed, etc.