simplest.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. }
  11. }
  12. }
  13. enum SimpleWindowMsg {
  14. Close,
  15. }
  16. impl Component for SimpleWindow {
  17. type ParentMsg = UIControlMsg;
  18. type Msg = SimpleWindowMsg;
  19. fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg> {
  20. match msg {
  21. SimpleWindowMsg::Close => vec![UIControlMsg::Terminate],
  22. }
  23. }
  24. }
  25. impl WindowComponent for SimpleWindow {
  26. fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
  27. match we {
  28. patina::window::WindowEvent::CloseRequested => Some(SimpleWindowMsg::Close),
  29. _ => None,
  30. }
  31. }
  32. // type RootWidget = patina::widget::Spacer<Self>;
  33. type RootWidget = patina::widget::Label<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(SimpleWindow::new).run();
  43. }