spreadsheet_ods/style/
colstyle.rs

1use get_size::GetSize;
2use get_size_derive::GetSize;
3
4use crate::attrmap2::AttrMap2;
5use crate::style::units::{Length, PageBreak};
6use crate::style::AnyStyleRef;
7use crate::style::ParseStyleAttr;
8use crate::style::{rel_width_string, StyleOrigin, StyleUse};
9use crate::OdsError;
10use std::borrow::Borrow;
11
12style_ref2!(ColStyleRef);
13
14/// Describes the style information for a table column.
15/// Hardly ever used. It's easier to set the col_width via
16/// Sheet::set_col_width
17///
18#[derive(Debug, Clone, GetSize)]
19pub struct ColStyle {
20    /// From where did we get this style.
21    origin: StyleOrigin,
22    /// Which tag contains this style.
23    styleuse: StyleUse,
24    /// Style name
25    name: String,
26
27    /// General attributes
28    attr: AttrMap2,
29    /// Column style properties
30    colstyle: AttrMap2,
31}
32
33styles_styles2!(ColStyle, ColStyleRef);
34
35impl ColStyle {
36    /// empty
37    pub fn new_empty() -> Self {
38        Self {
39            origin: Default::default(),
40            styleuse: Default::default(),
41            name: Default::default(),
42            attr: Default::default(),
43            colstyle: Default::default(),
44        }
45    }
46
47    /// New Style.
48    pub fn new<S: AsRef<str>>(name: S) -> Self {
49        Self {
50            origin: Default::default(),
51            styleuse: Default::default(),
52            name: name.as_ref().to_string(),
53            attr: Default::default(),
54            colstyle: Default::default(),
55        }
56    }
57
58    /// Attributes
59    pub fn attrmap(&self) -> &AttrMap2 {
60        &self.attr
61    }
62
63    /// Attributes
64    pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
65        &mut self.attr
66    }
67
68    /// Style attributes
69    pub fn colstyle(&self) -> &AttrMap2 {
70        &self.colstyle
71    }
72
73    /// Style attributes
74    pub fn colstyle_mut(&mut self) -> &mut AttrMap2 {
75        &mut self.colstyle
76    }
77
78    fo_break!(colstyle);
79    style_column_width!(colstyle);
80    style_rel_column_width!(colstyle);
81    style_use_optimal_column_width!(colstyle);
82}