simplest.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use patina::{
  2. prelude::*, ui::UIControlMsg, window::WindowComponent
  3. };
  4. struct SimpleWindow {
  5. widget: <Self as WindowComponent>::RootWidget,
  6. }
  7. impl SimpleWindow {
  8. fn new(uih: &patina::ui::UIHandle) -> Self {
  9. Self { widget: patina::widget::Spacer::new(uih) }
  10. }
  11. }
  12. enum SimpleWindowMsg {
  13. Close,
  14. }
  15. impl Component for SimpleWindow {
  16. type ParentMsg = UIControlMsg;
  17. type Msg = SimpleWindowMsg;
  18. fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg> {
  19. match msg {
  20. SimpleWindowMsg::Close => vec![UIControlMsg::Terminate],
  21. }
  22. }
  23. }
  24. impl WindowComponent for SimpleWindow {
  25. fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
  26. match we {
  27. patina::window::WindowEvent::CloseRequested => {
  28. Some(SimpleWindowMsg::Close)
  29. },
  30. _ => None
  31. }
  32. }
  33. type RootWidget = patina::widget::Spacer<Self>;
  34. fn root_widget(&self) -> &Self::RootWidget {
  35. &self.widget
  36. }
  37. fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
  38. &mut self.widget
  39. }
  40. }
  41. fn main() {
  42. patina::ui::make_opinionated_ui(|uih| {
  43. SimpleWindow::new(uih)
  44. }).run();
  45. }