use kahlo::math::PixelSideOffsets; use patina::{ layout::SizePolicy, prelude::*, ui::{UIControlMsg, UIHandle}, widget, }; enum TextEditMsg { CloseRequest, } struct TextEditWindow { root: widget::Frame, } impl TextEditWindow { 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("simple editor:", { let mut edit = widget::TextEdit::new(uih); edit.set_text("default text"); edit.boxed() }); group.add_widget("simple editor:", { let mut edit = widget::TextEdit::new(uih); edit.set_text("......"); edit.boxed() }); group.add_widget("simple editor:", { let mut edit = widget::TextEdit::new(uih); edit.set_text("^^^^^^"); edit.boxed() }); Self { root: widget::Frame::wrap_widget(group), } } } impl Component for TextEditWindow { type ParentMsg = UIControlMsg; type Msg = TextEditMsg; fn process(&mut self, _msg: Self::Msg) -> Vec { 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"); let jsout = std::fs::File::create("patina-text-edit-example.json").unwrap(); patina::layout::dump_tree_json( self.root.layout_node(), &mut std::io::BufWriter::new(jsout), ) .expect("couldn't dump node tree JSON"); vec![UIControlMsg::Terminate] } } impl WindowComponent for TextEditWindow { fn map_window_event(&self, we: patina::window::WindowEvent) -> Option { match we { patina::window::WindowEvent::CloseRequested => Some(TextEditMsg::CloseRequest), _ => None, } } type RootWidget = widget::Frame; 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(TextEditWindow::new).run(); }