use esoc_color::Color;
#[derive(Clone, Debug)]
pub struct StrokeStyle {
pub color: Color,
pub width: f32,
pub dash: Vec<f32>,
pub dash_offset: f32,
pub line_cap: LineCap,
pub line_join: LineJoin,
}
impl Default for StrokeStyle {
fn default() -> Self {
Self {
color: Color::BLACK,
width: 1.0,
dash: Vec::new(),
dash_offset: 0.0,
line_cap: LineCap::Butt,
line_join: LineJoin::Miter,
}
}
}
impl StrokeStyle {
pub fn solid(color: Color, width: f32) -> Self {
Self {
color,
width,
..Default::default()
}
}
pub fn is_none(&self) -> bool {
self.width <= 0.0 || self.color.a <= 0.0
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LineCap {
#[default]
Butt,
Round,
Square,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LineJoin {
#[default]
Miter,
Round,
Bevel,
}
#[derive(Clone, Debug, Default)]
pub enum FillStyle {
#[default]
None,
Solid(Color),
}
impl FillStyle {
pub fn color(&self) -> Option<Color> {
match self {
Self::None => None,
Self::Solid(c) => Some(*c),
}
}
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
}
impl From<Color> for FillStyle {
fn from(c: Color) -> Self {
Self::Solid(c)
}
}
#[derive(Clone, Debug)]
pub struct FontStyle {
pub family: String,
pub size: f32,
pub weight: u16,
pub italic: bool,
}
impl Default for FontStyle {
fn default() -> Self {
Self {
family: "sans-serif".to_string(),
size: 12.0,
weight: 400,
italic: false,
}
}
}
impl FontStyle {
pub fn bold(mut self) -> Self {
self.weight = 700;
self
}
pub fn with_size(mut self, size: f32) -> Self {
self.size = size;
self
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum MarkerShape {
#[default]
Circle,
Square,
Diamond,
TriangleUp,
TriangleDown,
Cross,
Star,
Plus,
}
impl MarkerShape {
pub fn type_index(self) -> u32 {
match self {
Self::Circle => 0,
Self::Square => 1,
Self::Diamond => 2,
Self::TriangleUp => 3,
Self::TriangleDown => 4,
Self::Cross => 5,
Self::Star => 6,
Self::Plus => 7,
}
}
}