bodil / vgtk

A declarative desktop UI framework for Rust built on GTK and Gtk-rs
http://bodil.lol/vgtk/
Other
1.05k stars 37 forks source link

Complex data in messages #58

Open piegamesde opened 4 years ago

piegamesde commented 4 years ago

How are messages handled internally? Why do they require Send and Clone?

My concrete problem is that I have some images, stored as gdk_pixbuf::Pixbuf in the model. When clicking on a button, a new image is selected then loaded. So I thought I'd put the new Pixbuf into some AddImage message. But I cannot do this because Message requires Send. Also since Message is Clone I'm starting to doubt if putting big data into it is a good idea at all.

So, how should I go about this? How can I still communicated with and update my model?

wmww commented 4 years ago

I'm sorry if this is irrelevant and/or dumb, but would putting an Arc<Mutex<gdk_pixbuf::Pixbuf>> in the message solve your problem?

piegamesde commented 4 years ago

It's neither nor. The problem with glib types is they are internally Rc<RefCell> wrapped. They all have inner mutability and can be cloned and passed around freely. From a Rust perspective, this means that you have absolutely no control over the data in the inner and a Mutex sadly won't change that.