a stackoverflow question up for grabs :slightly_sm...
# compose-desktop
a
k
You wouldn't want the canvas to keep its state. Canvas is, well, canvas. You issue drawing commands for "this" particular frame. Every frame you issue new commands. So if you want some objects to persist, if you will, you need to store those objects, along with operations to add/remove them. And then your drawing pass goes over all the current objects and "converts" them to canvas drawing commands.
a
Meaning, on every click I re-draw all the objects that I’ve created?
k
Yes, this is how canvas works
a
Thanks!
k
Otherwise it'd be pure madness to "erase" previously drawn content on every frame
a
it’s not how the same code works with drawing the Path object’s though, but probably that is the specifics of that specific object? code: https://github.com/antonarhipov/compose-for-desktop-samples/blob/main/src/main/kotlin/Strokes.kt
o
@antonarhipov the difference is that you remembered the path and modifying it. Essentially, the path is your storage of drawing commands. Canvas is redrawn each time, but the path is accumulating the changes
🙏 1
y
I have created this little prototype for a project I am working on

https://www.youtube.com/watch?v=ST3pGgbns3A

. So I confirm that what you are trying to do can be done but the "state" is in the model.. not with the canvas. The canvas call simply renders the background image + every widget on top (including their state, like when selected, it draws a yellow rectangle around). And I am also handling all the drag/drop myself. Once you wrap your head around the model it is actually not that hard and pretty clean.