use super::Point;
use super::Shape;
use crate::graphics::colours::RGBA;
use crate::graphics::Size;
use crate::{Border, Radius};
pub struct Builder<const N: usize> {
shape: Option<Shape>,
}
impl<const N: usize> Builder<N> {
pub fn new() -> Self {
Self { shape: None }
}
pub fn create(&mut self, points: [Point; N], borders: Option<[Border; N]>) -> &mut Self {
let borders = if borders == None {
vec![]
} else {
borders.unwrap().to_vec()
};
self.shape = Some(Shape {
points: points.to_vec(),
borders,
filled: (false, None),
radius: Radius::new(0.0),
});
self
}
pub fn fill(&mut self, colour: RGBA) -> &mut Self {
self.shape.as_mut().unwrap().filled = (true, Some(colour));
self
}
pub fn round(&mut self, radius: Radius) -> &mut Self {
self.shape.as_mut().unwrap().radius = radius;
self
}
pub fn finish(&mut self) -> Shape {
self.shape.clone().unwrap()
}
}
impl Builder<4> {
pub fn rectangle(&mut self, size: Size, borders: Option<[Border; 4]>) -> &mut Self {
self.create(
[
[0, 0],
[size[0] as isize, 0],
[size[0] as isize, size[1] as isize],
[0, size[1] as isize],
],
borders,
)
}
}