Adding tool button events
We'll continue by adding event handlers to some of the buttons.
First of all, we'll need new use
statements:
use gtk::{ ToolButtonExt, WidgetExt, }; use App;
We import ToolButtonExt
, which provides methods to be called on ToolButton
and App
from the main
module, because we'll add a new method to this type:
impl App { pub fn connect_toolbar_events(&self) { let window = self.window.clone(); self.toolbar.quit_button.connect_clicked(move |_| { window.destroy(); }); } }
In Rust, it's perfectly valid to declare a method in a module different to where the type was created. Here, we say that clicking the quit button will destroy the window, which will effectively exit the application.
Let's add another event that will toggle the play button image with the pause image:
let play_button = self.toolbar.play_button.clone(); self.toolbar.play_button.connect_clicked(move |_| { if play_button.get_stock_id() == Some...