use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt}; use relm4::{ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent}; 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("Log example"), 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 { set_margin_all: 5, #[watch] set_label: &format!("Counter: {}", model.counter), } } } } fn init( counter: Self::Init, root: Self::Root, sender: ComponentSender, ) -> ComponentParts { let model = App { counter }; // Insert the macro code generation 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() { // Show traces to find potential performance bottlenecks, for example tracing_subscriber::fmt() .with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL) .with_max_level(tracing::Level::TRACE) .init(); tracing::info!("Starting application!"); let app = RelmApp::new("relm4.example.log"); app.run::(0); }