openprxl 0.1.0

A Rust spreadsheet library inspired by Python's openpyxl
Documentation
//! Fill styling.

/// A cell fill.
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub enum Fill {
    #[default]
    None,
    Pattern(PatternFill),
}

/// A pattern fill.
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct PatternFill {
    pub pattern_type: PatternType,
    pub fg_color: Option<String>,
    pub bg_color: Option<String>,
}

impl PatternFill {
    pub fn new(pattern_type: PatternType) -> Self {
        Self {
            pattern_type,
            fg_color: None,
            bg_color: None,
        }
    }

    /// Create a solid fill with the given RGB foreground color.
    pub fn solid<S: Into<String>>(rgb: S) -> Self {
        Self {
            pattern_type: PatternType::Solid,
            fg_color: Some(rgb.into()),
            bg_color: None,
        }
    }

    pub fn fg_color<S: Into<String>>(mut self, rgb: S) -> Self {
        self.fg_color = Some(rgb.into());
        self
    }

    pub fn bg_color<S: Into<String>>(mut self, rgb: S) -> Self {
        self.bg_color = Some(rgb.into());
        self
    }
}

/// Pattern types for fills.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum PatternType {
    #[default]
    None,
    Solid,
    DarkGray,
    MediumGray,
    LightGray,
    Gray125,
    Gray0625,
}

impl std::fmt::Display for PatternType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            PatternType::None => write!(f, "none"),
            PatternType::Solid => write!(f, "solid"),
            PatternType::DarkGray => write!(f, "darkGray"),
            PatternType::MediumGray => write!(f, "mediumGray"),
            PatternType::LightGray => write!(f, "lightGray"),
            PatternType::Gray125 => write!(f, "gray125"),
            PatternType::Gray0625 => write!(f, "gray0625"),
        }
    }
}