Skip to main content

umya_spreadsheet/structs/
column_reference.rs

1use crate::{
2    helper::coordinate::{
3        adjustment_insert_coordinate,
4        adjustment_remove_coordinate,
5        is_remove_coordinate,
6        string_from_column_index,
7    },
8    traits::AdjustmentValue,
9};
10
11#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
12pub struct ColumnReference {
13    num:     u32,
14    is_lock: bool,
15}
16
17impl Default for ColumnReference {
18    #[inline]
19    fn default() -> Self {
20        Self {
21            num:     1,
22            is_lock: false,
23        }
24    }
25}
26
27impl ColumnReference {
28    #[inline]
29    #[must_use]
30    pub fn num(&self) -> u32 {
31        self.num
32    }
33
34    #[inline]
35    #[must_use]
36    #[deprecated(since = "3.0.0", note = "Use num()")]
37    pub fn get_num(&self) -> u32 {
38        self.num()
39    }
40
41    #[inline]
42    pub fn set_num(&mut self, value: u32) -> &mut Self {
43        self.num = value;
44        self
45    }
46
47    #[inline]
48    pub(crate) fn offset_num(&mut self, value: i32) -> &mut Self {
49        if value > 0 {
50            self.plus_num(value.try_into().unwrap());
51        }
52        if value < 0 {
53            self.minus_num((-value).try_into().unwrap());
54        }
55        self
56    }
57
58    #[inline]
59    pub(crate) fn plus_num(&mut self, value: u32) -> &mut Self {
60        self.num += value;
61        self
62    }
63
64    #[inline]
65    pub(crate) fn minus_num(&mut self, value: u32) -> &mut Self {
66        self.num -= value;
67        self
68    }
69
70    #[inline]
71    #[must_use]
72    pub fn is_lock(&self) -> bool {
73        self.is_lock
74    }
75
76    #[inline]
77    #[must_use]
78    #[deprecated(since = "3.0.0", note = "Use is_lock()")]
79    pub fn get_is_lock(&self) -> bool {
80        self.is_lock()
81    }
82
83    #[inline]
84    pub fn set_is_lock(&mut self, value: bool) -> &mut Self {
85        self.is_lock = value;
86        self
87    }
88
89    #[inline]
90    pub fn set_is_lock_usize(&mut self, value: u32) -> &mut Self {
91        self.is_lock = value == 1;
92        self
93    }
94
95    #[inline]
96    pub(crate) fn coordinate(&self) -> String {
97        format!(
98            "{}{}",
99            if self.is_lock { "$" } else { "" },
100            string_from_column_index(self.num),
101        )
102    }
103
104    #[inline]
105    #[deprecated(since = "3.0.0", note = "Use coordinate()")]
106    pub(crate) fn get_coordinate(&self) -> String {
107        self.coordinate()
108    }
109}
110impl AdjustmentValue for ColumnReference {
111    #[inline]
112    fn adjustment_insert_value(&mut self, root_num: u32, offset_num: u32) {
113        self.num = adjustment_insert_coordinate(self.num, root_num, offset_num);
114    }
115
116    #[inline]
117    fn adjustment_remove_value(&mut self, root_num: u32, offset_num: u32) {
118        self.num = adjustment_remove_coordinate(self.num, root_num, offset_num);
119    }
120
121    #[inline]
122    fn is_remove_value(&self, root_num: u32, offset_num: u32) -> bool {
123        is_remove_coordinate(self.num, root_num, offset_num)
124    }
125}