Way to force Canvas repaint?

I’m using a Canvas to draw on, and would like to have a series of instructions to draw to the canvas, delay a bit, then draw something different to the canvas, delay a bit, etc. Basically showing all the intermediate steps in the drawing.

But, the Canvas does not actually repaint itself until the function I’m currently in finishes, at which point it only shows the last frame drawn. For reasons because of the context of the app, I can’t use a Timer component to build a series of timed draws.

Is there any way to force the Canvas to repaint out of its normal redraw cycle?

Edit: Here’s a clone link of an app that shows what currently happens. Push the button, and after a short delay, the square jumps quite a ways to the right, despite multiple calls to draw the canvas separated by artificial delays.

What I’d like is some way to display the intermediate draws as they happen.

https://anvil.works/build#clone:6X5CKODZHALI45GG=HZ5RM5FPSIKOSFSVTIR4CK7Y

Have you tried introducing a sleep rather than the artificial delay?

3 Likes

Just tried it, and that does the trick. Apparently the sleep allows other queued up actions to happen on the page. Thanks!

3 Likes