1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::fmt;
use std::fmt::Display;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum CssUnit {
/// Automatic.
Auto,
/// No unit.
None,
/// Percentage.
Perc,
/// centimeters, 1cm = 37.8px = 25.2/64in.
Cm,
/// Millimeters, 1mm = 1/10th of 1cm
Mm,
/// Quarter-millimeters, 1Q = 1/40th of 1cm
Q,
/// Inches, 1in = 2.54cm = 96px
In,
/// Picas, 1pc = 1/6th of 1in
Pc,
/// Points, 1pt = 1/72nd of 1in
Pt,
/// Pixels, 1px = 1/96th of 1in
Px,
/// Font size of the parent, in the case of typographical properties like font-size, and font size of the element itself, in the case of other properties like width.
Em,
/// x-height of the element's font.
Ex,
/// The advance measure (width) of the glyph "0" of the element's font.
Ch,
/// Font size of the root element.
Rem,
/// Line height of the element.
Lh,
/// Line height of the root element.
Rlh,
/// 1% of the viewport's width.
Vw,
/// 1% of the viewport's height.
Vh,
/// 1% of the viewport's smaller dimension.
Vmin,
/// 1% of the viewport's larger dimension.
Vmax,
/// 1% of the size of the initial containing block in the direction of the root element's block axis.
Vb,
/// 1% of the size of the initial containing block in the direction of the root element's inline axis.
Vi,
/// 1% of the small viewport's width.
Svw,
/// 1% of the small viewport's height.
Svh,
/// 1% of the large viewport's width.
Lvw,
/// 1% of the large viewport's height.
Lvh,
/// 1% of the dynamic viewport's width.
Dvw,
/// 1% of the dynamic viewport's height.
Dvh,
}
impl Display for CssUnit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
CssUnit::Auto => "auto",
CssUnit::None => "",
CssUnit::Perc => "%",
CssUnit::Cm => "cm",
CssUnit::Mm => "mm",
CssUnit::Q => "Q",
CssUnit::In => "in",
CssUnit::Pc => "pc",
CssUnit::Pt => "pt",
CssUnit::Px => "px",
CssUnit::Em => "em",
CssUnit::Ex => "ex",
CssUnit::Ch => "ch",
CssUnit::Rem => "rem",
CssUnit::Lh => "lh",
CssUnit::Rlh => "rlh",
CssUnit::Vw => "vw",
CssUnit::Vh => "vh",
CssUnit::Vmin => "vmin",
CssUnit::Vmax => "vmax",
CssUnit::Vb => "vb",
CssUnit::Vi => "vi",
CssUnit::Svw => "svw",
CssUnit::Svh => "svh",
CssUnit::Lvw => "lvw",
CssUnit::Lvh => "lvh",
CssUnit::Dvw => "dvw",
CssUnit::Dvh => "dvh",
}
)
}
}