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