1use esoc_color::Color;
5
6#[derive(Clone, Debug)]
8pub struct StrokeStyle {
9 pub color: Color,
11 pub width: f32,
13 pub dash: Vec<f32>,
15 pub dash_offset: f32,
17 pub line_cap: LineCap,
19 pub line_join: LineJoin,
21}
22
23impl Default for StrokeStyle {
24 fn default() -> Self {
25 Self {
26 color: Color::BLACK,
27 width: 1.0,
28 dash: Vec::new(),
29 dash_offset: 0.0,
30 line_cap: LineCap::Butt,
31 line_join: LineJoin::Miter,
32 }
33 }
34}
35
36impl StrokeStyle {
37 pub fn solid(color: Color, width: f32) -> Self {
39 Self {
40 color,
41 width,
42 ..Default::default()
43 }
44 }
45
46 pub fn is_none(&self) -> bool {
48 self.width <= 0.0 || self.color.a <= 0.0
49 }
50}
51
52#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
54pub enum LineCap {
55 #[default]
57 Butt,
58 Round,
60 Square,
62}
63
64#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
66pub enum LineJoin {
67 #[default]
69 Miter,
70 Round,
72 Bevel,
74}
75
76#[derive(Clone, Debug, Default)]
78pub enum FillStyle {
79 #[default]
81 None,
82 Solid(Color),
84}
85
86impl FillStyle {
87 pub fn color(&self) -> Option<Color> {
89 match self {
90 Self::None => None,
91 Self::Solid(c) => Some(*c),
92 }
93 }
94
95 pub fn is_none(&self) -> bool {
97 matches!(self, Self::None)
98 }
99}
100
101impl From<Color> for FillStyle {
102 fn from(c: Color) -> Self {
103 Self::Solid(c)
104 }
105}
106
107#[derive(Clone, Debug)]
109pub struct FontStyle {
110 pub family: String,
112 pub size: f32,
114 pub weight: u16,
116 pub italic: bool,
118}
119
120impl Default for FontStyle {
121 fn default() -> Self {
122 Self {
123 family: "sans-serif".to_string(),
124 size: 12.0,
125 weight: 400,
126 italic: false,
127 }
128 }
129}
130
131impl FontStyle {
132 pub fn bold(mut self) -> Self {
134 self.weight = 700;
135 self
136 }
137
138 pub fn with_size(mut self, size: f32) -> Self {
140 self.size = size;
141 self
142 }
143}
144
145#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
147pub enum MarkerShape {
148 #[default]
150 Circle,
151 Square,
153 Diamond,
155 TriangleUp,
157 TriangleDown,
159 Cross,
161 Star,
163 Plus,
165}
166
167impl MarkerShape {
168 pub fn type_index(self) -> u32 {
170 match self {
171 Self::Circle => 0,
172 Self::Square => 1,
173 Self::Diamond => 2,
174 Self::TriangleUp => 3,
175 Self::TriangleDown => 4,
176 Self::Cross => 5,
177 Self::Star => 6,
178 Self::Plus => 7,
179 }
180 }
181}