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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use crate::{Drawable, screen::ZelData};
use super::*;

// == drawable implementation for modifiers
impl<'d, D:Drawable> Drawable for Offset<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect {
        self.1.borrow(|d| d.bounds().translate(-self.0.to_vector()))
    }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| d.raw_touch(zp.add_size(&self.0.to_vector().to_size()), format, modify))
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| d.deposit_supertile(zp.add_size(&self.0.to_vector().to_size()), tile))
    }
}

impl<'d, D:Drawable> Drawable for Clip<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect { self.0 }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        if !self.0.contains(zp) { return; }
        self.1.borrow(|d| d.raw_touch(zp, format, modify))
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        if !self.0.contains(zp) { return; }
        self.1.borrow(|d| d.deposit_supertile(zp, tile))
    }
}

impl<'d, D:Drawable> Drawable for SetFont<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.0 }

    fn bounds(&self) -> ZelRect { self.1.borrow(|d| d.bounds()) }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| { d.raw_touch(zp, format, modify); } )
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| { d.deposit_supertile(zp, tile)})
    }
}

impl<'d, D:Drawable> Drawable for SetFg<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect { self.1.borrow(|d| d.bounds()) }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| { d.raw_touch(zp, format, |z| { 
            if format { z.fg = self.0; } 
            modify(z);
        }); } )
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| { d.deposit_supertile(zp, tile)})
    }
}

impl<'d, D:Drawable> Drawable for SetBg<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect { self.1.borrow(|d| d.bounds()) }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| { d.raw_touch(zp, format, |z| { 
            if format { z.bg = self.0 }
            modify(z);
        }); } )
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| { d.deposit_supertile(zp, tile)})
    }
}

impl<'d, D:Drawable> Drawable for SetClick<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect { self.1.borrow(|d| d.bounds()) }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| { d.raw_touch(zp, format, |z| { 
            if format { z.click = self.0 }
            modify(z); 
        }); } )
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| { d.deposit_supertile(zp, tile)})
    }
}

impl<'d, D:Drawable> Drawable for SetScroll<'d, D> {
    fn affordance(&mut self) -> Affordance { self.1.borrow(|d| d.affordance()) }
    fn get_font(&self) -> Font { self.1.borrow(|d| d.get_font()) }

    fn bounds(&self) -> ZelRect { self.1.borrow(|d| d.bounds()) }

    fn raw_touch(&mut self, zp: Zel, format: bool, modify: impl FnOnce(&mut ZelData)) {
        self.1.borrow(|d| { d.raw_touch(zp, format, |z| { 
            if format { z.scroll = self.0 }
            modify(z); 
        }); } )
    }

    fn deposit_supertile(&mut self, zp: Zel, tile: SuperTile) {
        self.1.borrow(|d| { d.deposit_supertile(zp, tile)})
    }
}