paperforge-layout 0.1.0

High-level document layout engine
Documentation
use paperforge_core::{Color, Point};

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Style {
    Normal,
    Bold,
    Italic,
    BoldItalic,
    Underline,
    Strikethrough,
}

#[derive(Debug, Clone)]
pub struct Span {
    pub text: String,
    pub style: Style,
    pub color: Color,
    pub font_size: f64,
}

impl Span {
    pub fn new(text: &str) -> Self {
        Self {
            text: text.to_string(),
            style: Style::Normal,
            color: Color::black(),
            font_size: 12.0,
        }
    }

    pub fn normal(mut self) -> Self {
        self.style = Style::Normal;
        self
    }

    pub fn bold(mut self) -> Self {
        self.style = Style::Bold;
        self
    }

    pub fn italic(mut self) -> Self {
        self.style = Style::Italic;
        self
    }

    pub fn underline(mut self) -> Self {
        self.style = Style::Underline;
        self
    }

    pub fn color(mut self, color: Color) -> Self {
        self.color = color;
        self
    }

    pub fn font_size(mut self, size: f64) -> Self {
        self.font_size = size;
        self
    }
}

#[derive(Debug, Clone)]
pub struct TextBuilder {
    pub position: Point,
    pub font_size: f64,
    pub color: Color,
    pub text: String,
}

impl TextBuilder {
    pub fn new() -> Self {
        Self {
            position: Point::new(0.0, 0.0),
            font_size: 12.0,
            color: Color::black(),
            text: String::new(),
        }
    }

    pub fn at(mut self, x: f64, y: f64) -> Self {
        self.position = Point::new(x, y);
        self
    }

    pub fn font_size(mut self, size: f64) -> Self {
        self.font_size = size;
        self
    }

    pub fn color(mut self, color: Color) -> Self {
        self.color = color;
        self
    }

    pub fn write(mut self, text: &str) -> Self {
        self.text = text.to_string();
        self
    }
}

impl Default for TextBuilder {
    fn default() -> Self {
        Self::new()
    }
}