umya_spreadsheet/structs/
workbook_view.rs1use super::Int32Value;
2use super::UInt32Value;
3use crate::reader::driver::*;
4use crate::writer::driver::*;
5use quick_xml::events::BytesStart;
6use quick_xml::Reader;
7use quick_xml::Writer;
8use std::io::Cursor;
9
10#[derive(Clone, Debug)]
11pub struct WorkbookView {
12 active_tab: UInt32Value,
13 x_window: Int32Value,
14 y_window: Int32Value,
15 window_width: Int32Value,
16 window_height: Int32Value,
17 tab_ratio: Int32Value,
18}
19impl Default for WorkbookView {
20 #[inline]
21 fn default() -> Self {
22 let mut x_window = Int32Value::default();
23 x_window.set_value(240);
24 let mut y_window = Int32Value::default();
25 y_window.set_value(105);
26 let mut window_width = Int32Value::default();
27 window_width.set_value(14805);
28 let mut window_height = Int32Value::default();
29 window_height.set_value(8010);
30 Self {
31 active_tab: UInt32Value::default(),
32 x_window,
33 y_window,
34 window_width,
35 window_height,
36 tab_ratio: Int32Value::default(),
37 }
38 }
39}
40impl WorkbookView {
41 #[inline]
42 pub fn get_active_tab(&self) -> &u32 {
43 self.active_tab.get_value()
44 }
45
46 #[inline]
47 pub fn set_active_tab(&mut self, value: u32) -> &mut Self {
48 self.active_tab.set_value(value);
49 self
50 }
51
52 #[inline]
53 pub fn get_x_window(&self) -> &i32 {
54 self.x_window.get_value()
55 }
56
57 #[inline]
58 pub fn set_x_window(&mut self, value: i32) -> &mut Self {
59 self.x_window.set_value(value);
60 self
61 }
62
63 #[inline]
64 pub fn get_y_window(&self) -> &i32 {
65 self.y_window.get_value()
66 }
67
68 #[inline]
69 pub fn set_y_window(&mut self, value: i32) -> &mut Self {
70 self.y_window.set_value(value);
71 self
72 }
73
74 #[inline]
75 pub fn get_window_width(&self) -> &i32 {
76 self.window_width.get_value()
77 }
78
79 #[inline]
80 pub fn set_window_width(&mut self, value: i32) -> &mut Self {
81 self.window_width.set_value(value);
82 self
83 }
84
85 #[inline]
86 pub fn get_window_height(&self) -> &i32 {
87 self.window_height.get_value()
88 }
89
90 #[inline]
91 pub fn set_window_height(&mut self, value: i32) -> &mut Self {
92 self.window_height.set_value(value);
93 self
94 }
95
96 #[inline]
97 pub fn get_tab_ratio(&self) -> &i32 {
98 self.tab_ratio.get_value()
99 }
100
101 #[inline]
102 pub fn set_tab_ratio(&mut self, value: i32) -> &mut Self {
103 self.tab_ratio.set_value(value);
104 self
105 }
106
107 #[inline]
108 pub(crate) fn set_attributes<R: std::io::BufRead>(
109 &mut self,
110 _reader: &mut Reader<R>,
111 e: &BytesStart,
112 ) {
113 set_string_from_xml!(self, e, active_tab, "activeTab");
114 set_string_from_xml!(self, e, x_window, "xWindow");
115 set_string_from_xml!(self, e, y_window, "yWindow");
116 set_string_from_xml!(self, e, window_width, "windowWidth");
117 set_string_from_xml!(self, e, window_height, "windowHeight");
118 set_string_from_xml!(self, e, tab_ratio, "tabRatio");
119 }
120
121 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
122 let mut attributes: Vec<(&str, &str)> = Vec::new();
124 let active_tab = self.active_tab.get_value_string();
125 if self.active_tab.has_value() {
126 attributes.push(("activeTab", active_tab.as_str()));
127 }
128
129 let x_window = self.x_window.get_value_string();
130 if self.x_window.has_value() {
131 attributes.push(("xWindow", x_window.as_str()));
132 }
133
134 let y_window = self.y_window.get_value_string();
135 if self.y_window.has_value() {
136 attributes.push(("yWindow", y_window.as_str()));
137 }
138
139 let window_width = self.window_width.get_value_string();
140 if self.window_width.has_value() {
141 attributes.push(("windowWidth", window_width.as_str()));
142 }
143
144 let window_height = self.window_height.get_value_string();
145 if self.window_height.has_value() {
146 attributes.push(("windowHeight", window_height.as_str()));
147 }
148
149 let tab_ratio = self.tab_ratio.get_value_string();
150 if self.tab_ratio.has_value() {
151 attributes.push(("tabRatio", tab_ratio.as_str()));
152 }
153
154 write_start_tag(writer, "workbookView", attributes, true);
156 }
157}