use super::{AlignContent, AlignItems, AlignSelf, CoreStyle, Dimension, JustifyContent, LengthPercentage, Style};
use crate::geometry::Size;
pub trait FlexboxContainerStyle: CoreStyle {
#[inline(always)]
fn flex_direction(&self) -> FlexDirection {
Style::<Self::CustomIdent>::DEFAULT.flex_direction
}
#[inline(always)]
fn flex_wrap(&self) -> FlexWrap {
Style::<Self::CustomIdent>::DEFAULT.flex_wrap
}
#[inline(always)]
fn gap(&self) -> Size<LengthPercentage> {
Style::<Self::CustomIdent>::DEFAULT.gap
}
#[inline(always)]
fn align_content(&self) -> Option<AlignContent> {
Style::<Self::CustomIdent>::DEFAULT.align_content
}
#[inline(always)]
fn align_items(&self) -> Option<AlignItems> {
Style::<Self::CustomIdent>::DEFAULT.align_items
}
#[inline(always)]
fn justify_content(&self) -> Option<JustifyContent> {
Style::<Self::CustomIdent>::DEFAULT.justify_content
}
}
pub trait FlexboxItemStyle: CoreStyle {
#[inline(always)]
fn flex_basis(&self) -> Dimension {
Style::<Self::CustomIdent>::DEFAULT.flex_basis
}
#[inline(always)]
fn flex_grow(&self) -> f32 {
Style::<Self::CustomIdent>::DEFAULT.flex_grow
}
#[inline(always)]
fn flex_shrink(&self) -> f32 {
Style::<Self::CustomIdent>::DEFAULT.flex_shrink
}
#[inline(always)]
fn align_self(&self) -> Option<AlignSelf> {
Style::<Self::CustomIdent>::DEFAULT.align_self
}
}
use crate::geometry::AbsoluteAxis;
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum FlexWrap {
#[default]
NoWrap,
Wrap,
WrapReverse,
}
#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(FlexWrap,
"nowrap" => NoWrap,
"wrap" => Wrap,
"wrap-reverse" => WrapReverse,
);
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum FlexDirection {
#[default]
Row,
Column,
RowReverse,
ColumnReverse,
}
#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(FlexDirection,
"row" => Row,
"column" => Column,
"row-reverse" => RowReverse,
"column-reverse" => ColumnReverse,
);
impl FlexDirection {
#[inline]
pub(crate) const fn is_row(self) -> bool {
matches!(self, Self::Row | Self::RowReverse)
}
#[inline]
pub(crate) const fn is_column(self) -> bool {
matches!(self, Self::Column | Self::ColumnReverse)
}
#[inline]
pub(crate) const fn is_reverse(self) -> bool {
matches!(self, Self::RowReverse | Self::ColumnReverse)
}
#[inline]
pub(crate) const fn main_axis(self) -> AbsoluteAxis {
match self {
Self::Row | Self::RowReverse => AbsoluteAxis::Horizontal,
Self::Column | Self::ColumnReverse => AbsoluteAxis::Vertical,
}
}
#[inline]
pub(crate) const fn cross_axis(self) -> AbsoluteAxis {
match self {
Self::Row | Self::RowReverse => AbsoluteAxis::Vertical,
Self::Column | Self::ColumnReverse => AbsoluteAxis::Horizontal,
}
}
}
#[cfg(test)]
mod tests {
mod test_flex_direction {
use crate::style::*;
#[test]
fn flex_direction_is_row() {
assert!(FlexDirection::Row.is_row());
assert!(FlexDirection::RowReverse.is_row());
assert!(!FlexDirection::Column.is_row());
assert!(!FlexDirection::ColumnReverse.is_row());
}
#[test]
fn flex_direction_is_column() {
assert!(!FlexDirection::Row.is_column());
assert!(!FlexDirection::RowReverse.is_column());
assert!(FlexDirection::Column.is_column());
assert!(FlexDirection::ColumnReverse.is_column());
}
#[test]
fn flex_direction_is_reverse() {
assert!(!FlexDirection::Row.is_reverse());
assert!(FlexDirection::RowReverse.is_reverse());
assert!(!FlexDirection::Column.is_reverse());
assert!(FlexDirection::ColumnReverse.is_reverse());
}
}
}