antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

Connect within update #179

Closed balping closed 5 years ago

balping commented 5 years ago

Hi,

I'm creating widgets dynamically, by reacting to events, inside the update() method. I'd like to add event listeners to the newly created widgets.

How could I use the connect! macro there? I don't seem to have access to the relm object there, just self.

antoyo commented 5 years ago

You need to save the relm object in your widget in the model() method, as done here. Then, you'll have access to it in the update() method via self.model.relm.

balping commented 5 years ago

Ah, thank you. I tried this, by saving a reference, but that didn't work – and I didn't think of clone(). Thanks again.