January 2018
Beginner to intermediate
454 pages
10h 8m
English
Views are created in a declarative way in relm as a part of the Widget trait:
use gtk::{ GtkWindowExt, Inhibit, WidgetExt, }; use relm::Widget; use relm_attributes::widget; use self::Msg::*; #[widget] impl Widget for App { // … view! { gtk::Window { title: "Rusic", delete_event(_, _) => (Quit, Inhibit(false)), } } }
We first imported some stuff from the gtk crate. Then we imported the Widget trait from relm and the widget attribute. Later, we imported the variant of our enum Msg because we use it in this code. To declare the view, we use the view! macro. This macro is very particular, it is not a macro that is declared as macro_rules!, as we saw in Chapter 1, Basics of Rust. Instead, it is parsed by the procedural macro implementing ...