use crate::protocol::elements::Element;
use crate::BorderSettings;
use serde::Serialize;
#[derive(Debug, Default, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Table {
rows: Vec<Row>,
#[serde(skip_serializing_if = "Option::is_none")]
point_layout: Option<Vec<f32>>,
}
impl Table {
pub fn new() -> Self {
Self::default()
}
pub fn add_row(mut self, row: Row) -> Self {
self.rows.push(row);
self
}
pub fn set_rows(mut self, rows: Vec<Row>) -> Self {
self.rows = rows;
self
}
pub fn set_point_layout(mut self, layout: Vec<f32>) -> Self {
self.point_layout = Some(layout);
self
}
}
#[allow(clippy::from_over_into)]
impl Into<Element> for Table {
fn into(self) -> Element {
Element::table(self)
}
}
#[derive(Debug, Default, Clone, Serialize)]
pub struct Row {
columns: Vec<Column>,
}
impl Row {
pub fn new() -> Self {
Self::default()
}
pub fn add_column(mut self, column: Column) -> Self {
self.columns.push(column);
self
}
pub fn set_columns(mut self, columns: Vec<Column>) -> Self {
self.columns = columns;
self
}
}
#[derive(Debug, Default, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Column {
border_settings: Option<BorderSettings>,
elements: Vec<Element>,
}
impl Column {
pub fn new() -> Self {
Self::default()
}
pub fn add_element(mut self, element: Element) -> Self {
self.elements.push(element);
self
}
pub fn set_elements(mut self, elements: Vec<Element>) -> Self {
self.elements = elements;
self
}
pub fn set_border(mut self, border: BorderSettings) -> Self {
self.border_settings = Some(border);
self
}
}