css-style 0.9.0

Typed CSS Style
Documentation
use crate::{unit::*, Style, StyleUpdater};

/// ```
/// use css_style::{Style, unit::{px, em}};
///
/// Style::default()
///     .gap(px(2))
///     // this can take percent value too (.e.g 40%).
///     .gap(0.4)
///     // and can take row and column each with different value
///     .gap((em(4.), em(8.)));
/// ```
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Gap {
    Value(LengthPercent),
    #[display(fmt = "{} {}", _0, _1)]
    RowColumn(LengthPercent, LengthPercent),
}

impl<T> From<T> for Gap
where
    T: Into<LengthPercent>,
{
    fn from(source: T) -> Self {
        Gap::Value(source.into())
    }
}

impl<T1, T2> From<(T1, T2)> for Gap
where
    T1: Into<LengthPercent>,
    T2: Into<LengthPercent>,
{
    fn from((row, col): (T1, T2)) -> Self {
        let row = row.into();
        let col = col.into();
        Gap::RowColumn(row, col)
    }
}

impl StyleUpdater for Gap {
    fn update_style(self, style: Style) -> Style {
        style.insert("gap", self)
    }
}