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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::*;

// Using this depends on https://github.com/rust-lang/rust/issues/63063
pub trait Body: View {
    type V: View;
    fn body(&self) -> Self::V;

    fn print(&self, id: ViewID, cx: &mut Context) {
        self.body().print(id, cx)
    }

    fn process(&self, event: &Event, id: ViewID, cx: &mut Context, vger: &mut VGER) {
        self.body().process(event, id, cx, vger)
    }

    fn draw(&self, id: ViewID, cx: &mut Context, vger: &mut VGER) {
        self.body().draw(id, cx, vger)
    }

    fn layout(&self, id: ViewID, sz: LocalSize, cx: &mut Context, vger: &mut VGER) -> LocalSize {
        self.body().layout(id, sz, cx, vger)
    }

    fn hittest(
        &self,
        id: ViewID,
        pt: LocalPoint,
        cx: &mut Context,
        vger: &mut VGER,
    ) -> Option<ViewID> {
        self.body().hittest(id, pt, cx, vger)
    }

    fn commands(&self, id: ViewID, cx: &mut Context, cmds: &mut Vec<CommandInfo>) {
        self.body().commands(id, cx, cmds);
    }
}

#[macro_export]
macro_rules! body_view {
    () => {
        fn print(&self, id: ViewID, cx: &mut Context) {
            self.body().print(id, cx)
        }

        fn process(&self, event: &Event, id: ViewID, cx: &mut Context, vger: &mut VGER) {
            self.body().process(event, id, cx, vger)
        }

        fn draw(&self, id: ViewID, cx: &mut Context, vger: &mut VGER) {
            self.body().draw(id, cx, vger)
        }

        fn layout(
            &self,
            id: ViewID,
            sz: LocalSize,
            cx: &mut Context,
            vger: &mut VGER,
        ) -> LocalSize {
            self.body().layout(id, sz, cx, vger)
        }

        fn hittest(
            &self,
            id: ViewID,
            pt: LocalPoint,
            cx: &mut Context,
            vger: &mut VGER,
        ) -> Option<ViewID> {
            self.body().hittest(id, pt, cx, vger)
        }

        fn commands(&self, id: ViewID, cx: &mut Context, cmds: &mut Vec<CommandInfo>) {
            self.body().commands(id, cx, cmds);
        }

        fn gc(&self, id: ViewID, cx: &mut Context, map: &mut StateMap) {
            self.body().gc(id, cx, map)
        }

        fn access(
            &self,
            id: ViewID,
            cx: &mut Context,
            nodes: &mut Vec<accesskit::Node>,
        ) -> Option<accesskit::NodeId> {
            self.body().access(id, cx, nodes)
        }
    };
}