Skip to main content

azul_css/props/
formatter.rs

1//! Trait and implementations for formatting CSS properties back into strings.
2
3use alloc::{
4    string::{String, ToString},
5    vec::Vec,
6};
7use core::fmt;
8
9// Re-export the PrintAsCssValue trait from the css module
10pub use crate::css::PrintAsCssValue;
11use crate::props::{
12    basic::{
13        angle::AngleValue,
14        color::ColorU,
15        direction::{Direction, DirectionCorner},
16        font::*,
17        length::{FloatValue, PercentageValue},
18        pixel::PixelValue,
19    },
20    layout::{dimensions::*, display::*, flex::*, overflow::*, position::*, spacing::*},
21    style::{
22        background::*,
23        border::*,
24        border_radius::*,
25        box_shadow::{BoxShadowClipMode, StyleBoxShadow},
26        effects::*,
27        filter::*,
28        scrollbar::*,
29        text::*,
30        transform::*,
31    },
32};
33
34pub trait FormatAsCssValue {
35    fn format_as_css_value(&self, f: &mut fmt::Formatter) -> fmt::Result;
36}
37
38// --- Style Properties ---
39
40impl PrintAsCssValue for StyleBorderTopLeftRadius {
41    fn print_as_css_value(&self) -> String {
42        format!("{}", self.inner)
43    }
44}
45impl PrintAsCssValue for StyleBorderTopRightRadius {
46    fn print_as_css_value(&self) -> String {
47        format!("{}", self.inner)
48    }
49}
50impl PrintAsCssValue for StyleBorderBottomLeftRadius {
51    fn print_as_css_value(&self) -> String {
52        format!("{}", self.inner)
53    }
54}
55impl PrintAsCssValue for StyleBorderBottomRightRadius {
56    fn print_as_css_value(&self) -> String {
57        format!("{}", self.inner)
58    }
59}
60
61impl PrintAsCssValue for StyleBorderTopStyle {
62    fn print_as_css_value(&self) -> String {
63        format!("{}", self.inner)
64    }
65}
66impl PrintAsCssValue for StyleBorderRightStyle {
67    fn print_as_css_value(&self) -> String {
68        format!("{}", self.inner)
69    }
70}
71impl PrintAsCssValue for StyleBorderBottomStyle {
72    fn print_as_css_value(&self) -> String {
73        format!("{}", self.inner)
74    }
75}
76impl PrintAsCssValue for StyleBorderLeftStyle {
77    fn print_as_css_value(&self) -> String {
78        format!("{}", self.inner)
79    }
80}
81
82impl PrintAsCssValue for StyleBorderTopColor {
83    fn print_as_css_value(&self) -> String {
84        self.inner.to_hash()
85    }
86}
87impl PrintAsCssValue for StyleBorderRightColor {
88    fn print_as_css_value(&self) -> String {
89        self.inner.to_hash()
90    }
91}
92impl PrintAsCssValue for StyleBorderBottomColor {
93    fn print_as_css_value(&self) -> String {
94        self.inner.to_hash()
95    }
96}
97impl PrintAsCssValue for StyleBorderLeftColor {
98    fn print_as_css_value(&self) -> String {
99        self.inner.to_hash()
100    }
101}
102
103impl PrintAsCssValue for LayoutBorderTopWidth {
104    fn print_as_css_value(&self) -> String {
105        format!("{}", self.inner)
106    }
107}
108impl PrintAsCssValue for LayoutBorderRightWidth {
109    fn print_as_css_value(&self) -> String {
110        format!("{}", self.inner)
111    }
112}
113impl PrintAsCssValue for LayoutBorderBottomWidth {
114    fn print_as_css_value(&self) -> String {
115        format!("{}", self.inner)
116    }
117}
118impl PrintAsCssValue for LayoutBorderLeftWidth {
119    fn print_as_css_value(&self) -> String {
120        format!("{}", self.inner)
121    }
122}
123
124// --- Layout Spacing Properties ---
125
126impl PrintAsCssValue for LayoutPaddingTop {
127    fn print_as_css_value(&self) -> String {
128        format!("{}", self.inner)
129    }
130}
131impl PrintAsCssValue for LayoutPaddingLeft {
132    fn print_as_css_value(&self) -> String {
133        format!("{}", self.inner)
134    }
135}
136impl PrintAsCssValue for LayoutPaddingRight {
137    fn print_as_css_value(&self) -> String {
138        format!("{}", self.inner)
139    }
140}
141impl PrintAsCssValue for LayoutPaddingBottom {
142    fn print_as_css_value(&self) -> String {
143        format!("{}", self.inner)
144    }
145}
146
147impl PrintAsCssValue for LayoutPaddingInlineStart {
148    fn print_as_css_value(&self) -> String {
149        format!("{}", self.inner)
150    }
151}
152
153impl PrintAsCssValue for LayoutPaddingInlineEnd {
154    fn print_as_css_value(&self) -> String {
155        format!("{}", self.inner)
156    }
157}
158
159impl PrintAsCssValue for LayoutMarginTop {
160    fn print_as_css_value(&self) -> String {
161        format!("{}", self.inner)
162    }
163}
164impl PrintAsCssValue for LayoutMarginLeft {
165    fn print_as_css_value(&self) -> String {
166        format!("{}", self.inner)
167    }
168}
169impl PrintAsCssValue for LayoutMarginRight {
170    fn print_as_css_value(&self) -> String {
171        format!("{}", self.inner)
172    }
173}
174impl PrintAsCssValue for LayoutMarginBottom {
175    fn print_as_css_value(&self) -> String {
176        format!("{}", self.inner)
177    }
178}
179
180impl PrintAsCssValue for LayoutColumnGap {
181    fn print_as_css_value(&self) -> String {
182        format!("{}", self.inner)
183    }
184}
185
186impl PrintAsCssValue for LayoutRowGap {
187    fn print_as_css_value(&self) -> String {
188        format!("{}", self.inner)
189    }
190}