12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- use kahlo::math::PixelSideOffsets;
- use patina::{
- layout::SizePolicy,
- prelude::*,
- ui::{UIControlMsg, UIHandle},
- widget,
- };
- struct FormWindow {
- root: widget::Frame<Self>,
- }
- impl FormWindow {
- fn new(uih: &mut UIHandle) -> Self {
- let mut group = widget::FormGroup::new(uih);
- group
- .layout_node_mut()
- .set_height_policy(SizePolicy::fixed(0));
- group.set_label_margin(PixelSideOffsets::new(0, 10, 0, 10));
- group.add_widget(
- "button",
- widget::Button::new(uih).with_label("engage").boxed(),
- );
- group.add_widget(
- "button 2",
- widget::Button::new(uih).with_label("engage").boxed(),
- );
- group.add_widget(
- "button 3",
- widget::Button::new(uih).with_label("engage").boxed(),
- );
- group.add_widget(
- "button 4 with longer description",
- widget::Button::new(uih).with_label("engage").boxed(),
- );
- Self {
- root: widget::Frame::wrap_widget(group),
- }
- }
- }
- impl Component for FormWindow {
- type ParentMsg = UIControlMsg;
- type Msg = ();
- fn process(&mut self, _msg: Self::Msg) -> Vec<Self::ParentMsg> {
- let mut out = String::new();
- patina::layout::dump_node_tree(self.root.layout_node(), &mut out);
- std::fs::write("patina-form-example.layout_tree", out).expect("couldn't dump node tree");
- vec![UIControlMsg::Terminate]
- }
- }
- impl WindowComponent for FormWindow {
- fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
- match we {
- patina::window::WindowEvent::CloseRequested => Some(()),
- _ => None,
- }
- }
- type RootWidget = widget::Frame<Self>;
- fn root_widget(&self) -> &Self::RootWidget {
- &self.root
- }
- fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
- &mut self.root
- }
- }
- fn main() {
- patina::ui::make_opinionated_ui(FormWindow::new).run();
- }
|