umya_spreadsheet/structs/
break.rs

1// brk
2use crate::reader::driver::*;
3use crate::structs::BooleanValue;
4use crate::structs::UInt32Value;
5use crate::writer::driver::*;
6use quick_xml::events::BytesStart;
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10
11#[derive(Clone, Default, Debug)]
12pub struct Break {
13    id: UInt32Value,
14    max: UInt32Value,
15    min: UInt32Value,
16    manual_page_break: BooleanValue,
17}
18
19impl Break {
20    #[inline]
21    pub fn get_id(&self) -> &u32 {
22        self.id.get_value()
23    }
24
25    #[inline]
26    pub fn set_id(&mut self, value: u32) -> &mut Self {
27        self.id.set_value(value);
28        self
29    }
30
31    #[inline]
32    pub fn get_max(&self) -> &u32 {
33        self.max.get_value()
34    }
35
36    #[inline]
37    pub fn set_max(&mut self, value: u32) -> &mut Self {
38        self.max.set_value(value);
39        self
40    }
41
42    #[inline]
43    pub fn get_manual_page_break(&self) -> &bool {
44        self.manual_page_break.get_value()
45    }
46
47    #[inline]
48    pub fn set_manual_page_break(&mut self, value: bool) -> &mut Self {
49        self.manual_page_break.set_value(value);
50        self
51    }
52
53    #[inline]
54    pub(crate) fn set_attributes<R: std::io::BufRead>(
55        &mut self,
56        _reader: &mut Reader<R>,
57        e: &BytesStart,
58    ) {
59        set_string_from_xml!(self, e, id, "id");
60        set_string_from_xml!(self, e, max, "max");
61        set_string_from_xml!(self, e, min, "min");
62        set_string_from_xml!(self, e, manual_page_break, "man");
63    }
64
65    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
66        // brk
67        let mut attributes: Vec<(&str, &str)> = Vec::new();
68        let id = self.id.get_value_string();
69        attributes.push(("id", &id));
70
71        let max = self.max.get_value_string();
72        if self.max.has_value() {
73            attributes.push(("max", &max));
74        }
75
76        let min = self.min.get_value_string();
77        if self.min.has_value() {
78            attributes.push(("min", &min));
79        }
80
81        let manual_page_break = self.manual_page_break.get_value_string();
82        if self.manual_page_break.has_value() {
83            attributes.push(("man", manual_page_break));
84        }
85        write_start_tag(writer, "brk", attributes, true);
86    }
87}