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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Lynx-only `relative-*` properties for the `display: relative`
//! layout container.
//!
//! `relative-id` identifies children; the other properties refer to
//! sibling `relative-id`s to anchor a child to a sibling edge.
use crate::css::Css;
impl Css {
/// Sets `relative-id` — identifies the element for sibling-edge
/// references.
/// <https://lynxjs.org/api/css/properties/relative-id>
pub fn relative_id(self, v: i32) -> Self {
self.push_raw("relative-id", v.to_string())
}
/// Sets `relative-align-top` — id of the sibling to top-align with.
/// <https://lynxjs.org/api/css/properties/relative-align-top>
pub fn relative_align_top(self, v: i32) -> Self {
self.push_raw("relative-align-top", v.to_string())
}
/// Sets `relative-align-right` — id of the sibling to right-align with.
/// <https://lynxjs.org/api/css/properties/relative-align-right>
pub fn relative_align_right(self, v: i32) -> Self {
self.push_raw("relative-align-right", v.to_string())
}
/// Sets `relative-align-bottom`.
/// <https://lynxjs.org/api/css/properties/relative-align-bottom>
pub fn relative_align_bottom(self, v: i32) -> Self {
self.push_raw("relative-align-bottom", v.to_string())
}
/// Sets `relative-align-left`.
/// <https://lynxjs.org/api/css/properties/relative-align-left>
pub fn relative_align_left(self, v: i32) -> Self {
self.push_raw("relative-align-left", v.to_string())
}
/// Sets `relative-top-of` — id of the sibling this element sits below.
/// <https://lynxjs.org/api/css/properties/relative-top-of>
pub fn relative_top_of(self, v: i32) -> Self {
self.push_raw("relative-top-of", v.to_string())
}
/// Sets `relative-right-of` — id of the sibling this element sits to the right of.
/// <https://lynxjs.org/api/css/properties/relative-right-of>
pub fn relative_right_of(self, v: i32) -> Self {
self.push_raw("relative-right-of", v.to_string())
}
/// Sets `relative-bottom-of`.
/// <https://lynxjs.org/api/css/properties/relative-bottom-of>
pub fn relative_bottom_of(self, v: i32) -> Self {
self.push_raw("relative-bottom-of", v.to_string())
}
/// Sets `relative-left-of`.
/// <https://lynxjs.org/api/css/properties/relative-left-of>
pub fn relative_left_of(self, v: i32) -> Self {
self.push_raw("relative-left-of", v.to_string())
}
/// Sets `relative-center` — centers the element relative to a sibling.
/// <https://lynxjs.org/api/css/properties/relative-center>
pub fn relative_center(self, v: i32) -> Self {
self.push_raw("relative-center", v.to_string())
}
/// Sets `relative-center-horizontal` — centers horizontally only.
/// <https://lynxjs.org/api/css/properties/relative-center-horizontal>
pub fn relative_center_horizontal(self, v: i32) -> Self {
self.push_raw("relative-center-horizontal", v.to_string())
}
/// Sets `relative-center-vertical` — centers vertically only.
/// <https://lynxjs.org/api/css/properties/relative-center-vertical>
pub fn relative_center_vertical(self, v: i32) -> Self {
self.push_raw("relative-center-vertical", v.to_string())
}
/// Sets `relative-layout-once` — performs the relative-layout
/// pass only on the first render.
/// <https://lynxjs.org/api/css/properties/relative-layout-once>
pub fn relative_layout_once(self, v: bool) -> Self {
self.push_raw("relative-layout-once", if v { "true" } else { "false" })
}
/// Sets `relative-align-inline-start` (logical-direction alias).
pub fn relative_align_inline_start(self, v: i32) -> Self {
self.push_raw("relative-align-inline-start", v.to_string())
}
/// Sets `relative-align-inline-end` (logical-direction alias).
pub fn relative_align_inline_end(self, v: i32) -> Self {
self.push_raw("relative-align-inline-end", v.to_string())
}
/// Sets `relative-inline-start-of`.
pub fn relative_inline_start_of(self, v: i32) -> Self {
self.push_raw("relative-inline-start-of", v.to_string())
}
/// Sets `relative-inline-end-of`.
pub fn relative_inline_end_of(self, v: i32) -> Self {
self.push_raw("relative-inline-end-of", v.to_string())
}
}
#[cfg(test)]
mod tests {
use crate::Css;
#[test]
fn relative_id_and_anchors() {
let s = Css::new()
.relative_id(1)
.relative_align_top(2)
.relative_left_of(3)
.relative_center(4);
assert_eq!(
s.to_string(),
"relative-id: 1; relative-align-top: 2; relative-left-of: 3; relative-center: 4;"
);
}
#[test]
fn relative_all_align_edges() {
let s = Css::new()
.relative_align_top(1)
.relative_align_right(2)
.relative_align_bottom(3)
.relative_align_left(4);
assert_eq!(
s.to_string(),
"relative-align-top: 1; relative-align-right: 2; relative-align-bottom: 3; relative-align-left: 4;"
);
}
#[test]
fn relative_all_of_edges() {
let s = Css::new()
.relative_top_of(1)
.relative_right_of(2)
.relative_bottom_of(3)
.relative_left_of(4);
assert_eq!(
s.to_string(),
"relative-top-of: 1; relative-right-of: 2; relative-bottom-of: 3; relative-left-of: 4;"
);
}
#[test]
fn relative_center_variants() {
let s = Css::new()
.relative_center(1)
.relative_center_horizontal(2)
.relative_center_vertical(3);
assert_eq!(
s.to_string(),
"relative-center: 1; relative-center-horizontal: 2; relative-center-vertical: 3;"
);
}
#[test]
fn relative_layout_once_bool() {
assert_eq!(
Css::new().relative_layout_once(true).to_string(),
"relative-layout-once: true;"
);
assert_eq!(
Css::new().relative_layout_once(false).to_string(),
"relative-layout-once: false;"
);
}
#[test]
fn relative_inline_aliases() {
let s = Css::new()
.relative_align_inline_start(1)
.relative_align_inline_end(2)
.relative_inline_start_of(3)
.relative_inline_end_of(4);
assert_eq!(
s.to_string(),
"relative-align-inline-start: 1; relative-align-inline-end: 2; relative-inline-start-of: 3; relative-inline-end-of: 4;"
);
}
}