figma_schema/
paint.rs

1use super::{BlendMode, Color, Vector};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Deserialize, Serialize)]
5#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
6#[typeshare::typeshare]
7pub enum PaintType {
8    Solid,
9    GradientLinear,
10    GradientRadial,
11    GradientAngular,
12    GradientDiamond,
13    Image,
14}
15
16/// A solid color, gradient, or image texture that can be applied as fills or strokes
17///
18/// [Figma documentation](https://www.figma.com/developers/api#paint-type)
19#[derive(Debug, Deserialize, Serialize)]
20#[typeshare::typeshare]
21pub struct Paint {
22    pub r#type: PaintType,
23    /// Is the paint enabled?
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub visible: Option<bool>,
26    /// Overall opacity of paint (colors within the paint can also have opacity values which would blend with this)
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub opacity: Option<f64>,
29    /// Solid color of the paint
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub color: Option<Color>,
32    /// How this node blends with nodes behind it in the scene
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub blend_mode: Option<BlendMode>,
35    /// This field contains three vectors, each of which are a position in normalized object space (normalized object space is if the top left corner of the bounding box of the object is (0, 0) and the bottom right is (1,1)). The first position corresponds to the start of the gradient (value 0 for the purposes of calculating gradient stops), the second position is the end of the gradient (value 1), and the third handle position determines the width of the gradient. See image examples below:
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub gradient_handle_positions: Option<[Vector; 3]>,
38}
39
40impl Paint {
41    pub fn visible(&self) -> bool {
42        self.visible.unwrap_or(true)
43    }
44
45    pub fn opacity(&self) -> f64 {
46        self.opacity.unwrap_or(1.0)
47    }
48
49    pub fn color(&self) -> Option<&Color> {
50        self.color.as_ref()
51    }
52}