Skip to main content

peacock_crest/style/prop_validation/
max_size.rs

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