table_layout.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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(
  13. vec![
  14. Box::new(widget::Spacer::new(uih)) as Box<dyn Widget<Self>>,
  15. Box::new(widget::Spacer::new(uih)),
  16. ]
  17. .into_iter(),
  18. );
  19. Self { root: group }
  20. }
  21. }
  22. impl Component for TableWindow {
  23. type ParentMsg = UIControlMsg;
  24. type Msg = ();
  25. fn process(&mut self, _msg: Self::Msg) -> Vec<Self::ParentMsg> {
  26. vec![UIControlMsg::Terminate]
  27. }
  28. }
  29. impl WindowComponent for TableWindow {
  30. fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
  31. match we {
  32. patina::window::WindowEvent::CloseRequested => Some(()),
  33. _ => None,
  34. }
  35. }
  36. type RootWidget = widget::PlainGroup<Self>;
  37. fn root_widget(&self) -> &Self::RootWidget {
  38. &self.root
  39. }
  40. fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
  41. &mut self.root
  42. }
  43. }
  44. fn main() {
  45. patina::ui::make_opinionated_ui(TableWindow::new).run();
  46. }