Skip to content

Commit 8bd76b2

Browse files
SeaDvebilelmoussaoui
authored andcommitted
gsk: Add builder for Stroke
1 parent 0665f3c commit 8bd76b2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

gsk4/src/builders.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
66
pub use crate::auto::builders::*;
77
pub use crate::color_stop::ColorStopBuilder;
8+
#[cfg(feature = "v4_14")]
9+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
10+
pub use crate::stroke::StrokeBuilder;
811
pub use crate::ShaderArgsBuilder;

gsk4/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ mod rounded_clip_node;
7979
mod shadow_node;
8080
#[cfg(feature = "v4_14")]
8181
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
82+
mod stroke;
83+
#[cfg(feature = "v4_14")]
84+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
8285
mod stroke_node;
8386
mod text_node;
8487
mod texture_node;

gsk4/src/stroke.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)