summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas/drawable.rs
blob: 5209fa6f4c449cb3e34917efe02ae423011fe959 (plain) (blame)
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
use crate::canvas::Frame;

/// A type that can be drawn on a [`Frame`].
///
/// [`Frame`]: struct.Frame.html
pub trait Drawable {
    /// Draws the [`Drawable`] on the given [`Frame`].
    ///
    /// [`Drawable`]: trait.Drawable.html
    /// [`Frame`]: struct.Frame.html
    fn draw(&self, frame: &mut Frame);
}

impl<'a> Drawable for dyn Fn(&mut Frame) + 'a {
    fn draw(&self, frame: &mut Frame) {
        self(frame)
    }
}

impl<T> Drawable for &T
where
    T: Drawable,
{
    fn draw(&self, frame: &mut Frame) {
        T::draw(self, frame)
    }
}

impl<T> Drawable for &[T]
where
    T: Drawable,
{
    fn draw(&self, frame: &mut Frame) {
        self.iter().for_each(|drawable| drawable.draw(frame));
    }
}