simplest.rs 1.4 KB

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