drawme/style/
fill.rs

1use std::borrow::Cow;
2
3use crate::prelude::*;
4
5pub struct Fill<'a>(Cow<'a, Paint>);
6
7impl<'a> Fill<'a> {
8    pub fn new(paint: impl Into<Cow<'a, Paint>>) -> Self {
9        Self(paint.into())
10    }
11
12    pub fn paint_mut(&mut self) -> &mut Paint {
13        self.0.to_mut()
14    }
15
16    pub fn paint(&self) -> &Paint {
17        &self.0
18    }
19
20    pub fn into_cow(self) -> Cow<'a, Paint> {
21        self.0
22    }
23    pub fn into_paint(self) -> Paint {
24        self.0.into_owned()
25    }
26}
27
28impl<C: Canvas + ?Sized> Draw<C> for Fill<'_> {
29    fn draw(&self, canvas: &mut C) {
30        canvas.set_fill(self.paint());
31    }
32}