Trait bevy_prototype_lyon::geometry::Geometry
source · pub trait Geometry {
// Required method
fn add_geometry(&self, b: &mut Builder);
}
Expand description
Structs that implement this trait can be drawn as a shape. See the
shapes
module for some examples.
§Implementation example
use bevy_prototype_lyon::geometry::Geometry;
use lyon_tessellation::{
math::{Box2D, Point, Size},
path::{path::Builder, traits::PathBuilder, Path, Winding},
};
// First, create a struct to hold the shape features:
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rectangle {
pub width: f32,
pub height: f32,
}
// Implementing the `Default` trait is not required, but it may facilitate the
// definition of the shape before spawning it.
impl Default for Rectangle {
fn default() -> Self {
Self {
width: 1.0,
height: 1.0,
}
}
}
// Finally, implement the `add_geometry` method.
impl Geometry for Rectangle {
fn add_geometry(&self, b: &mut Builder) {
b.add_rectangle(
&Box2D::new(Point::zero(), Point::new(self.width, self.height)),
Winding::Positive,
);
}
}
Required Methods§
sourcefn add_geometry(&self, b: &mut Builder)
fn add_geometry(&self, b: &mut Builder)
Adds the geometry of the shape to the given Lyon path Builder
.