table_layout.rs 2.3 KB

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