figma_schema/
effect.rs

1use serde::{Deserialize, Serialize};
2
3use super::{Color, Vector};
4
5#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
6#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
7#[typeshare::typeshare]
8pub enum EffectType {
9    InnerShadow,
10    DropShadow,
11    LayerBlur,
12    BackgroundBlur,
13}
14
15/// A visual effect such as a shadow or blur
16///
17/// [Figma documentation](https://www.figma.com/developers/api#effect-type)
18#[derive(Debug, Deserialize, Serialize)]
19#[serde(rename_all = "camelCase")]
20#[typeshare::typeshare]
21pub struct Effect {
22    /// Type of effect
23    pub r#type: EffectType,
24    /// Is the effect active?
25    pub visible: bool,
26    /// The color of the shadow
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub color: Option<Color>,
29    /// How far the shadow is projected in the x and y directions
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub offset: Option<Vector>,
32    /// How far the shadow spreads
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub spread: Option<f64>,
35}
36
37impl Effect {
38    pub fn spread(&self) -> f64 {
39        self.spread.unwrap_or(0.0)
40    }
41}