Improving the organization of the application
The main function is starting to get bigger, so we'll refactor our code a little to make it easier to update in the upcoming sections and chapters.
First, we'll create a new module called toolbar. As a reminder, here's how to do so:
- Create a new file:
src/toolbar.rs. - Add a statement,
mod toolbar;, at the top of the filemain.rs.
This new module toolbar will start with the import statement and the const declaration:
use gtk::{
ContainerExt,
SeparatorToolItem,
Toolbar,
ToolButton,
};
const PLAY_STOCK: &str = "gtk-media-play";We'll then create a new structure holding all the widgets that compose the toolbar:
pub struct MusicToolbar {
open_button: ToolButton,
next_button: ToolButton,
play_button: ToolButton,
previous_button: ToolButton,
quit_button: ToolButton,
remove_button: ToolButton,
stop_button: ToolButton,
toolbar: Toolbar,
}We use the pub keyword here because we want to be able to use this type...