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
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Clone, Debug, Default)]
pub enum Content {
/// Default layout, children are stacked along the direction axis.
#[default]
Normal,
/// Resize children to evenly fit the available space along the direction axis.
Fit,
/// Let children use [`Size::Flex`](crate::size::Size::Flex) to grow proportionally to fill the available space.
Flex,
/// Wrap children to the next line or column when they exceed the available space,
/// with an optional gap between wrapped lines.
Wrap { wrap_spacing: Option<f32> },
}
impl Content {
/// Use a [`Normal`](Content::Normal) content.
pub fn normal() -> Content {
Content::Normal
}
/// Use a [`Fit`](Content::Fit) content.
pub fn fit() -> Content {
Content::Fit
}
/// Use a [`Flex`](Content::Flex) content.
pub fn flex() -> Content {
Content::Flex
}
/// Use a [`Wrap`](Content::Wrap) content with no spacing.
pub fn wrap() -> Content {
Content::Wrap { wrap_spacing: None }
}
/// Use a [`Wrap`](Content::Wrap) content with the given spacing.
pub fn wrap_spacing(spacing: f32) -> Content {
Content::Wrap {
wrap_spacing: Some(spacing),
}
}
pub fn is_fit(&self) -> bool {
self == &Self::Fit
}
pub fn is_flex(&self) -> bool {
self == &Self::Flex
}
pub fn is_wrap(&self) -> bool {
matches!(self, Self::Wrap { .. })
}
pub fn allows_alignments(&self) -> bool {
matches!(self, Self::Normal | Self::Flex | Self::Fit)
}
}
impl Content {
pub fn pretty(&self) -> String {
match self {
Self::Normal => "normal".to_owned(),
Self::Fit => "fit".to_owned(),
Self::Flex => "flex".to_owned(),
Self::Wrap { .. } => "wrap".to_owned(),
}
}
}