1#[derive(Copy, Clone, PartialEq, Eq, Debug)]
5pub enum Fill {
6 NonZero,
8 EvenOdd,
10}
11
12#[derive(Copy, Clone, PartialEq, Eq, Debug)]
14pub enum Join {
15 Bevel,
17 Miter,
19 Round,
21}
22
23#[derive(Copy, Clone, PartialEq, Eq, Debug)]
25pub enum Cap {
26 Butt,
28 Square,
30 Round,
32}
33
34#[derive(Copy, Clone, Debug)]
36pub struct Stroke<'a> {
37 pub width: f32,
39 pub join: Join,
41 pub miter_limit: f32,
43 pub start_cap: Cap,
45 pub end_cap: Cap,
47 pub dashes: &'a [f32],
49 pub offset: f32,
51 pub scale: bool,
53}
54
55impl Default for Stroke<'_> {
56 fn default() -> Self {
57 Self {
58 width: 1.,
59 join: Join::Miter,
60 miter_limit: 4.,
61 start_cap: Cap::Butt,
62 end_cap: Cap::Butt,
63 dashes: &[],
64 offset: 0.,
65 scale: true,
66 }
67 }
68}
69
70impl<'a> Stroke<'a> {
71 #[allow(clippy::field_reassign_with_default)]
73 pub fn new(width: f32) -> Self {
74 let mut s = Self::default();
75 s.width = width;
76 s
77 }
78
79 pub fn width(&mut self, width: f32) -> &mut Self {
81 self.width = width;
82 self
83 }
84
85 pub fn join(&mut self, join: Join) -> &mut Self {
88 self.join = join;
89 self
90 }
91
92 pub fn miter_limit(&mut self, limit: f32) -> &mut Self {
95 self.miter_limit = limit;
96 self
97 }
98
99 pub fn cap(&mut self, cap: Cap) -> &mut Self {
103 self.start_cap = cap;
104 self.end_cap = cap;
105 self
106 }
107
108 pub fn caps(&mut self, start: Cap, end: Cap) -> &mut Self {
110 self.start_cap = start;
111 self.end_cap = end;
112 self
113 }
114
115 pub fn dash(&mut self, dashes: &'a [f32], offset: f32) -> &mut Self {
118 self.dashes = dashes;
119 self.offset = offset;
120 self
121 }
122
123 pub fn scale(&mut self, scale: bool) -> &mut Self {
125 self.scale = scale;
126 self
127 }
128}
129
130#[derive(Copy, Clone, Debug)]
132pub enum Style<'a> {
133 Fill(Fill),
134 Stroke(Stroke<'a>),
135}
136
137impl Default for Style<'_> {
138 fn default() -> Self {
139 Self::Fill(Fill::NonZero)
140 }
141}
142
143impl Style<'_> {
144 pub fn is_stroke(&self) -> bool {
146 matches!(self, Self::Stroke(_))
147 }
148}
149
150impl From<Fill> for Style<'_> {
151 fn from(style: Fill) -> Self {
152 Self::Fill(style)
153 }
154}
155
156impl<'a> From<Stroke<'a>> for Style<'a> {
157 fn from(style: Stroke<'a>) -> Self {
158 Self::Stroke(style)
159 }
160}
161
162impl<'a> From<&'a Stroke<'a>> for Style<'a> {
163 fn from(style: &'a Stroke<'a>) -> Self {
164 Self::Stroke(*style)
165 }
166}
167
168impl<'a> From<&'a mut Stroke<'a>> for Style<'a> {
169 fn from(style: &'a mut Stroke<'a>) -> Self {
170 Self::Stroke(*style)
171 }
172}