#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Fill {
NonZero,
EvenOdd,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Join {
Bevel,
Miter,
Round,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Cap {
Butt,
Square,
Round,
}
#[derive(Copy, Clone, Debug)]
pub struct Stroke<'a> {
pub width: f32,
pub join: Join,
pub miter_limit: f32,
pub start_cap: Cap,
pub end_cap: Cap,
pub dashes: &'a [f32],
pub offset: f32,
pub scale: bool,
}
impl Default for Stroke<'_> {
fn default() -> Self {
Self {
width: 1.,
join: Join::Miter,
miter_limit: 4.,
start_cap: Cap::Butt,
end_cap: Cap::Butt,
dashes: &[],
offset: 0.,
scale: true,
}
}
}
impl<'a> Stroke<'a> {
#[allow(clippy::field_reassign_with_default)]
pub fn new(width: f32) -> Self {
let mut s = Self::default();
s.width = width;
s
}
pub fn width(&mut self, width: f32) -> &mut Self {
self.width = width;
self
}
pub fn join(&mut self, join: Join) -> &mut Self {
self.join = join;
self
}
pub fn miter_limit(&mut self, limit: f32) -> &mut Self {
self.miter_limit = limit;
self
}
pub fn cap(&mut self, cap: Cap) -> &mut Self {
self.start_cap = cap;
self.end_cap = cap;
self
}
pub fn caps(&mut self, start: Cap, end: Cap) -> &mut Self {
self.start_cap = start;
self.end_cap = end;
self
}
pub fn dash(&mut self, dashes: &'a [f32], offset: f32) -> &mut Self {
self.dashes = dashes;
self.offset = offset;
self
}
pub fn scale(&mut self, scale: bool) -> &mut Self {
self.scale = scale;
self
}
}
#[derive(Copy, Clone, Debug)]
pub enum Style<'a> {
Fill(Fill),
Stroke(Stroke<'a>),
}
impl Default for Style<'_> {
fn default() -> Self {
Self::Fill(Fill::NonZero)
}
}
impl Style<'_> {
pub fn is_stroke(&self) -> bool {
matches!(self, Self::Stroke(_))
}
}
impl From<Fill> for Style<'_> {
fn from(style: Fill) -> Self {
Self::Fill(style)
}
}
impl<'a> From<Stroke<'a>> for Style<'a> {
fn from(style: Stroke<'a>) -> Self {
Self::Stroke(style)
}
}
impl<'a> From<&'a Stroke<'a>> for Style<'a> {
fn from(style: &'a Stroke<'a>) -> Self {
Self::Stroke(*style)
}
}
impl<'a> From<&'a mut Stroke<'a>> for Style<'a> {
fn from(style: &'a mut Stroke<'a>) -> Self {
Self::Stroke(*style)
}
}