docx_reader/documents/elements/
text_box.rs1use serde::Serialize;
2
3use crate::documents::*;
4use crate::types::*;
5
6#[derive(Debug, Clone, Serialize, PartialEq)]
7#[serde(rename_all = "camelCase")]
8pub struct TextBox {
9 pub children: Vec<TextBoxContentChild>,
11 pub size: (u32, u32),
13 pub position_type: DrawingPositionType,
14 pub simple_pos: bool,
19 pub simple_pos_x: i32,
21 pub simple_pos_y: i32,
22 pub layout_in_cell: bool,
26 pub relative_height: u32,
31 pub allow_overlap: bool,
32 pub position_h: DrawingPosition,
33 pub position_v: DrawingPosition,
34 pub relative_from_h: RelativeFromHType,
35 pub relative_from_v: RelativeFromVType,
36 pub dist_t: i32,
39 pub dist_b: i32,
40 pub dist_l: i32,
41 pub dist_r: i32,
42}
43
44impl Default for TextBox {
45 fn default() -> Self {
46 Self::new()
47 }
48}
49
50impl TextBox {
51 pub fn new() -> Self {
52 Self {
53 children: vec![],
54 size: (from_px(100), from_px(100)),
55 position_type: DrawingPositionType::Inline,
56 simple_pos: false,
57 simple_pos_x: 0,
58 simple_pos_y: 0,
59 layout_in_cell: false,
60 relative_height: 190500,
61 allow_overlap: false,
62 position_v: DrawingPosition::Offset(0),
63 position_h: DrawingPosition::Offset(0),
64 relative_from_h: RelativeFromHType::default(),
65 relative_from_v: RelativeFromVType::default(),
66 dist_t: 0,
67 dist_b: 0,
68 dist_l: 0,
69 dist_r: 0,
70 }
71 }
72
73 pub fn size(mut self, w_emu: u32, h_emu: u32) -> Self {
75 self.size = (w_emu, h_emu);
76 self
77 }
78
79 pub fn floating(mut self) -> Self {
80 self.position_type = DrawingPositionType::Anchor;
81 self
82 }
83
84 pub fn offset_x(mut self, x: i32) -> Self {
85 self.position_h = DrawingPosition::Offset(x);
86 self
87 }
88
89 pub fn offset_y(mut self, y: i32) -> Self {
90 self.position_v = DrawingPosition::Offset(y);
91 self
92 }
93
94 pub fn position_h(mut self, pos: DrawingPosition) -> Self {
95 self.position_h = pos;
96 self
97 }
98
99 pub fn position_v(mut self, pos: DrawingPosition) -> Self {
100 self.position_v = pos;
101 self
102 }
103
104 pub fn relative_from_h(mut self, t: RelativeFromHType) -> Self {
105 self.relative_from_h = t;
106 self
107 }
108
109 pub fn relative_from_v(mut self, t: RelativeFromVType) -> Self {
110 self.relative_from_v = t;
111 self
112 }
113
114 pub fn dist_t(mut self, v: i32) -> Self {
115 self.dist_t = v;
116 self
117 }
118
119 pub fn dist_b(mut self, v: i32) -> Self {
120 self.dist_b = v;
121 self
122 }
123
124 pub fn dist_l(mut self, v: i32) -> Self {
125 self.dist_l = v;
126 self
127 }
128
129 pub fn dist_r(mut self, v: i32) -> Self {
130 self.dist_r = v;
131 self
132 }
133
134 pub fn simple_pos(mut self, v: bool) -> Self {
135 self.simple_pos = v;
136 self
137 }
138
139 pub fn relative_height(mut self, v: u32) -> Self {
140 self.relative_height = v;
141 self
142 }
143}
144
145