pub struct ShapeBuilder { /* private fields */ }Expand description
A builder for creating complex shapes using a fluent interface.
The ShapeBuilder allows you to define the stroke and path of a shape using
method chaining. Fill is assigned per instance through the renderer, and an
unset fill renders as transparent. 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 is set per-instance via the renderer (renderer.set_shape_color)
.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 a default black 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 duplicate 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 UnsafeUnpin 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