1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- use patina::{prelude::*, ui::UIControlMsg, window::WindowComponent};
- struct SimpleWindow {
- widget: <Self as WindowComponent>::RootWidget,
- }
- impl SimpleWindow {
- fn new(uih: &mut patina::ui::UIHandle) -> Self {
- Self {
- // widget: patina::widget::Spacer::new(uih),
- // widget: patina::widget::Label::new(uih),
- widget: patina::widget::Frame::new(uih),
- }
- }
- }
- enum SimpleWindowMsg {
- Close,
- }
- 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],
- }
- }
- }
- 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::Spacer<Self>;
- // type RootWidget = patina::widget::Label<Self>;
- 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() {
- patina::ui::make_opinionated_ui(SimpleWindow::new).run();
- }
|