use super::{Brush, Thickness};
#[derive(Default)]
pub struct BorderBuilder {
brush: Brush,
thickness: Thickness,
radius: f64,
}
impl BorderBuilder {
pub fn new() -> BorderBuilder {
BorderBuilder::default()
}
pub fn brush<B: Into<Brush>>(mut self, brush: B) -> Self {
self.brush = brush.into();
self
}
pub fn thickness(mut self, thickness: Thickness) -> Self {
self.thickness = thickness;
self
}
pub fn radius(mut self, radius: f64) -> Self {
self.radius = radius;
self
}
pub fn build(self) -> Border {
Border {
brush: self.brush,
thickness: self.thickness,
radius: self.radius,
}
}
}
#[derive(Clone, Default, Debug, PartialEq)]
pub struct Border {
brush: Brush,
thickness: Thickness,
radius: f64,
}
impl Border {
pub fn create() -> BorderBuilder {
BorderBuilder::new()
}
pub fn brush(&self) -> &Brush {
&self.brush
}
pub fn set_brush<B: Into<Brush>>(&mut self, brush: B) {
self.brush = brush.into();
}
pub fn thickness(&self) -> Thickness {
self.thickness
}
pub fn set_thickness(&mut self, thickness: Thickness) {
self.thickness = thickness;
}
pub fn radius(&self) -> f64 {
self.radius
}
pub fn set_radius(&mut self, radius: f64) {
self.radius = radius
}
}
pub trait Bordered {
fn border_thickness(&self) -> Thickness;
fn set_border_thickness(&mut self, thickness: Thickness);
fn border_brush(&self) -> &Brush;
fn set_border_brush(&mut self, brush: Brush);
fn border_radius(&self) -> f64;
fn set_border_radius(&mut self, radius: f64);
fn border(&self) -> &Border;
fn set_border(&mut self, border: Border);
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn test_brush() {
let brush = Brush::from("#000000");
let builder = BorderBuilder::new();
let border = builder.brush(brush).build();
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let builder = BorderBuilder::new();
let border = builder.thickness(thickness).build();
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_radius() {
let radius = 0.0;
let builder = BorderBuilder::new();
let border = builder.radius(radius).build();
assert!(crate::f64_cmp(border.radius(), radius));
}
#[test]
fn test_set_brush() {
let brush = Brush::from("#000000");
let mut border = Border::default();
border.set_brush(brush);
let test_brush = Brush::from("#000000");
assert_eq!(border.brush(), &test_brush);
}
#[test]
fn test_set_thickness() {
let thickness = Thickness::new(0.0, 0.0, 0.0, 0.0);
let mut border = Border::default();
border.set_thickness(thickness);
assert_eq!(border.thickness(), thickness);
}
#[test]
fn test_set_radius() {
let radius = 0.0;
let mut border = Border::default();
border.set_radius(radius);
assert!(crate::f64_cmp(border.radius(), radius));
}
}