Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsk: Add builder for Stroke #1482

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions gsk4/src/stroke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Take a look at the license at the top of the repository in the LICENSE file.

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 {
assert_initialized_main_thread!();
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
}

// rustdoc-stripper-ignore-next
/// Build the [`Stroke`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Stroke {
self.0
}
}
Loading