table_layout.rs 1.2 KB

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