12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- use kahlo::math::PixelSideOffsets;
- use patina::{
- layout::SizePolicy,
- prelude::*,
- ui::{UIControlMsg, UIHandle},
- widget,
- };
- enum TextEditMsg {
- CloseRequest,
- }
- struct TextEditWindow {
- root: widget::Frame<Self>,
- }
- 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<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");
- 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<Self::Msg> {
- match we {
- patina::window::WindowEvent::CloseRequested => Some(TextEditMsg::CloseRequest),
- _ => 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(TextEditWindow::new).run();
- }
|