use std::collections::HashMap;
#[derive(Debug, Default, Clone)]
pub struct StyleManifest {
pub styles: Vec<StyleSpec>,
pub cells: HashMap<String, HashMap<(u32, u32), usize>>,
pub merges: HashMap<String, Vec<String>>,
pub columns: HashMap<String, Vec<ColumnWidth>>,
}
#[derive(Debug, Clone, Copy)]
pub struct ColumnWidth {
pub col: u32,
pub width: f64,
}
#[derive(Debug, Default, Clone)]
pub struct StyleSpec {
pub font: Option<FontSpec>,
pub num_fmt: Option<String>,
pub alignment: Option<AlignmentSpec>,
pub fill: Option<FillSpec>,
}
#[derive(Debug, Default, Clone)]
pub struct FontSpec {
pub name: Option<String>,
pub size: Option<f64>,
pub bold: bool,
pub italic: bool,
pub underline: bool,
pub color: Option<String>,
}
#[derive(Debug, Default, Clone, Copy)]
pub struct AlignmentSpec {
pub horizontal: Option<HorizontalAlign>,
pub vertical: Option<VerticalAlign>,
pub wrap_text: bool,
pub indent: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HorizontalAlign {
Left,
Center,
Right,
Justify,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VerticalAlign {
Top,
Middle,
Bottom,
}
#[derive(Debug, Clone)]
pub struct FillSpec {
pub pattern: FillPattern,
pub color: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FillPattern {
Solid,
}
impl StyleManifest {
pub fn cell_style(&self, sheet: &str, row: u32, col: u32) -> Option<&StyleSpec> {
let idx = *self.cells.get(sheet)?.get(&(row, col))?;
self.styles.get(idx)
}
pub fn sheet_merges(&self, sheet: &str) -> &[String] {
self.merges
.get(sheet)
.map(|v| v.as_slice())
.unwrap_or(&[])
}
pub fn sheet_columns(&self, sheet: &str) -> &[ColumnWidth] {
self.columns
.get(sheet)
.map(|v| v.as_slice())
.unwrap_or(&[])
}
}