gsk4/
stroke.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{LineCap, LineJoin, Stroke};
4
5impl Stroke {
6    // rustdoc-stripper-ignore-next
7    /// Creates a new builder-pattern struct instance to construct a [`Stroke`].
8    ///
9    /// This method returns an instance of
10    /// [`StrokeBuilder`](crate::builders::StrokeBuilder) which can be used to
11    /// create a [`Stroke`].
12    pub fn builder(line_width: f32) -> StrokeBuilder {
13        assert_initialized_main_thread!();
14        StrokeBuilder(Stroke::new(line_width))
15    }
16}
17
18// rustdoc-stripper-ignore-next
19/// A [builder-pattern] type to construct a [`Stroke`].
20///
21/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
22#[must_use = "The builder must be built to be used"]
23pub struct StrokeBuilder(Stroke);
24
25impl StrokeBuilder {
26    pub fn dash(self, dash: &[f32]) -> Self {
27        self.0.set_dash(dash);
28        self
29    }
30
31    pub fn dash_offset(self, dash_offset: f32) -> Self {
32        self.0.set_dash_offset(dash_offset);
33        self
34    }
35
36    pub fn line_cap(self, line_cap: LineCap) -> Self {
37        self.0.set_line_cap(line_cap);
38        self
39    }
40
41    pub fn line_join(self, line_join: LineJoin) -> Self {
42        self.0.set_line_join(line_join);
43        self
44    }
45
46    pub fn miter_limit(self, miter_limit: f32) -> Self {
47        self.0.set_miter_limit(miter_limit);
48        self
49    }
50
51    // rustdoc-stripper-ignore-next
52    /// Build the [`Stroke`].
53    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
54    pub fn build(self) -> Stroke {
55        self.0
56    }
57}