1
//! Trait and implementations for formatting CSS properties back into strings.
2
//!
3
//! This module defines `FormatAsCssValue` (zero-alloc, `fmt::Formatter`-based)
4
//! and re-exports `PrintAsCssValue` (from `css.rs`, returns `String`).
5
//! `PrintAsCssValue` impls for border, padding, margin, and gap types live here.
6

            
7
use alloc::string::String;
8
use core::fmt;
9

            
10
// Re-export the PrintAsCssValue trait from the css module
11
pub use crate::css::PrintAsCssValue;
12
use crate::props::{
13
    layout::{dimensions::*, spacing::*},
14
    style::{
15
        border::*,
16
        border_radius::*,
17
    },
18
};
19

            
20
/// Zero-allocation CSS value formatting trait using `fmt::Formatter`.
21
///
22
/// Unlike `PrintAsCssValue` (which returns a `String`), this trait writes
23
/// directly into a formatter and is suitable for `Display` impl delegation.
24
pub trait FormatAsCssValue {
25
    fn format_as_css_value(&self, f: &mut fmt::Formatter) -> fmt::Result;
26
}
27

            
28
macro_rules! impl_print_as_css_display {
29
    ($($t:ty),+ $(,)?) => {
30
        $(impl PrintAsCssValue for $t {
31
            fn print_as_css_value(&self) -> String {
32
                format!("{}", self.inner)
33
            }
34
        })+
35
    };
36
}
37

            
38
macro_rules! impl_print_as_css_hash {
39
    ($($t:ty),+ $(,)?) => {
40
        $(impl PrintAsCssValue for $t {
41
            fn print_as_css_value(&self) -> String {
42
                self.inner.to_hash()
43
            }
44
        })+
45
    };
46
}
47

            
48
// --- Style Properties ---
49

            
50
impl_print_as_css_display!(
51
    StyleBorderTopLeftRadius,
52
    StyleBorderTopRightRadius,
53
    StyleBorderBottomLeftRadius,
54
    StyleBorderBottomRightRadius,
55
    StyleBorderTopStyle,
56
    StyleBorderRightStyle,
57
    StyleBorderBottomStyle,
58
    StyleBorderLeftStyle,
59
    LayoutBorderTopWidth,
60
    LayoutBorderRightWidth,
61
    LayoutBorderBottomWidth,
62
    LayoutBorderLeftWidth,
63
);
64

            
65
impl_print_as_css_hash!(
66
    StyleBorderTopColor,
67
    StyleBorderRightColor,
68
    StyleBorderBottomColor,
69
    StyleBorderLeftColor,
70
);
71

            
72
// --- Layout Spacing Properties ---
73

            
74
impl_print_as_css_display!(
75
    LayoutPaddingTop,
76
    LayoutPaddingLeft,
77
    LayoutPaddingRight,
78
    LayoutPaddingBottom,
79
    LayoutPaddingInlineStart,
80
    LayoutPaddingInlineEnd,
81
    LayoutMarginTop,
82
    LayoutMarginLeft,
83
    LayoutMarginRight,
84
    LayoutMarginBottom,
85
    LayoutColumnGap,
86
    LayoutRowGap,
87
);