123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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> {
- 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();
- }
|