pub struct ShapeBuilder { /* private fields */ }Expand description
A builder for creating complex shapes using a fluent interface.
The ShapeBuilder allows you to define the fill color, stroke, and path of a shape
using method chaining. You also can get it from the Shape::builder method.
§Examples
use grafo::Color;
use grafo::Stroke;
use grafo::ShapeBuilder;
let custom_shape = ShapeBuilder::new()
.fill(Color::rgb(0, 0, 255)) // Blue fill
.stroke(Stroke::new(3.0, Color::BLACK)) // Black stroke with width 3.0
.begin((0.0, 0.0))
.line_to((50.0, 10.0))
.line_to((50.0, 50.0))
.close()
.build();Implementations§
Source§impl ShapeBuilder
impl ShapeBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ShapeBuilder with default fill color (black) and stroke.
§Examples
use grafo::ShapeBuilder;
let builder = ShapeBuilder::new();Sourcepub fn stroke(self, stroke: Stroke) -> Self
pub fn stroke(self, stroke: Stroke) -> Self
Sets the stroke properties of the shape.
§Parameters
stroke: The desired stroke properties.
§Returns
The updated ShapeBuilder instance.
§Examples
use grafo::Stroke;
use grafo::Color;
use grafo::ShapeBuilder;
let builder = ShapeBuilder::new().stroke(Stroke::new(2.0, Color::BLACK)); // Black stroke with width 2.0Sourcepub fn cubic_bezier_to(
self,
ctrl: (f32, f32),
ctrl2: (f32, f32),
to: (f32, f32),
) -> Self
pub fn cubic_bezier_to( self, ctrl: (f32, f32), ctrl2: (f32, f32), to: (f32, f32), ) -> Self
Draws a cubic Bézier curve from the current point to the specified end point.
§Parameters
ctrl: The first control point.ctrl2: The second control point.to: The end point of the curve.
§Returns
The updated ShapeBuilder instance.
§Examples
use grafo::ShapeBuilder;
let builder = ShapeBuilder::new()
.begin((0.0, 0.0))
.cubic_bezier_to((20.0, 30.0), (40.0, 30.0), (50.0, 10.0));Sourcepub fn quadratic_bezier_to(self, ctrl: (f32, f32), to: (f32, f32)) -> Self
pub fn quadratic_bezier_to(self, ctrl: (f32, f32), to: (f32, f32)) -> Self
Draws a quadratic Bézier curve from the current point to the specified end point.
§Parameters
ctrl: The control point.to: The end point of the curve.
§Returns
The updated ShapeBuilder instance.
§Examples
use grafo::ShapeBuilder;
let builder = ShapeBuilder::new()
.begin((0.0, 0.0))
.quadratic_bezier_to((25.0, 40.0), (50.0, 10.0));Trait Implementations§
Source§impl Clone for ShapeBuilder
impl Clone for ShapeBuilder
Source§fn clone(&self) -> ShapeBuilder
fn clone(&self) -> ShapeBuilder
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for ShapeBuilder
impl Default for ShapeBuilder
Source§impl From<ShapeBuilder> for Shape
impl From<ShapeBuilder> for Shape
Source§fn from(value: ShapeBuilder) -> Self
fn from(value: ShapeBuilder) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ShapeBuilder
impl RefUnwindSafe for ShapeBuilder
impl Send for ShapeBuilder
impl Sync for ShapeBuilder
impl Unpin for ShapeBuilder
impl UnwindSafe for ShapeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more