12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- use patina::{
- prelude::*,
- window::{Window, WindowComponent},
- };
- struct SimpleWindow {
- widget: <Self as WindowComponent>::RootWidget,
- }
- impl Component for SimpleWindow {
- type ParentMsg = ();
- type Msg = ();
- fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg> {
- vec![()]
- }
- }
- impl WindowComponent for SimpleWindow {
- fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
- Some(())
- }
- type RootWidget = patina::widget::Spacer<Self>;
- fn root_widget(&self) -> &Self::RootWidget {
- &self.widget
- }
- fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
- &mut self.widget
- }
- }
- struct Simplest {
- main_window: Option<Window<SimpleWindow>>,
- }
- impl Component for Simplest {
- type ParentMsg = patina::UIControlMsg;
- type Msg = ();
- fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg> {
- vec![patina::UIControlMsg::Terminate]
- }
- }
- impl patina::UIComponent for Simplest {
- fn init<'l>(&mut self, mut ui_handle: patina::UIHandle<'_>) {
- let mut widget = patina::widget::Spacer::new(&ui_handle);
- widget.layout_node_mut().set_width_policy(patina::layout::SizePolicy { minimum: 0, desired: 0, slack_weight: 1 });
- widget.layout_node_mut().set_height_policy(patina::layout::SizePolicy { minimum: 0, desired: 0, slack_weight: 1 });
- self.main_window = Some(ui_handle.window_builder().build(|uih| SimpleWindow {
- widget
- }));
- }
- fn poll(&mut self) -> Vec<patina::UIControlMsg> {
- let Some(mw) = self.main_window.as_mut() else { return vec![] };
- let evts = mw.poll();
- self.process_all(evts.into_iter())
- }
- }
- fn main() {
- let ui = patina::UI::<Simplest>::new(Simplest { main_window: None });
- ui.run();
- }
|