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

pub struct Padding<V> {
    pub(crate) view: V,
    pub(crate) offsets: Offsets,
}

impl<V: View> View for Padding<V> {
    #[inline]
    fn size(&self) -> Size {
        let mut size = self.view.size();
        size.width += self.offsets.horizontal();
        size.height += self.offsets.vertical();

        size
    }

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

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