use gtk::prelude::*; use relm4::prelude::*; struct App { counter: u8, } #[derive(Debug)] enum Msg { Increment, Decrement, } #[relm4::component] impl SimpleComponent for App { type Init = u8; type Input = Msg; type Output = (); view! { gtk::Window { set_title: Some("Simple app"), set_default_size: (300, 100), gtk::Box { set_orientation: gtk::Orientation::Vertical, set_spacing: 5, set_margin_all: 5, gtk::Button { set_label: "Increment", connect_clicked => Msg::Increment, }, gtk::Button { set_label: "Decrement", connect_clicked => Msg::Decrement, }, gtk::Label { #[watch] set_label: &format!("Counter: {}", model.counter), set_margin_all: 5, } } } } // Initialize the component. fn init( counter: Self::Init, root: Self::Root, sender: ComponentSender, ) -> ComponentParts { let model = App { counter }; // Insert the code generation of the view! macro here let widgets = view_output!(); ComponentParts { model, widgets } } fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { match msg { Msg::Increment => { self.counter = self.counter.wrapping_add(1); } Msg::Decrement => { self.counter = self.counter.wrapping_sub(1); } } } } fn main() { let app = RelmApp::new("relm4.example.simple"); app.run::(0); }