form_demo.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. use kahlo::math::PixelSideOffsets;
  2. use patina::{
  3. layout::SizePolicy,
  4. prelude::*,
  5. ui::{UIControlMsg, UIHandle},
  6. widget,
  7. };
  8. struct FormWindow {
  9. root: widget::Frame<Self>,
  10. }
  11. impl FormWindow {
  12. fn new(uih: &mut UIHandle) -> Self {
  13. let mut group = widget::FormGroup::new(uih);
  14. group
  15. .layout_node_mut()
  16. .set_height_policy(SizePolicy::fixed(0));
  17. group.set_label_margin(PixelSideOffsets::new(0, 10, 0, 10));
  18. group.add_widget(
  19. "button",
  20. widget::Button::new(uih).with_label("engage").boxed(),
  21. );
  22. group.add_widget(
  23. "button 2",
  24. widget::Button::new(uih).with_label("engage").boxed(),
  25. );
  26. group.add_widget(
  27. "button 3",
  28. widget::Button::new(uih).with_label("engage").boxed(),
  29. );
  30. group.add_widget(
  31. "button 4 with longer description",
  32. widget::Button::new(uih).with_label("engage").boxed(),
  33. );
  34. Self {
  35. root: widget::Frame::wrap_widget(group),
  36. }
  37. }
  38. }
  39. impl Component for FormWindow {
  40. type ParentMsg = UIControlMsg;
  41. type Msg = ();
  42. fn process(&mut self, _msg: Self::Msg) -> Vec<Self::ParentMsg> {
  43. vec![UIControlMsg::Terminate]
  44. }
  45. }
  46. impl WindowComponent for FormWindow {
  47. fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
  48. match we {
  49. patina::window::WindowEvent::CloseRequested => Some(()),
  50. _ => None,
  51. }
  52. }
  53. type RootWidget = widget::Frame<Self>;
  54. fn root_widget(&self) -> &Self::RootWidget {
  55. &self.root
  56. }
  57. fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
  58. &mut self.root
  59. }
  60. }
  61. fn main() {
  62. patina::ui::make_opinionated_ui(FormWindow::new).run();
  63. }