Skip to content

Commit

Permalink
gsk: Add builder for Stroke
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Aug 31, 2023
1 parent 87180d0 commit 83924c3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gsk4/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@

pub use crate::auto::builders::*;
pub use crate::color_stop::ColorStopBuilder;
#[cfg(feature = "v4_14")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
pub use crate::stroke::StrokeBuilder;
pub use crate::ShaderArgsBuilder;
3 changes: 3 additions & 0 deletions gsk4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ mod rounded_clip_node;
mod shadow_node;
#[cfg(feature = "v4_14")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
mod stroke;
#[cfg(feature = "v4_14")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
mod stroke_node;
mod text_node;
mod texture_node;
Expand Down
49 changes: 49 additions & 0 deletions gsk4/src/stroke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::{LineCap, LineJoin, Stroke};

impl Stroke {
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct a [`Stroke`].
///
/// This method returns an instance of [`StrokeBuilder`](crate::builders::StrokeBuilder) which can be used to create a [`Stroke`].
pub fn builder(line_width: f32) -> StrokeBuilder {
StrokeBuilder(Stroke::new(line_width))
}
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct a [`Stroke`].
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct StrokeBuilder(Stroke);

impl StrokeBuilder {
pub fn dash(self, dash: &[f32]) -> Self {
self.0.set_dash(dash);
self
}

pub fn dash_offset(self, dash_offset: f32) -> Self {
self.0.set_dash_offset(dash_offset);
self
}

pub fn line_cap(self, line_cap: LineCap) -> Self {
self.0.set_line_cap(line_cap);
self
}

pub fn line_join(self, line_join: LineJoin) -> Self {
self.0.set_line_join(line_join);
self
}

pub fn miter_limit(self, miter_limit: f32) -> Self {
self.0.set_miter_limit(miter_limit);
self
}

pub fn build(self) -> Stroke {
self.0
}
}

0 comments on commit 83924c3

Please sign in to comment.