forked from servo/rust-css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.rs
62 lines (54 loc) · 1.12 KB
/
units.rs
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*!
Units used by CSS
*/
#[deriving(Eq)]
pub enum Length {
Em(float), // normalized to 'em'
Px(float), // normalized to 'px'
}
impl Length {
fn rel(self) -> float {
match self {
Em(x) => x,
_ => fail!(~"attempted to access relative unit of an absolute length")
}
}
fn abs(self) -> float {
match self {
Em(x) => x,
_ => fail!(~"attempted to access relative unit of an absolute length")
}
}
}
#[deriving(Eq)]
pub enum BoxSizing { // used by width, height, top, left, etc
BoxLength(Length),
BoxPercent(float),
BoxAuto
}
#[deriving(Eq)]
pub enum AbsoluteSize {
XXSmall,
XSmall,
Small,
Medium,
Large,
XLarge,
XXLarge
}
#[deriving(Eq)]
pub enum RelativeSize {
Larger,
Smaller
}
#[deriving(Eq)]
pub enum GenericFontFamily {
Serif,
SansSerif,
Cursive,
Fantasy,
Monospace,
}