Skip to main content

umya_spreadsheet/structs/drawing/
offset.rs

1// a:off
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::BytesStart,
8};
9
10use super::super::super::Int64Value;
11use crate::{
12    reader::driver::get_attribute,
13    writer::driver::write_start_tag,
14};
15
16#[derive(Clone, Default, Debug)]
17pub struct Offset {
18    x: Int64Value,
19    y: Int64Value,
20}
21impl Offset {
22    #[inline]
23    #[must_use]
24    pub fn x(&self) -> i64 {
25        self.x.value()
26    }
27
28    #[inline]
29    #[must_use]
30    #[deprecated(since = "3.0.0", note = "Use x()")]
31    pub fn get_x(&self) -> i64 {
32        self.x()
33    }
34
35    #[inline]
36    pub fn set_x(&mut self, value: i64) {
37        self.x.set_value(value);
38    }
39
40    #[inline]
41    #[must_use]
42    pub fn y(&self) -> i64 {
43        self.y.value()
44    }
45
46    #[inline]
47    #[must_use]
48    #[deprecated(since = "3.0.0", note = "Use y()")]
49    pub fn get_y(&self) -> i64 {
50        self.y()
51    }
52
53    #[inline]
54    pub fn set_y(&mut self, value: i64) {
55        self.y.set_value(value);
56    }
57
58    #[inline]
59    pub(crate) fn set_attributes<R: std::io::BufRead>(
60        &mut self,
61        _reader: &mut Reader<R>,
62        e: &BytesStart,
63    ) {
64        self.x.set_value_string(get_attribute(e, b"x").unwrap());
65        self.y.set_value_string(get_attribute(e, b"y").unwrap());
66    }
67
68    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
69        // a:off
70        write_start_tag(
71            writer,
72            "a:off",
73            vec![
74                ("x", self.x.value_string()).into(),
75                ("y", self.y.value_string()).into(),
76            ],
77            true,
78        );
79    }
80}