umya_spreadsheet/structs/
alignment.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::BytesStart,
8};
9
10use super::{
11 BooleanValue,
12 EnumValue,
13 HorizontalAlignmentValues,
14 UInt32Value,
15 VerticalAlignmentValues,
16};
17use crate::{
18 reader::driver::{
19 get_attribute,
20 set_string_from_xml,
21 },
22 writer::driver::write_start_tag,
23};
24
25#[derive(Default, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
26pub struct Alignment {
27 horizontal: EnumValue<HorizontalAlignmentValues>,
28 vertical: EnumValue<VerticalAlignmentValues>,
29 wrap_text: BooleanValue,
30 text_rotation: UInt32Value,
31 indent: UInt32Value,
32}
33
34impl Alignment {
35 #[inline]
36 #[must_use]
37 pub fn horizontal(&self) -> &HorizontalAlignmentValues {
38 self.horizontal.value()
39 }
40
41 #[inline]
42 #[must_use]
43 #[deprecated(since = "3.0.0", note = "Use horizontal()")]
44 pub fn get_horizontal(&self) -> &HorizontalAlignmentValues {
45 self.horizontal()
46 }
47
48 #[inline]
49 pub fn set_horizontal(&mut self, value: HorizontalAlignmentValues) {
50 self.horizontal.set_value(value);
51 }
52
53 #[inline]
54 #[must_use]
55 pub fn vertical(&self) -> &VerticalAlignmentValues {
56 self.vertical.value()
57 }
58
59 #[inline]
60 #[must_use]
61 #[deprecated(since = "3.0.0", note = "Use vertical()")]
62 pub fn get_vertical(&self) -> &VerticalAlignmentValues {
63 self.vertical()
64 }
65
66 #[inline]
67 pub fn set_vertical(&mut self, value: VerticalAlignmentValues) {
68 self.vertical.set_value(value);
69 }
70
71 #[inline]
72 #[must_use]
73 pub fn wrap_text(&self) -> bool {
74 self.wrap_text.value()
75 }
76
77 #[inline]
78 #[must_use]
79 #[deprecated(since = "3.0.0", note = "Use wrap_text()")]
80 pub fn get_wrap_text(&self) -> bool {
81 self.wrap_text()
82 }
83
84 #[inline]
85 pub fn set_wrap_text(&mut self, value: bool) {
86 self.wrap_text.set_value(value);
87 }
88
89 #[inline]
90 #[must_use]
91 pub fn text_rotation(&self) -> u32 {
92 self.text_rotation.value()
93 }
94
95 #[inline]
96 #[must_use]
97 #[deprecated(since = "3.0.0", note = "Use text_rotation()")]
98 pub fn get_text_rotation(&self) -> u32 {
99 self.text_rotation()
100 }
101
102 #[inline]
103 pub fn set_text_rotation(&mut self, value: u32) {
104 self.text_rotation.set_value(value);
105 }
106
107 #[inline]
108 #[must_use]
109 pub fn indent(&self) -> u32 {
110 self.indent.value()
111 }
112
113 #[inline]
114 #[must_use]
115 #[deprecated(since = "3.0.0", note = "Use indent()")]
116 pub fn get_indent(&self) -> u32 {
117 self.indent()
118 }
119
120 #[inline]
121 pub fn set_indent(&mut self, value: u32) {
122 self.indent.set_value(value);
123 }
124
125 pub(crate) fn hash_code(&self) -> String {
126 crate::helper::utils::md5_hash(format!(
127 "{}{}{}{}{}",
128 self.horizontal.hash_string(),
129 self.vertical.hash_string(),
130 self.wrap_text.hash_string(),
131 self.text_rotation.hash_string(),
132 self.indent.hash_string(),
133 ))
134 }
135
136 #[deprecated(since = "3.0.0", note = "Use hash_code()")]
137 pub(crate) fn get_hash_code(&self) -> String {
138 self.hash_code()
139 }
140
141 #[inline]
142 pub(crate) fn set_attributes<R: std::io::BufRead>(
143 &mut self,
144 _reader: &mut Reader<R>,
145 e: &BytesStart,
146 ) {
147 set_string_from_xml!(self, e, horizontal, "horizontal");
148 set_string_from_xml!(self, e, vertical, "vertical");
149 set_string_from_xml!(self, e, wrap_text, "wrapText");
150 set_string_from_xml!(self, e, text_rotation, "textRotation");
151 set_string_from_xml!(self, e, indent, "indent");
152 }
153
154 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
155 let mut attributes: crate::structs::AttrCollection = Vec::new();
157 if self.horizontal.has_value() {
158 attributes.push(("horizontal", self.horizontal.value_string()).into());
159 }
160 if self.vertical.has_value() {
161 attributes.push(("vertical", self.vertical.value_string()).into());
162 }
163 if self.wrap_text.has_value() {
164 attributes.push(("wrapText", self.wrap_text.value_string()).into());
165 }
166 let text_rotation = self.text_rotation.value_string();
167 if self.text_rotation.has_value() {
168 attributes.push(("textRotation", text_rotation).into());
169 }
170 let indent = self.indent.value_string();
171 if self.indent.has_value() {
172 attributes.push(("indent", indent).into());
173 }
174 write_start_tag(writer, "alignment", attributes, true);
175 }
176}