1#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2#[derive(PartialEq, Clone, Debug, Default)]
3pub enum Content {
4 #[default]
6 Normal,
7 Fit,
9 Flex,
11 Wrap { wrap_spacing: Option<f32> },
14}
15
16impl Content {
17 pub fn normal() -> Content {
19 Content::Normal
20 }
21
22 pub fn fit() -> Content {
24 Content::Fit
25 }
26
27 pub fn flex() -> Content {
29 Content::Flex
30 }
31
32 pub fn wrap() -> Content {
34 Content::Wrap { wrap_spacing: None }
35 }
36
37 pub fn wrap_spacing(spacing: f32) -> Content {
39 Content::Wrap {
40 wrap_spacing: Some(spacing),
41 }
42 }
43
44 pub fn is_fit(&self) -> bool {
45 self == &Self::Fit
46 }
47
48 pub fn is_flex(&self) -> bool {
49 self == &Self::Flex
50 }
51
52 pub fn is_wrap(&self) -> bool {
53 matches!(self, Self::Wrap { .. })
54 }
55
56 pub fn allows_alignments(&self) -> bool {
57 matches!(self, Self::Normal | Self::Flex | Self::Fit)
58 }
59}
60
61impl Content {
62 pub fn pretty(&self) -> String {
63 match self {
64 Self::Normal => "normal".to_owned(),
65 Self::Fit => "fit".to_owned(),
66 Self::Flex => "flex".to_owned(),
67 Self::Wrap { .. } => "wrap".to_owned(),
68 }
69 }
70}