use patina::{prelude::*, ui::UIControlMsg, window::WindowComponent}; /// struct to represent a window and dispatch event processing within it struct SimpleWindow { widget: ::RootWidget, } impl SimpleWindow { fn new(uih: &mut patina::ui::UIHandle) -> Self { Self { widget: patina::widget::Frame::new(uih), } } } /// messages that can be sent to the window component enum SimpleWindowMsg { Close, } /// internal message handling impl Component for SimpleWindow { type ParentMsg = UIControlMsg; type Msg = SimpleWindowMsg; fn process(&mut self, msg: Self::Msg) -> Vec { match msg { SimpleWindowMsg::Close => vec![UIControlMsg::Terminate], } } } /// window-specific event handling impl WindowComponent for SimpleWindow { fn map_window_event(&self, we: patina::window::WindowEvent) -> Option { match we { patina::window::WindowEvent::CloseRequested => Some(SimpleWindowMsg::Close), _ => None, } } type RootWidget = patina::widget::Frame; fn root_widget(&self) -> &Self::RootWidget { &self.widget } fn root_widget_mut(&mut self) -> &mut Self::RootWidget { &mut self.widget } } fn main() { // see the docs for make_opinionated_ui patina::ui::make_opinionated_ui(SimpleWindow::new).run(); }