January 2018
Beginner to intermediate
454 pages
10h 8m
English
So, let's see how to send a message to the same widget without using this syntax: this is useful in more complex cases, such as when we want to conditionally send a message. Let's go back to our Playlist and add a play() method:
impl Playlist { fn play(&mut self) { if let Some(path) = self.selected_path() { self.model.current_song = Some(path.into()); self.model.relm.stream().emit(SongStarted(self.pixbuf())); } } }
This line sends a message to the current widget:
self.model.relm.stream().emit(SongStarted(self.pixbuf()));
We first get the event stream from the relm widget and then call emit() on it with a message. This play() method requires two new methods:
use gtk::{ TreeModelExt, TreeSelectionExt, }; impl Playlist { fn pixbuf(&self ...