use super::colors::Color;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Fill {
pub fill_type: Option<String>,
pub rotation: i64,
pub start_color: Color,
pub end_color: Color,
}
impl Default for Fill {
fn default() -> Self {
Fill {
fill_type: None,
rotation: 0,
start_color: Color::new(Color::WHITE),
end_color: Color::new(Color::BLACK),
}
}
}
impl Fill {
pub const FILL_NONE: Option<&'static str> = None;
pub const FILL_SOLID: &'static str = "solid";
pub const FILL_GRADIENT_LINEAR: &'static str = "linear";
pub const FILL_GRADIENT_PATH: &'static str = "path";
pub const FILL_PATTERN_DARKDOWN: &'static str = "darkDown";
pub const FILL_PATTERN_DARKGRAY: &'static str = "darkGray";
pub const FILL_PATTERN_DARKGRID: &'static str = "darkGrid";
pub const FILL_PATTERN_DARKHORIZONTAL: &'static str = "darkHorizontal";
pub const FILL_PATTERN_DARKTRELLIS: &'static str = "darkTrellis";
pub const FILL_PATTERN_DARKUP: &'static str = "darkUp";
pub const FILL_PATTERN_DARKVERTICAL: &'static str = "darkVertical";
pub const FILL_PATTERN_GRAY0625: &'static str = "gray0625";
pub const FILL_PATTERN_GRAY125: &'static str = "gray125";
pub const FILL_PATTERN_LIGHTDOWN: &'static str = "lightDown";
pub const FILL_PATTERN_LIGHTGRAY: &'static str = "lightGray";
pub const FILL_PATTERN_LIGHTGRID: &'static str = "lightGrid";
pub const FILL_PATTERN_LIGHTHORIZONTAL: &'static str = "lightHorizontal";
pub const FILL_PATTERN_LIGHTTRELLIS: &'static str = "lightTrellis";
pub const FILL_PATTERN_LIGHTUP: &'static str = "lightUp";
pub const FILL_PATTERN_LIGHTVERTICAL: &'static str = "lightVertical";
pub const FILL_PATTERN_MEDIUMGRAY: &'static str = "mediumGray";
pub fn new() -> Self {
Fill::default()
}
pub fn solid(color: Color) -> Self {
Fill {
fill_type: Some(Fill::FILL_SOLID.to_string()),
start_color: color,
..Fill::default()
}
}
pub fn with_fill_type(mut self, pattern: Option<&str>) -> Self {
self.fill_type = pattern.map(|p| p.to_string());
self
}
pub fn with_start_color(mut self, color: Color) -> Self {
self.start_color = color;
self
}
pub fn with_end_color(mut self, color: Color) -> Self {
self.end_color = color;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_match_python() {
let fill = Fill::new();
assert_eq!(fill.fill_type, None);
assert_eq!(fill.rotation, 0);
assert_eq!(fill.start_color.index, Color::WHITE);
assert_eq!(fill.end_color.index, Color::BLACK);
}
#[test]
fn solid_helper() {
let fill = Fill::solid(Color::new("FFFF0000"));
assert_eq!(fill.fill_type.as_deref(), Some("solid"));
assert_eq!(fill.start_color.index, "FFFF0000");
}
#[test]
fn equality_uses_all_fields() {
let a = Fill::new();
let mut b = Fill::new();
assert_eq!(a, b);
b.rotation = 90;
assert_ne!(a, b);
}
}