Skip to main content

pepl_ui/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Dimension type for width, height, etc.
4///
5/// Number literal coercion: `width: 100` → `Px(100.0)`.
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(tag = "type", content = "value")]
8pub enum Dimension {
9    /// Fixed pixel value.
10    Px(f64),
11    /// Automatic sizing based on content.
12    Auto,
13    /// Fill available space.
14    Fill,
15    /// Percentage of parent (0.0–100.0).
16    Percent(f64),
17}
18
19impl Dimension {
20    /// Coerce a number to `Px`.
21    pub fn from_number(n: f64) -> Self {
22        Dimension::Px(n)
23    }
24}
25
26/// Edge insets (padding, margin, etc.).
27///
28/// Number literal coercion: `padding: 16` → `Uniform(16.0)`.
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum Edges {
32    /// All four sides equal.
33    Uniform(f64),
34    /// Individual sides.
35    Sides {
36        top: f64,
37        bottom: f64,
38        start: f64,
39        end: f64,
40    },
41}
42
43impl Edges {
44    /// Coerce a number to `Uniform`.
45    pub fn from_number(n: f64) -> Self {
46        Edges::Uniform(n)
47    }
48
49    /// Create explicit sides.
50    pub fn sides(top: f64, bottom: f64, start: f64, end: f64) -> Self {
51        Edges::Sides {
52            top,
53            bottom,
54            start,
55            end,
56        }
57    }
58}
59
60/// Alignment for layout components (Column, Row).
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
62#[serde(rename_all = "snake_case")]
63pub enum Alignment {
64    Start,
65    Center,
66    End,
67    Stretch,
68    SpaceBetween,
69    SpaceAround,
70}
71
72/// Border style definition.
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74pub struct BorderStyle {
75    /// Border width in pixels.
76    pub width: f64,
77    /// Border color as RGBA.
78    pub color: ColorValue,
79    /// Border line style (default: "solid").
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub style: Option<String>,
82}
83
84/// Shadow style definition.
85#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
86pub struct ShadowStyle {
87    /// Horizontal offset in pixels.
88    pub offset_x: f64,
89    /// Vertical offset in pixels.
90    pub offset_y: f64,
91    /// Blur radius in pixels.
92    pub blur: f64,
93    /// Shadow color as RGBA.
94    pub color: ColorValue,
95}
96
97/// RGBA color value (each component 0.0–1.0).
98#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
99pub struct ColorValue {
100    pub r: f64,
101    pub g: f64,
102    pub b: f64,
103    pub a: f64,
104}
105
106impl ColorValue {
107    /// Create a new color.
108    pub fn new(r: f64, g: f64, b: f64, a: f64) -> Self {
109        Self { r, g, b, a }
110    }
111
112    /// Opaque color (alpha = 1.0).
113    pub fn rgb(r: f64, g: f64, b: f64) -> Self {
114        Self { r, g, b, a: 1.0 }
115    }
116}