table_layout.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. widget::Label::new_with_text(uih, "r1c1")
  16. .framed()
  17. .with_table_cell(TableCell::new(0, 0))
  18. .boxed(),
  19. widget::Label::new_with_text(uih, "r2c1")
  20. .framed()
  21. .with_table_cell(TableCell::new(0, 1))
  22. .boxed(),
  23. widget::Label::new_with_text(uih, "r2c2")
  24. .framed()
  25. .with_table_cell(TableCell::new(1, 1))
  26. .boxed(),
  27. widget::Label::new_with_text(uih, "r2c2")
  28. .framed()
  29. .with_table_cell(TableCell::new(1, 2))
  30. .boxed(),
  31. widget::Label::new_with_text(uih, "r3c2")
  32. .framed()
  33. .with_table_cell(TableCell::new(3, 2))
  34. .boxed(),
  35. ]
  36. .into_iter(),
  37. );
  38. Self { root: group }
  39. }
  40. }
  41. impl Component for TableWindow {
  42. type ParentMsg = UIControlMsg;
  43. type Msg = ();
  44. fn process(&mut self, _msg: Self::Msg) -> Vec<Self::ParentMsg> {
  45. vec![UIControlMsg::Terminate]
  46. }
  47. }
  48. impl WindowComponent for TableWindow {
  49. fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
  50. match we {
  51. patina::window::WindowEvent::CloseRequested => Some(()),
  52. _ => None,
  53. }
  54. }
  55. type RootWidget = widget::PlainGroup<Self>;
  56. fn root_widget(&self) -> &Self::RootWidget {
  57. &self.root
  58. }
  59. fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
  60. &mut self.root
  61. }
  62. }
  63. fn main() {
  64. patina::ui::make_opinionated_ui(TableWindow::new).run();
  65. }