elvis_core/style/
flex.rs

1//! Flex Style
2use crate::{
3    style::Style,
4    value::{
5        layouts::{Alignment, FlexBasis, FlexDirection, FlexWrap},
6        Unit,
7    },
8};
9use elvis_core_support::Setter;
10
11/// `Flex` Style
12#[derive(Clone, Default, Setter)]
13pub struct FlexStyle {
14    /// Flex align
15    pub align: Option<Alignment>,
16    /// Flex basis
17    pub basis: Option<FlexBasis>,
18    /// Flex direction
19    pub direction: Option<FlexDirection>,
20    /// Flex grow
21    #[skip]
22    pub grow: Option<Unit>,
23    /// Flex order
24    #[skip]
25    pub order: Option<Unit>,
26    /// Flex wrap
27    pub wrap: Option<FlexWrap>,
28}
29
30impl FlexStyle {
31    /// Set FlexGrow
32    pub fn grow(mut self, grow: i64) -> FlexStyle {
33        self.grow = Some(Unit::None(grow as f64));
34        self
35    }
36
37    /// Set FlexOrder
38    pub fn order(mut self, order: i64) -> FlexStyle {
39        self.order = Some(Unit::None(order as f64));
40        self
41    }
42}
43
44impl Into<Vec<Style>> for FlexStyle {
45    fn into(self) -> Vec<Style> {
46        let mut styles: Vec<Style> = vec![];
47
48        // let align_style: Vec<Style> = self.align.into();
49        // vec![
50        //     align_style[0].clone(),
51        //     align_style[1].clone(),
52        //     self.basis.into(),
53        //     self.direction.into(),
54        //     Style::FlexGrow(self.grow),
55        //     Style::Order(self.order),
56        //     Style::FlexWrap(self.wrap),
57        // ]
58        if let Some(v) = self.align {
59            styles.append(&mut v.into());
60        }
61
62        styles
63    }
64}