Obj can't refresh new state when it happens while others are refreshing

The button state changed when other objects are refreshing,and the new state didn’t show correctly,it’s till in the previous state,but the state has changed as it should be by the set state function.

First of all ,the buttons here are to remind users what are they used for,they are not in a group and bind to input device,I set the state of it manualy when button pressed or released by sending event to its callback function,and set state in its callback.
The routine is like : button_pressed->send button pressing event->change its state to focused(a style aplly to it)->delete some objects and create some on the screen(change screen)->button released->send release event(change its state to default while the screen is still refreshing )->screen changed ok,but the new state of the button not changed on the screen.
If I release the button a little slowly after others’ refreshing done,then the new state will display good.


show the right state of the button when state changed

I trid to refresh it after others’ refreshing done,and it works,the new state will show good

A video I record upload to youtube

I think that object states can’t be altered mid-refresh without rendering problems like this. However, you should be able to use lv_async_call to schedule the call for the next LVGL “tick”. The delay is likely to be unnoticeable for a human.

Alternatively invalidating the object after changing its state might also work.

I’ll ping @kisvegabor to confirm.

1 Like

@embeddedt thank you,yes invalidate it works,but need to call it after the refreshing ongoing,or won’t work too.

Is there a callback after refreshing,then I can invalidate the buttons to refresh them in case they changed states when refreshing

monitor_cb is called when rendering finishes, but you wouldn’t want to unconditionally invalidate the buttons in there, or they would get redrawn on every single frame (which is a waste of power and CPU resources). You would need to check whether the state really did change.

I think using an async callback would be much cleaner.

1 Like

Yes,I can’t invalidate the buttons here ,it will loop there forever.I will check the function mentioned before.

Thanks @embeddedt I use the asycn callback to set the button state,it work good now.

I can confirm that, you can’t trigger invalidations, state changes, or any modification on objects during drawing.

I’m thinking about supporting at least invalidation but it’s still under consideration.

1 Like

Yeah,that’s a little inconvenient,especially when freshing goes slowly.
The events happened during drawing should be queued for later check,if something changed then refresh it.