1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{View, Node, Bind, Context, Identified, Binding, Event, IdPath};

#[derive(Debug, Clone)]
pub struct TextField {
    content: Binding<String>,
}

impl TextField {
    pub fn new(content: Binding<String>) -> Self {
        Self { content }
    }
}

impl Bind for TextField {
    fn bind(&mut self, _context: &Context) {}
}

impl View for TextField {
    fn fire(&self, event: &Event, id_path: &IdPath) {
        assert!(id_path.is_root());
        if let Event::UpdateText { content } = event {
            self.content.set(content.to_owned());
        }
    }

    fn render(&mut self, context: &Context) -> Identified<Node> {
        self.bind(context);
        context.identify(Node::TextField { content: self.content.get() })
    }
}