spreadsheet_ods/style/
stylemap.rs

1//!
2//! Conditional styles.
3//!
4
5use crate::condition::Condition;
6use crate::style::AnyStyleRef;
7use crate::CellRef;
8use get_size::GetSize;
9use get_size_derive::GetSize;
10
11/// A style-map is one way for conditional formatting of cells.
12///
13/// It seems this is always translated into calcext:conditional-formats
14/// which seem to be the preferred way to deal with this. But it still
15/// works somewhat.
16#[derive(Clone, Debug, GetSize)]
17pub struct StyleMap {
18    condition: Condition,
19    applied_style: AnyStyleRef,
20    base_cell: Option<CellRef>,
21}
22
23impl StyleMap {
24    ///
25    pub fn new_empty() -> Self {
26        Self {
27            condition: Default::default(),
28            applied_style: AnyStyleRef::from(""),
29            base_cell: None,
30        }
31    }
32
33    ///  Create a stylemap. When the condition is fullfilled the style
34    /// applied_style is used. The base_cell is used to resolve all relative
35    /// cell-references within the condition.
36    pub fn new(
37        condition: Condition,
38        applied_style: AnyStyleRef,
39        base_cell: Option<CellRef>,
40    ) -> Self {
41        Self {
42            condition,
43            applied_style,
44            base_cell,
45        }
46    }
47
48    /// Condition
49    pub fn condition(&self) -> &Condition {
50        &self.condition
51    }
52
53    /// Condition
54    pub fn set_condition(&mut self, cond: Condition) {
55        self.condition = cond;
56    }
57
58    /// The applied style.
59    pub fn applied_style(&self) -> &AnyStyleRef {
60        &self.applied_style
61    }
62
63    /// Sets the applied style.
64    pub fn set_applied_style(&mut self, style: AnyStyleRef) {
65        self.applied_style = style;
66    }
67
68    /// Base cell.
69    pub fn base_cell(&self) -> Option<&CellRef> {
70        self.base_cell.as_ref()
71    }
72
73    /// Sets the base cell.
74    pub fn set_base_cell(&mut self, cellref: Option<CellRef>) {
75        self.base_cell = cellref;
76    }
77}