ribir_painter/
style.rs

1use ribir_algo::Resource;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5  color::{LinearGradient, RadialGradient},
6  Color, PixelImage,
7};
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub enum Brush {
11  Color(Color),
12  /// Image brush always use a repeat mode to brush the path.
13  Image(Resource<PixelImage>),
14  RadialGradient(RadialGradient),
15  LinearGradient(LinearGradient),
16}
17
18impl Brush {
19  pub fn only_convert_color(&self, f: impl FnOnce(&Color) -> Color) -> Brush {
20    match self {
21      Brush::Color(color) => f(color).into(),
22      _ => panic!("Need Color!"),
23    }
24  }
25}
26
27impl From<Color> for Brush {
28  #[inline]
29  fn from(c: Color) -> Self { Brush::Color(c) }
30}
31
32impl From<Color> for Option<Brush> {
33  #[inline]
34  fn from(c: Color) -> Self { Some(c.into()) }
35}
36
37impl From<Resource<PixelImage>> for Brush {
38  #[inline]
39  fn from(img: Resource<PixelImage>) -> Self { Brush::Image(img) }
40}
41
42impl From<PixelImage> for Brush {
43  #[inline]
44  fn from(img: PixelImage) -> Self { Resource::new(img).into() }
45}
46
47impl Default for Brush {
48  #[inline]
49  fn default() -> Self { Color::BLACK.into() }
50}