use patina::{ prelude::*, ui::{UIControlMsg, UIHandle}, widget, }; enum ButtonWindowMsg { Shutdown, } struct ButtonWindow { group: widget::PlainGroup, } impl ButtonWindow { fn new(uih: &mut UIHandle) -> Self { let mut group = widget::PlainGroup::new_column(uih); group.extend( vec![ Box::new(widget::Spacer::new(uih)) as Box>, Box::new({ let mut button = widget::Button::new(uih); button.set_label("Button label"); button.set_hook(Box::new(|| Some(ButtonWindowMsg::Shutdown))); button }), Box::new(widget::Spacer::new(uih)), ] .into_iter(), ); Self { group } } } impl Component for ButtonWindow { type ParentMsg = UIControlMsg; type Msg = ButtonWindowMsg; fn process(&mut self, msg: Self::Msg) -> Vec { match msg { ButtonWindowMsg::Shutdown => vec![UIControlMsg::Terminate], } } } impl WindowComponent for ButtonWindow { fn map_window_event(&self, we: patina::window::WindowEvent) -> Option { match we { patina::window::WindowEvent::CloseRequested => Some(ButtonWindowMsg::Shutdown), _ => None, } } type RootWidget = widget::PlainGroup; fn root_widget(&self) -> &Self::RootWidget { &self.group } fn root_widget_mut(&mut self) -> &mut Self::RootWidget { &mut self.group } } fn main() { patina::ui::make_opinionated_ui(ButtonWindow::new).run(); }