table_layout.rs 1.4 KB

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