January 2018
Beginner to intermediate
454 pages
10h 8m
English
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 ...