pub enum Shape {
Path(PathShape),
Rect(RectShape),
}Expand description
Represents a graphical shape, which can be either a custom path or a simple rectangle.
§Variants
Path(PathShape): A custom path shape defined using Bézier curves and lines.Rect(RectShape): A simple rectangular shape with optional rounded corners.
§Examples
use grafo::Color;
use grafo::Stroke;
use grafo::{Shape, BorderRadii};
// Create a simple rectangle
let rect = Shape::rect(
[(0.0, 0.0), (100.0, 50.0)],
Color::rgb(255, 0, 0), // Red fill
Stroke::new(2.0, Color::BLACK), // Black stroke with width 2.0
);
// Create a custom path shape
let custom_path = Shape::builder()
.fill(Color::rgb(0, 255, 0))
.stroke(Stroke::new(1.0, Color::BLACK))
.begin((0.0, 0.0))
.line_to((50.0, 10.0))
.line_to((50.0, 50.0))
.close()
.build();Variants§
Path(PathShape)
A custom path shape defined using Bézier curves and lines.
Rect(RectShape)
A simple rectangular shape.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn builder() -> ShapeBuilder
pub fn builder() -> ShapeBuilder
Creates a new ShapeBuilder for constructing complex shapes.
§Examples
use grafo::Shape;
let builder = Shape::builder();Sourcepub fn rect(rect: [(f32, f32); 2], fill_color: Color, stroke: Stroke) -> Shape
pub fn rect(rect: [(f32, f32); 2], fill_color: Color, stroke: Stroke) -> Shape
Creates a simple rectangle shape with the specified coordinates, fill color, and stroke.
§Parameters
rect: An array containing two tuples representing the top-left and bottom-right coordinates of the rectangle.fill_color: The fill color of the rectangle.stroke: The stroke properties of the rectangle.
§Examples
use grafo::Color;
use grafo::Stroke;
use grafo::Shape;
let rect = Shape::rect(
[(0.0, 0.0), (100.0, 50.0)],
Color::rgb(255, 0, 0), // Red fill
Stroke::new(2.0, Color::BLACK), // Black stroke with width 2.0
);Sourcepub fn rounded_rect(
rect: [(f32, f32); 2],
border_radii: BorderRadii,
fill_color: Color,
stroke: Stroke,
) -> Shape
pub fn rounded_rect( rect: [(f32, f32); 2], border_radii: BorderRadii, fill_color: Color, stroke: Stroke, ) -> Shape
Creates a rectangle shape with rounded corners.
§Parameters
rect: An array containing two tuples representing the top-left and bottom-right coordinates of the rectangle.border_radii: The radii for each corner of the rectangle.fill_color: The fill color of the rectangle.stroke: The stroke properties of the rectangle.
§Examples
use grafo::Color;
use grafo::Stroke;
use grafo::{Shape, BorderRadii};
let rounded_rect = Shape::rounded_rect(
[(0.0, 0.0), (100.0, 50.0)],
BorderRadii::new(10.0),
Color::rgba(0, 255, 0, 128), // Semi-transparent green fill
Stroke::new(1.5, Color::BLACK), // Black stroke with width 1.5
);Trait Implementations§
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 Shape
impl RefUnwindSafe for Shape
impl Send for Shape
impl Sync for Shape
impl Unpin for Shape
impl UnwindSafe for Shape
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