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
use crate::views::{Bounds, Event, Output, Point, Size, View};

///
pub struct Fixed<V> {
    pub(crate) view: V,
    pub(crate) size: Size,
}

impl<V: View> View for Fixed<V> {
    #[inline(always)]
    fn size(&self) -> Size {
        self.size
    }

    #[inline]
    fn event(&self, event: Event, offset: Point, mut bounds: Bounds) {
        bounds.set_size(self.size);
        self.view.event(event, offset, bounds)
    }

    #[inline]
    fn draw(&self, mut bounds: Bounds, onto: &mut impl Output) {
        bounds.set_size(self.size);
        self.view.draw(bounds, onto)
    }
}

///
pub struct FixedWidth<V: View> {
    pub(crate) view: V,
    pub(crate) width: f32,
}

impl<V: View> View for FixedWidth<V> {
    #[inline]
    fn size(&self) -> Size {
        let mut size = self.view.size();
        size.width = self.width;

        size
    }

    #[inline]
    fn event(&self, event: Event, offset: Point, mut bounds: Bounds) {
        let mut size = bounds.size();
        size.width = self.width;
        bounds.set_size(size);

        self.view.event(event, offset, bounds)
    }

    #[inline]
    fn draw(&self, mut bounds: Bounds, onto: &mut impl Output) {
        let mut size = bounds.size();
        size.width = self.width;
        bounds.set_size(size);

        self.view.draw(bounds, onto)
    }
}

///
pub struct FixedHeight<V: View> {
    pub(crate) view: V,
    pub(crate) height: f32,
}

impl<V: View> View for FixedHeight<V> {
    #[inline]
    fn size(&self) -> Size {
        let mut size = self.view.size();
        size.height = self.height;

        size
    }

    #[inline]
    fn event(&self, event: Event, offset: Point, mut bounds: Bounds) {
        let mut size = bounds.size();
        size.height = self.height;
        bounds.set_size(size);

        self.view.event(event, offset, bounds)
    }

    #[inline]
    fn draw(&self, mut bounds: Bounds, onto: &mut impl Output) {
        let mut size = bounds.size();
        size.height = self.height;
        bounds.set_size(size);

        self.view.draw(bounds, onto)
    }
}