simplest.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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::Frame::new(uih),
  9. }
  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 => Some(SimpleWindowMsg::Close),
  28. _ => None,
  29. }
  30. }
  31. type RootWidget = patina::widget::Frame<Self>;
  32. fn root_widget(&self) -> &Self::RootWidget {
  33. &self.widget
  34. }
  35. fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
  36. &mut self.widget
  37. }
  38. }
  39. fn main() {
  40. patina::ui::make_opinionated_ui(SimpleWindow::new).run();
  41. }