Skip to main content

euv_core/style/paint_prop/
impl.rs

1use super::*;
2
3/// Identity default for `Transform2D`.
4impl Default for Transform2D {
5    /// Creates an identity 2D transform (`scale = 1.0`, `translate = 0.0`, `rotation = 0.0`).
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - Identity `Transform2D`.
10    fn default() -> Self {
11        Self::new(0.0, 0.0, 1.0, 1.0, 0.0)
12    }
13}
14
15/// Default paint properties (`opacity = 1.0`, transparent background).
16impl Default for PaintStyle {
17    /// Creates default transparent paint properties.
18    ///
19    /// # Returns
20    ///
21    /// - `Self` - Default `PaintStyle`.
22    fn default() -> Self {
23        Self {
24            background: None,
25            gradient: None,
26            border: Border::default(),
27            radius: CornerRadius::default(),
28            shadow: None,
29            focus_ring: None,
30            opacity: 1.0,
31            transform: Transform2D::default(),
32            cursor: CursorIcon::Default,
33            pointer_events: PointerEvents::Auto,
34            stop_scroll_propagation: false,
35            stop_event_propagation: false,
36        }
37    }
38}
39
40/// Inspection helpers for `Transform2D`.
41impl Transform2D {
42    /// Returns true when the transform is the exact identity transform.
43    ///
44    /// # Arguments
45    ///
46    /// - `&Self` - Transform to inspect.
47    ///
48    /// # Returns
49    ///
50    /// - `bool` - True when translation and rotation are zero and scale is one.
51    #[must_use]
52    pub fn is_identity(&self) -> bool {
53        self.get_translate_x() == 0.0
54            && self.get_translate_y() == 0.0
55            && self.get_scale_x() == 1.0
56            && self.get_scale_y() == 1.0
57            && self.get_rotation_rad() == 0.0
58    }
59}
60
61/// Non-panicking optional field readers for `PaintStyle`.
62impl PaintStyle {
63    /// Returns the optional background color.
64    ///
65    /// # Arguments
66    ///
67    /// - `&Self` - Paint style.
68    ///
69    /// # Returns
70    ///
71    /// - `Option<Color>` - Background color if set.
72    #[must_use]
73    pub fn background_color(&self) -> Option<Color> {
74        let Self { background, .. } = *self;
75        background
76    }
77
78    /// Returns the optional linear gradient fill.
79    ///
80    /// # Arguments
81    ///
82    /// - `&Self` - Paint style.
83    ///
84    /// # Returns
85    ///
86    /// - `Option<LinearGradient>` - Linear gradient if set.
87    #[must_use]
88    pub fn background_gradient(&self) -> Option<LinearGradient> {
89        let Self { gradient, .. } = *self;
90        gradient
91    }
92
93    /// Returns the optional drop shadow.
94    ///
95    /// # Arguments
96    ///
97    /// - `&Self` - Paint style.
98    ///
99    /// # Returns
100    ///
101    /// - `Option<Shadow>` - Drop shadow if set.
102    #[must_use]
103    pub fn box_shadow(&self) -> Option<Shadow> {
104        let Self { shadow, .. } = *self;
105        shadow
106    }
107
108    /// Returns the optional focus ring stroke.
109    ///
110    /// # Arguments
111    ///
112    /// - `&Self` - Paint style.
113    ///
114    /// # Returns
115    ///
116    /// - `Option<Border>` - Focus ring stroke if set.
117    #[must_use]
118    pub fn focus_ring_border(&self) -> Option<Border> {
119        let Self { focus_ring, .. } = *self;
120        focus_ring
121    }
122}