1#[derive(Clone, Debug)]
5pub enum Length {
6 Px(f32),
8 Rem(f32),
10 Em(f32),
12 Vw(f32),
14 Vh(f32),
16 Percent(f32),
18 Auto,
20 Zero,
22}
23
24impl Length {
25 pub fn px(value: f32) -> Self {
27 Self::Px(value)
28 }
29
30 pub fn rem(value: f32) -> Self {
32 Self::Rem(value)
33 }
34
35 pub fn em(value: f32) -> Self {
37 Self::Em(value)
38 }
39
40 pub fn vw(value: f32) -> Self {
42 Self::Vw(value)
43 }
44
45 pub fn vh(value: f32) -> Self {
47 Self::Vh(value)
48 }
49
50 pub fn percent(value: f32) -> Self {
52 Self::Percent(value)
53 }
54
55 pub fn to_css(&self) -> String {
57 match self {
58 Length::Px(v) => format!("{}px", v),
59 Length::Rem(v) => format!("{}rem", v),
60 Length::Em(v) => format!("{}em", v),
61 Length::Vw(v) => format!("{}vw", v),
62 Length::Vh(v) => format!("{}vh", v),
63 Length::Percent(v) => format!("{}%", v),
64 Length::Auto => "auto".to_string(),
65 Length::Zero => "0".to_string(),
66 }
67 }
68}
69
70#[derive(Clone, Debug)]
72pub struct Percentage(pub f32);
73
74impl Percentage {
75 pub fn new(value: f32) -> Self {
77 Self(value)
78 }
79
80 pub fn to_css(&self) -> String {
82 format!("{}%", self.0)
83 }
84}
85
86#[derive(Clone, Debug)]
88pub enum Time {
89 Seconds(f32),
91 Milliseconds(f32),
93}
94
95impl Time {
96 pub fn seconds(value: f32) -> Self {
98 Self::Seconds(value)
99 }
100
101 pub fn milliseconds(value: f32) -> Self {
103 Self::Milliseconds(value)
104 }
105
106 pub fn to_css(&self) -> String {
108 match self {
109 Time::Seconds(v) => format!("{}s", v),
110 Time::Milliseconds(v) => format!("{}ms", v),
111 }
112 }
113}
114
115#[derive(Clone, Debug)]
117pub enum Angle {
118 Deg(f32),
120 Rad(f32),
122}
123
124impl Angle {
125 pub fn deg(value: f32) -> Self {
127 Self::Deg(value)
128 }
129
130 pub fn rad(value: f32) -> Self {
132 Self::Rad(value)
133 }
134
135 pub fn to_css(&self) -> String {
137 match self {
138 Angle::Deg(v) => format!("{}deg", v),
139 Angle::Rad(v) => format!("{}rad", v),
140 }
141 }
142}