Hi All,
I am having some trouble wrapping my head around Iced’s memory mutability model.
I am currently learning Iced by playing with the integration example. Here we have two structs that contain state. We have a Controls struct that implements Program and handles messages from the UI and we have a Scene struct that contains state regarding the wgpu canvas and pipelines. The problem I have now is that I want the content on my wgpu canvas to respond to both input from the UI and input from winit, such as window resizes and key input events.
The main problem I face is that I cannot modify the Controls struct from main.rs where the winit events are handled. From there I can however modify the Scene struct that handles the wgpu state. So up to now I had all wgpu canvas state in the Scene struct. This worked fine, but it did mean that often I had to communicate state from the UI through main.rs by reading from the Controls struct and modifying the Scene. This did not feel very ergonomic already but I encountered an issue related to buttons. I can nicely communicate the state of a slider for example, but a button is a one off event. I can set some field like program.button_is_pressed to true when a message comes in, but after I handled that in main.rs I have no way of resetting that button_is_pressed field. The Controls struct is after all not mutable in main.rs.
I feel like I am fighting the design. Surely there is a more ergonomic way to store the state such that I can handle both UI messages and window events. Any tips would be greatly appreciated.
Cheers,
Timo