Skip to main content

peacock_crest/style/prop_validation/
size.rs

1use super::{CssValue, TokenExpected};
2use crate::Unit;
3
4#[derive(Debug, Clone)]
5pub struct CssWidth(Unit);
6
7#[derive(Debug, Clone)]
8pub struct CssHeight(Unit);
9
10#[derive(Debug, Clone, strum_macros::EnumString, strum_macros::Display)]
11pub enum KeywordSize {
12    #[strum(to_string = "max-content", serialize = "max-content")]
13    MaxContent,
14    #[strum(to_string = "min-content", serialize = "min-content")]
15    MinContent,
16    #[strum(to_string = "fit-content", serialize = "fit-content")]
17    FitContent,
18    #[strum(to_string = "auto", serialize = "auto")]
19    Auto,
20    #[strum(to_string = "stretch", serialize = "stretch")]
21    Stretch,
22}
23
24impl From<Unit> for CssWidth {
25    fn from(value: Unit) -> Self {
26        Self(value)
27    }
28}
29
30impl Into<Unit> for CssWidth {
31    fn into(self) -> Unit {
32        self.0
33    }
34}
35
36impl From<Unit> for CssHeight {
37    fn from(value: Unit) -> Self {
38        Self(value)
39    }
40}
41
42impl Into<Unit> for CssHeight {
43    fn into(self) -> Unit {
44        self.0
45    }
46}
47
48impl CssValue for CssWidth {
49    type Keyword = KeywordSize;
50
51    fn type_name() -> &'static str {
52        "CssWidth"
53    }
54    fn type_token() -> TokenExpected {
55        TokenExpected::Ident
56            | TokenExpected::Dimension
57            | TokenExpected::Percentage
58            | TokenExpected::Number
59    }
60}
61
62impl CssValue for CssHeight {
63    type Keyword = KeywordSize;
64
65    fn type_name() -> &'static str {
66        "CssHeight"
67    }
68    fn type_token() -> TokenExpected {
69        TokenExpected::Ident
70            | TokenExpected::Dimension
71            | TokenExpected::Percentage
72            | TokenExpected::Number
73    }
74}