spreadsheet_ods/style/
stylemap.rs

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