Skip to main content

peacock_crest/style/prop_validation/
font.rs

1use super::{CssValue, TokenExpected};
2use crate::Unit;
3
4#[derive(Debug, Clone)]
5pub struct CssFontFamily(Unit);
6
7#[derive(Debug, Clone, strum_macros::EnumString, strum_macros::Display)]
8pub enum KeywordFontFamily {
9    #[strum(to_string = "serif", serialize = "serif")]
10    Serif,
11    #[strum(to_string = "sans-serif", serialize = "sans-serif")]
12    SansSerif,
13    #[strum(to_string = "monospace", serialize = "monospace")]
14    Monospace,
15    #[strum(to_string = "cursive", serialize = "cursive")]
16    Cursive,
17    #[strum(to_string = "fantasy", serialize = "fantasy")]
18    Fantasy,
19    #[strum(to_string = "system-ui", serialize = "system-ui")]
20    SystemUI,
21    #[strum(to_string = "ui-serif", serialize = "ui-serif")]
22    UISerif,
23    #[strum(to_string = "ui-sans-serif", serialize = "ui-sans-serif")]
24    UISansSerif,
25    #[strum(to_string = "ui-monospace", serialize = "ui-monospace")]
26    UIMonospace,
27    #[strum(to_string = "ui-rounded", serialize = "ui-rounded")]
28    UIRounded,
29    #[strum(to_string = "math", serialize = "math")]
30    Math,
31    #[strum(to_string = "emoji", serialize = "emoji")]
32    Emoji,
33    #[strum(to_string = "fangsong", serialize = "fangsong")]
34    Fangsong,
35}
36
37#[derive(Debug, Clone)]
38pub struct CssFontSize(Unit);
39
40#[derive(Debug, Clone, strum_macros::EnumString, strum_macros::Display)]
41pub enum KeywordFontSize {
42    #[strum(to_string = "xx-small", serialize = "xx-small")]
43    XXSmall,
44    #[strum(to_string = "x-small", serialize = "x-small")]
45    XSmall,
46    #[strum(to_string = "small", serialize = "small")]
47    Small,
48    #[strum(to_string = "medium", serialize = "medium")]
49    Medium,
50    #[strum(to_string = "large", serialize = "large")]
51    Large,
52    #[strum(to_string = "x-large", serialize = "x-large")]
53    XLarge,
54    #[strum(to_string = "xx-large", serialize = "xx-large")]
55    XXLarge,
56    #[strum(to_string = "xxx-large", serialize = "xxx-large")]
57    XXXLarge,
58}
59
60impl From<Unit> for CssFontFamily {
61    fn from(value: Unit) -> Self {
62        Self(value)
63    }
64}
65
66impl From<Unit> for CssFontSize {
67    fn from(value: Unit) -> Self {
68        Self(value)
69    }
70}
71
72impl Into<Unit> for CssFontFamily {
73    fn into(self) -> Unit {
74        self.0
75    }
76}
77
78impl Into<Unit> for CssFontSize {
79    fn into(self) -> Unit {
80        self.0
81    }
82}
83
84impl CssValue for CssFontFamily {
85    type Keyword = KeywordFontFamily;
86
87    fn type_name() -> &'static str {
88        "CssFontFamily"
89    }
90    fn type_token() -> TokenExpected {
91        TokenExpected::QuotedString | TokenExpected::Ident
92    }
93}
94
95impl CssValue for CssFontSize {
96    type Keyword = KeywordFontSize;
97
98    fn type_name() -> &'static str {
99        "CssFontSize"
100    }
101    fn type_token() -> TokenExpected {
102        TokenExpected::Dimension | TokenExpected::Ident | TokenExpected::Percentage
103    }
104}