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