umya_spreadsheet/structs/
pane.rs1use super::Coordinate;
2use super::DoubleValue;
3use super::EnumValue;
4use super::PaneStateValues;
5use super::PaneValues;
6use crate::reader::driver::*;
7use crate::writer::driver::*;
8use quick_xml::events::BytesStart;
9use quick_xml::Reader;
10use quick_xml::Writer;
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct Pane {
15 horizontal_split: DoubleValue,
16 vertical_split: DoubleValue,
17 top_left_cell: Coordinate,
18 active_pane: EnumValue<PaneValues>,
19 state: EnumValue<PaneStateValues>,
20}
21
22impl Pane {
23 #[inline]
24 pub fn get_horizontal_split(&self) -> &f64 {
25 self.horizontal_split.get_value()
26 }
27
28 #[inline]
29 pub fn set_horizontal_split(&mut self, value: f64) -> &mut Self {
30 self.horizontal_split.set_value(value);
31 self
32 }
33
34 #[inline]
35 pub fn get_vertical_split(&self) -> &f64 {
36 self.vertical_split.get_value()
37 }
38
39 #[inline]
40 pub fn set_vertical_split(&mut self, value: f64) -> &mut Self {
41 self.vertical_split.set_value(value);
42 self
43 }
44
45 #[inline]
46 pub fn get_top_left_cell(&self) -> &Coordinate {
47 &self.top_left_cell
48 }
49
50 #[inline]
51 pub fn get_top_left_cell_mut(&mut self) -> &mut Coordinate {
52 &mut self.top_left_cell
53 }
54
55 #[inline]
56 pub fn set_top_left_cell(&mut self, value: Coordinate) -> &mut Self {
57 self.top_left_cell = value;
58 self
59 }
60
61 #[inline]
62 pub fn get_active_pane(&self) -> &PaneValues {
63 self.active_pane.get_value()
64 }
65
66 #[inline]
67 pub fn set_active_pane(&mut self, value: PaneValues) -> &mut Self {
68 self.active_pane.set_value(value);
69 self
70 }
71
72 #[inline]
73 pub fn get_state(&self) -> &PaneStateValues {
74 self.state.get_value()
75 }
76
77 #[inline]
78 pub fn set_state(&mut self, value: PaneStateValues) -> &mut Self {
79 self.state.set_value(value);
80 self
81 }
82
83 pub(crate) fn set_attributes<R: std::io::BufRead>(
84 &mut self,
85 _reader: &mut Reader<R>,
86 e: &BytesStart,
87 ) {
88 set_string_from_xml!(self, e, horizontal_split, "xSplit");
89 set_string_from_xml!(self, e, vertical_split, "ySplit");
90 set_string_from_xml!(self, e, active_pane, "activePane");
91 set_string_from_xml!(self, e, state, "state");
92
93 if let Some(v) = get_attribute(e, b"topLeftCell") {
94 self.top_left_cell.set_coordinate(v);
95 }
96 }
97
98 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
99 let mut attributes: Vec<(&str, &str)> = Vec::new();
101 let coordinate = self.top_left_cell.to_string();
102 let horizontal_split = self.horizontal_split.get_value_string();
103 if self.horizontal_split.has_value() {
104 attributes.push(("xSplit", &horizontal_split));
105 }
106 let vertical_split = self.vertical_split.get_value_string();
107 if self.vertical_split.has_value() {
108 attributes.push(("ySplit", &vertical_split));
109 }
110 attributes.push(("topLeftCell", &coordinate));
111 attributes.push(("activePane", self.active_pane.get_value_string()));
112 attributes.push(("state", self.state.get_value_string()));
113 write_start_tag(writer, "pane", attributes, true);
114 }
115}