#[derive(Clone, Debug)]
pub struct ElementText {
pub family: String,
pub face: crate::render::backend::FontFace,
pub size: f64,
pub color: (u8, u8, u8),
pub angle: f64,
pub hjust: f64,
pub vjust: f64,
pub visible: bool,
}
impl ElementText {
pub fn blank() -> Self {
ElementText {
visible: false,
..Default::default()
}
}
}
impl Default for ElementText {
fn default() -> Self {
ElementText {
family: "sans-serif".to_string(),
face: crate::render::backend::FontFace::Plain,
size: 12.0,
color: (0, 0, 0),
angle: 0.0,
hjust: 0.5,
vjust: 0.5,
visible: true,
}
}
}
#[derive(Clone, Debug)]
pub struct ElementLine {
pub color: (u8, u8, u8),
pub width: f64,
pub visible: bool,
pub linetype: crate::render::backend::Linetype,
}
impl ElementLine {
pub fn blank() -> Self {
ElementLine {
visible: false,
..Default::default()
}
}
}
impl Default for ElementLine {
fn default() -> Self {
ElementLine {
color: (0, 0, 0),
width: 1.0,
visible: true,
linetype: crate::render::backend::Linetype::Solid,
}
}
}
#[derive(Clone, Debug)]
pub struct ElementRect {
pub fill: Option<(u8, u8, u8)>,
pub color: Option<(u8, u8, u8)>,
pub width: f64,
pub visible: bool,
}
impl ElementRect {
pub fn blank() -> Self {
ElementRect {
visible: false,
..Default::default()
}
}
}
impl Default for ElementRect {
fn default() -> Self {
ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Default)]
pub struct ElementGeom {
pub ink: Option<(u8, u8, u8)>,
pub paper: Option<(u8, u8, u8)>,
pub accent: Option<(u8, u8, u8)>,
pub family: Option<String>,
}
impl ElementGeom {
pub fn with_ink(mut self, color: (u8, u8, u8)) -> Self {
self.ink = Some(color);
self
}
pub fn with_paper(mut self, color: (u8, u8, u8)) -> Self {
self.paper = Some(color);
self
}
pub fn with_accent(mut self, color: (u8, u8, u8)) -> Self {
self.accent = Some(color);
self
}
pub fn with_family(mut self, family: &str) -> Self {
self.family = Some(family.to_string());
self
}
}
#[cfg(test)]
mod element_geom_tests {
use super::ElementGeom;
#[test]
fn builders_set_every_field() {
let el = ElementGeom::default()
.with_ink((1, 2, 3))
.with_paper((4, 5, 6))
.with_accent((7, 8, 9))
.with_family("Georgia");
assert_eq!(el.ink, Some((1, 2, 3)));
assert_eq!(el.paper, Some((4, 5, 6)));
assert_eq!(el.accent, Some((7, 8, 9)));
assert_eq!(el.family, Some("Georgia".to_string()));
}
}