use crate::constants::DEFAULT_MARGIN;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
}
impl Color {
pub fn rgb(r: f32, g: f32, b: f32) -> Self {
Self {
r: r.clamp(0.0, 1.0),
g: g.clamp(0.0, 1.0),
b: b.clamp(0.0, 1.0),
}
}
pub fn black() -> Self {
Self::rgb(0.0, 0.0, 0.0)
}
pub fn white() -> Self {
Self::rgb(1.0, 1.0, 1.0)
}
pub fn gray(level: f32) -> Self {
let l = level.clamp(0.0, 1.0);
Self::rgb(l, l, l)
}
pub fn light_gray() -> Self {
Self::gray(0.8)
}
}
impl Default for Color {
fn default() -> Self {
Self::black()
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Alignment {
Left,
Center,
Right,
}
impl Default for Alignment {
fn default() -> Self {
Self::Left
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum VerticalAlignment {
Top,
Middle,
Bottom,
}
impl Default for VerticalAlignment {
fn default() -> Self {
Self::Middle
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BorderStyle {
None,
Solid,
Dashed,
Dotted,
}
impl Default for BorderStyle {
fn default() -> Self {
Self::Solid
}
}
#[derive(Debug, Clone, Copy)]
pub struct Padding {
pub top: f32,
pub right: f32,
pub bottom: f32,
pub left: f32,
}
impl Padding {
pub fn uniform(value: f32) -> Self {
Self {
top: value,
right: value,
bottom: value,
left: value,
}
}
pub fn symmetric(vertical: f32, horizontal: f32) -> Self {
Self {
top: vertical,
bottom: vertical,
left: horizontal,
right: horizontal,
}
}
}
impl Default for Padding {
fn default() -> Self {
Self::uniform(5.0)
}
}
#[derive(Debug, Clone)]
pub struct TableStyle {
pub border_style: BorderStyle,
pub border_width: f32,
pub border_color: Color,
pub background_color: Option<Color>,
pub padding: Padding,
pub font_name: String,
pub default_font_size: f32,
pub page_height: Option<f32>,
pub top_margin: f32,
pub bottom_margin: f32,
pub repeat_headers: bool,
pub embedded_font_resource_name: Option<String>,
pub embedded_font_resource_name_bold: Option<String>,
}
impl Default for TableStyle {
fn default() -> Self {
Self {
border_style: BorderStyle::Solid,
border_width: 1.0,
border_color: Color::black(),
background_color: None,
padding: Padding::default(),
font_name: "Helvetica".to_string(),
default_font_size: 10.0,
page_height: None, top_margin: DEFAULT_MARGIN,
bottom_margin: DEFAULT_MARGIN,
repeat_headers: true,
embedded_font_resource_name: None,
embedded_font_resource_name_bold: None,
}
}
}
#[derive(Debug, Clone)]
pub struct RowStyle {
pub background_color: Option<Color>,
pub border_top: Option<(BorderStyle, f32, Color)>,
pub border_bottom: Option<(BorderStyle, f32, Color)>,
pub height: Option<f32>,
}
impl Default for RowStyle {
fn default() -> Self {
Self {
background_color: None,
border_top: None,
border_bottom: None,
height: None,
}
}
}
#[derive(Debug, Clone)]
pub struct CellStyle {
pub background_color: Option<Color>,
pub text_color: Color,
pub font_size: Option<f32>,
pub font_name: Option<String>,
pub bold: bool,
pub italic: bool,
pub alignment: Alignment,
pub vertical_alignment: VerticalAlignment,
pub padding: Option<Padding>,
pub border_left: Option<(BorderStyle, f32, Color)>,
pub border_right: Option<(BorderStyle, f32, Color)>,
pub border_top: Option<(BorderStyle, f32, Color)>,
pub border_bottom: Option<(BorderStyle, f32, Color)>,
pub embedded_font_resource_name: Option<String>,
}
impl Default for CellStyle {
fn default() -> Self {
Self {
background_color: None,
text_color: Color::black(),
font_size: None,
font_name: None,
bold: false,
italic: false,
alignment: Alignment::Left,
vertical_alignment: VerticalAlignment::Middle,
padding: None,
border_left: None,
border_right: None,
border_top: None,
border_bottom: None,
embedded_font_resource_name: None,
}
}
}
impl CellStyle {
pub fn header() -> Self {
Self {
bold: true,
alignment: Alignment::Center,
background_color: Some(Color::light_gray()),
..Default::default()
}
}
}