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
macro_rules! create_impl {
    ($field:ident, $ty:ty) => {
        #[macro_export]
        macro_rules! $field {
            ($shape:ident) => {
                impl<'s> $shape<'s> {
                    pub fn $field(mut self, $field: $ty) -> Self {
                        self.$field = $field;
                        self
                    }
                }
            };
        }
    };
}

#[macro_export]
macro_rules! transform {
    ($shape:ident) => {
        impl<'s> $shape<'s> {
            pub fn transform(mut self, transform: Transform) -> Self {
                self.transform = transform;
                self
            }

            pub fn parent(mut self, parent: Transform) -> Self {
                self.parent = parent;
                self
            }

            pub fn position(mut self, position: Vec2<f32>) -> Self {
                self.transform.position = position;
                self
            }

            pub fn size(mut self, size: Vec2<f32>) -> Self {
                self.transform.size = size;
                self
            }
            
            pub fn scale(mut self, scale: f32) -> Self {
                self.transform.size = self.transform.size.normalize() * scale;
                self
            }

            pub fn rotation(mut self, rotation: f32) -> Self {
                self.transform.rotation = rotation;
                self
            }
        }
    }
}


create_impl!(position, Vec2<f32>);
create_impl!(size, Vec2<f32>);
create_impl!(rotation, f32);
create_impl!(scaling, bool);
create_impl!(color, [f32; 4]);
create_impl!(anchor, Anchor);
create_impl!(pivot, Anchor);
create_impl!(smooth, bool);
create_impl!(width, f32);
create_impl!(scale, f32);
create_impl!(depth, f32);