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
//! Utilidades de layout de Tailwind: posición, dirección inversa, `flex-*`, `self-*`, `content-*` y desbordamiento.
//! Se expande dentro de `Styled`; los tipos (`Align`, `Justify`…) se resuelven en `styled.rs`.
/// `z-10`, `-z-10`: orden de apilado entre hermanos.
macro_rules! z_indexes {
($($name:ident = $z:literal;)*) => {
setters! { $($name => |s| s.extra_mut().z = Some($z);)* }
};
}
macro_rules! layout_utilities {
() => {
z_indexes! {
z_0 = 0; z_10 = 10; z_20 = 20; z_30 = 30; z_40 = 40; z_50 = 50;
neg_z_10 = -10; neg_z_20 = -20; neg_z_30 = -30; neg_z_40 = -40; neg_z_50 = -50;
}
/// `z-[N]`: cualquier orden de apilado.
fn z(mut self, order: i16) -> Self {
self.style().extra_mut().z = Some(order);
self
}
setters! {
relative => |s| s.absolute = Some(false);
// No hay `position: fixed` aparte: dentro del árbol equivale a `absolute` respecto a su contenedor.
fixed => |s| s.absolute = Some(true);
flex_row_reverse => |s| {
s.direction = Some(Direction::Row);
s.extra_mut().reverse = Some(true);
};
flex_col_reverse => |s| {
s.direction = Some(Direction::Column);
s.extra_mut().reverse = Some(true);
};
flex_nowrap => |s| s.wrap = Some(false);
flex_auto => |s| {
s.flex_grow = Some(1.0);
s.flex_shrink = Some(1.0);
s.flex_basis = Some(Length::Auto);
};
flex_initial => |s| {
s.flex_grow = Some(0.0);
s.flex_shrink = Some(1.0);
s.flex_basis = Some(Length::Auto);
};
flex_none => |s| {
s.flex_grow = Some(0.0);
s.flex_shrink = Some(0.0);
s.flex_basis = Some(Length::Auto);
};
grow => |s| s.flex_grow = Some(1.0);
grow_0 => |s| s.flex_grow = Some(0.0);
shrink => |s| s.flex_shrink = Some(1.0);
shrink_0 => |s| s.flex_shrink = Some(0.0);
items_stretch => |s| s.align_items = Some(Align::Stretch);
items_baseline => |s| s.align_items = Some(Align::Baseline);
justify_around => |s| s.justify_content = Some(Justify::SpaceAround);
justify_evenly => |s| s.justify_content = Some(Justify::SpaceEvenly);
self_auto => |s| s.align_self = None;
self_start => |s| s.align_self = Some(Align::Start);
self_center => |s| s.align_self = Some(Align::Center);
self_end => |s| s.align_self = Some(Align::End);
self_stretch => |s| s.align_self = Some(Align::Stretch);
self_baseline => |s| s.align_self = Some(Align::Baseline);
content_start => |s| s.extra_mut().align_content = Some(Justify::Start);
content_center => |s| s.extra_mut().align_content = Some(Justify::Center);
content_end => |s| s.extra_mut().align_content = Some(Justify::End);
content_between => |s| s.extra_mut().align_content = Some(Justify::SpaceBetween);
content_around => |s| s.extra_mut().align_content = Some(Justify::SpaceAround);
content_evenly => |s| s.extra_mut().align_content = Some(Justify::SpaceEvenly);
overflow_visible => |s| {
s.overflow_x = Some(Overflow::Visible);
s.overflow_y = Some(Overflow::Visible);
};
overflow_x_hidden => |s| s.overflow_x = Some(Overflow::Hidden);
overflow_y_hidden => |s| s.overflow_y = Some(Overflow::Hidden);
overflow_x_scroll => |s| s.overflow_x = Some(Overflow::Scroll);
overflow_scroll => |s| {
s.overflow_x = Some(Overflow::Scroll);
s.overflow_y = Some(Overflow::Scroll);
};
// Como `overflow-auto`: la barra aparece solo si el contenido no cabe.
overflow_auto => |s| s.overflow_y = Some(Overflow::Scroll);
}
};
}
pub(crate) use {layout_utilities, z_indexes};