use crate::scaled::Scaled;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Clone, Debug, Default)]
pub enum Content {
#[default]
Normal,
Fit,
Flex,
Wrap { wrap_spacing: Option<f32> },
}
impl Content {
pub const fn normal() -> Content {
Content::Normal
}
pub const fn fit() -> Content {
Content::Fit
}
pub const fn flex() -> Content {
Content::Flex
}
pub const fn wrap() -> Content {
Content::Wrap { wrap_spacing: None }
}
pub const fn wrap_spacing(spacing: f32) -> Content {
Content::Wrap {
wrap_spacing: Some(spacing),
}
}
pub const fn is_fit(&self) -> bool {
matches!(self, Self::Fit)
}
pub const fn is_flex(&self) -> bool {
matches!(self, Self::Flex)
}
pub const fn is_wrap(&self) -> bool {
matches!(self, Self::Wrap { .. })
}
pub const 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(),
}
}
}
impl Scaled for Content {
fn scale(&mut self, scale_factor: f32) {
if let Self::Wrap {
wrap_spacing: Some(wrap_spacing),
} = self
{
*wrap_spacing *= scale_factor;
}
}
}