123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- use patina::{prelude::*, ui::UIControlMsg, window::WindowComponent};
- /// struct to represent a window and dispatch event processing within it
- struct SimpleWindow {
- widget: <Self as WindowComponent>::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<Self::ParentMsg> {
- 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<Self::Msg> {
- match we {
- patina::window::WindowEvent::CloseRequested => Some(SimpleWindowMsg::Close),
- _ => None,
- }
- }
- type RootWidget = patina::widget::Frame<Self>;
- 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();
- }
|