json2pdf_client/protocol/elements/
table.rs1use crate::protocol::elements::Element;
2use crate::BorderSettings;
3use serde::Serialize;
4
5#[derive(Debug, Default, Clone, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Table {
9 rows: Vec<Row>,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 point_layout: Option<Vec<f32>>,
12}
13
14impl Table {
15 pub fn new() -> Self {
17 Self::default()
18 }
19
20 pub fn add_row(mut self, row: Row) -> Self {
22 self.rows.push(row);
23 self
24 }
25
26 pub fn set_rows(mut self, rows: Vec<Row>) -> Self {
28 self.rows = rows;
29 self
30 }
31
32 pub fn set_point_layout(mut self, layout: Vec<f32>) -> Self {
35 self.point_layout = Some(layout);
36 self
37 }
38}
39
40#[allow(clippy::from_over_into)]
41impl Into<Element> for Table {
42 fn into(self) -> Element {
43 Element::table(self)
44 }
45}
46
47#[derive(Debug, Default, Clone, Serialize)]
49pub struct Row {
50 columns: Vec<Column>,
51}
52
53impl Row {
54 pub fn new() -> Self {
56 Self::default()
57 }
58
59 pub fn add_column(mut self, column: Column) -> Self {
61 self.columns.push(column);
62 self
63 }
64
65 pub fn set_columns(mut self, columns: Vec<Column>) -> Self {
67 self.columns = columns;
68 self
69 }
70}
71
72#[derive(Debug, Default, Clone, Serialize)]
74#[serde(rename_all = "camelCase")]
75pub struct Column {
76 border_settings: Option<BorderSettings>,
77 elements: Vec<Element>,
78}
79
80impl Column {
81 pub fn new() -> Self {
83 Self::default()
84 }
85
86 pub fn add_element(mut self, element: Element) -> Self {
88 self.elements.push(element);
89 self
90 }
91
92 pub fn set_elements(mut self, elements: Vec<Element>) -> Self {
94 self.elements = elements;
95 self
96 }
97
98 pub fn set_border(mut self, border: BorderSettings) -> Self {
100 self.border_settings = Some(border);
101 self
102 }
103}