tessera_ui_basic_components/
shape_def.rs

1//! Defines the basic shape types used by components.
2
3/// Defines the shape of a UI component for rendering and hit-testing.
4///
5/// This enum is used by components to specify their geometric outline,
6/// which affects both their visual appearance and interaction area.
7///
8/// # Variants
9///
10/// - [`Shape::RoundedRectangle`]: A rectangle with configurable corner radius and curvature.
11/// - [`Shape::Ellipse`]: An ellipse that fills the component's bounds.
12///
13/// # Example
14/// ```
15/// use tessera_ui_basic_components::shape_def::Shape;
16///
17/// // Create a rounded rectangle shape with a 6.0 radius
18/// let shape = Shape::RoundedRectangle { corner_radius: 6.0, g2_k_value: 3.0 };
19///
20/// // Use an ellipse shape
21/// let ellipse = Shape::Ellipse;
22/// ```
23#[derive(Clone, Copy, Debug, PartialEq)]
24pub enum Shape {
25    /// A rectangle with configurable rounded corners.
26    ///
27    /// - `corner_radius`: The radius of the corners in logical pixels (Dp).
28    /// - `g2_k_value`: Controls the curvature of the corner (higher values produce squarer corners).
29    ///
30    /// # Example
31    /// ```
32    /// use tessera_ui_basic_components::shape_def::Shape;
33    /// let shape = Shape::RoundedRectangle { corner_radius: 8.0, g2_k_value: 3.0 };
34    /// ```
35    RoundedRectangle { corner_radius: f32, g2_k_value: f32 },
36
37    /// An ellipse that fills the component's bounding rectangle.
38    ///
39    /// # Example
40    /// ```
41    /// use tessera_ui_basic_components::shape_def::Shape;
42    /// let shape = Shape::Ellipse;
43    /// ```
44    Ellipse,
45}
46
47impl Default for Shape {
48    /// Returns the default shape, which is a rectangle with zero corner radius.
49    ///
50    /// # Example
51    /// ```
52    /// use tessera_ui_basic_components::shape_def::Shape;
53    /// let default_shape = Shape::default();
54    /// assert_eq!(default_shape, Shape::RoundedRectangle { corner_radius: 0.0, g2_k_value: 3.0 });
55    /// ```
56    fn default() -> Self {
57        Shape::RoundedRectangle {
58            corner_radius: 0.0,
59            g2_k_value: 3.0,
60        }
61    }
62}