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

bevy_prototype_lyon v0.12.0 #250

Merged
merged 16 commits into from
Jul 5, 2024
14 changes: 6 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Changelog
## 0.10.0
- Support for Bevy 0.12.
- `ShapeBundle` now contains the `spatial: SpatialBundle` field, which bundles together `Transform`, `GlobalTransform`, `Visibility` and `InheritedVisibility`.

## 0.9.0
- Support for Bevy 0.11.
## 0.12.0
- Support for Bevy 0.14.

## 0.11.0
- Support for Bevy 0.13
- Support for Bevy 0.13.

## 0.10.0
- Support for Bevy 0.12
- Support for Bevy 0.12.
- `ShapeBundle` now contains the `spatial: SpatialBundle` field, which bundles together `Transform`, `GlobalTransform`, `Visibility` and `InheritedVisibility`.

## 0.9.0
- Support for Bevy 0.11.
- `ShapeBundle` now contains the `spatial: SpatialBundle` field,
which bundles together
`Transform`,
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ license = "MIT OR Apache-2.0"
name = "bevy_prototype_lyon"
readme = "README.md"
repository = "https://github.com/Nilirad/bevy_prototype_lyon/"
version = "0.11.0"
version = "0.12.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.13", default-features = false, features = [
"bevy_sprite",
"bevy_render",
"bevy_core_pipeline",
"bevy_asset",
bevy = { version = "0.14", default-features = false, features = [
"bevy_sprite",
"bevy_render",
"bevy_core_pipeline",
"bevy_asset",
] }
lyon_tessellation = "1"
lyon_algorithms = "1"
svgtypes = "0.12"

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = [
"x11",
"bevy_asset",
bevy = { version = "0.14", default-features = false, features = [
"x11",
"bevy_asset",
] }
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ cargo add bevy_prototype_lyon
Then, you can start by drawing simple shapes:

```rust
use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_prototype_lyon::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.run();
}
Expand All @@ -52,8 +51,8 @@ fn setup_system(mut commands: Commands) {
path: GeometryBuilder::build_as(&shape),
..default()
},
Fill::color(Color::CYAN),
Stroke::new(Color::BLACK, 10.0),
Fill::color(DARK_CYAN),
Stroke::new(BLACK, 10.0),
));
}
```
Expand All @@ -68,6 +67,7 @@ The following table shows the latest version of `bevy_prototype_lyon` that suppo

|bevy|bevy_prototype_lyon|license|
|---|---|---|
|0.14|0.12|MIT/Apache 2.0|
|0.13|0.11|MIT/Apache 2.0|
|0.12|0.10|MIT/Apache 2.0|
|0.11|0.9|MIT/Apache 2.0|
Expand Down
9 changes: 4 additions & 5 deletions examples/dynamic_shape.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::f64::consts::PI;

use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_prototype_lyon::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.add_systems(Update, change_draw_mode_system)
.add_systems(Update, change_number_of_sides)
Expand Down Expand Up @@ -63,8 +62,8 @@ fn setup_system(mut commands: Commands) {
path: GeometryBuilder::build_as(&shape),
..default()
},
Fill::color(Color::CYAN),
Stroke::new(Color::BLACK, 10.0),
Fill::color(DARK_CYAN),
Stroke::new(BLACK, 10.0),
ExampleShape,
));
}
9 changes: 4 additions & 5 deletions examples/path.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_prototype_lyon::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.run();
}
Expand Down Expand Up @@ -36,7 +35,7 @@ fn setup_system(mut commands: Commands) {
},
..default()
},
Stroke::new(Color::BLACK, 10.0),
Fill::color(Color::RED),
Stroke::new(BLACK, 10.0),
Fill::color(RED),
));
}
9 changes: 4 additions & 5 deletions examples/readme.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! This is the example that goes to the README.md file. The README.md should be
//! updated before every release.

use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_prototype_lyon::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.run();
}
Expand All @@ -26,7 +25,7 @@ fn setup_system(mut commands: Commands) {
path: GeometryBuilder::build_as(&shape),
..default()
},
Fill::color(Color::CYAN),
Stroke::new(Color::BLACK, 10.0),
Fill::color(DARK_CYAN),
Stroke::new(BLACK, 10.0),
));
}
7 changes: 3 additions & 4 deletions examples/rounded_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bevy::prelude::*;
use bevy::{color::palettes::css::*, prelude::*};
use bevy_prototype_lyon::prelude::*;

fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.run();
}
Expand Down Expand Up @@ -34,6 +33,6 @@ fn setup_system(mut commands: Commands) {
path: GeometryBuilder::build_as(&shape),
..default()
},
Fill::color(Color::CYAN),
Fill::color(DARK_CYAN),
));
}
3 changes: 1 addition & 2 deletions examples/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ fn main() {
App::new()
//Added msaa to reduce aliasing
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_plugins((DefaultPlugins, ShapePlugin))
.add_systems(Startup, setup_system)
.run();
}
Expand Down
14 changes: 7 additions & 7 deletions src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Types for defining shape color and options.

use bevy::{ecs::component::Component, render::color::Color};
use bevy::{color::Color, ecs::component::Component};
use lyon_tessellation::{FillOptions, StrokeOptions};

/// Defines the fill options for the lyon tessellator and color of the generated
Expand All @@ -15,10 +15,10 @@ pub struct Fill {
impl Fill {
/// Convenience constructor requiring only the `Color`.
#[must_use]
pub fn color(color: Color) -> Self {
pub fn color(color: impl Into<Color>) -> Self {
Self {
options: FillOptions::default(),
color,
color: color.into(),
}
}
}
Expand All @@ -35,19 +35,19 @@ pub struct Stroke {
impl Stroke {
/// Constructor that requires a `Color` and a line width.
#[must_use]
pub fn new(color: Color, line_width: f32) -> Self {
pub fn new(color: impl Into<Color>, line_width: f32) -> Self {
Self {
options: StrokeOptions::default().with_line_width(line_width),
color,
color: color.into(),
}
}

/// Convenience constructor requiring only the `Color`.
#[must_use]
pub fn color(color: Color) -> Self {
pub fn color(color: impl Into<Color>) -> Self {
Self {
options: StrokeOptions::default(),
color,
color: color.into(),
}
}
}
8 changes: 5 additions & 3 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl GeometryBuilder {
/// ```
/// # use bevy::prelude::*;
/// # use bevy_prototype_lyon::prelude::*;
/// # use bevy::color::palettes;
/// #
/// fn my_system(mut commands: Commands) {
/// let line = shapes::Line(Vec2::ZERO, Vec2::new(10.0, 0.0));
Expand All @@ -80,8 +81,8 @@ impl GeometryBuilder {
/// path: builder.build(),
/// ..default()
/// },
/// Fill::color(Color::ORANGE_RED),
/// Stroke::new(Color::ORANGE_RED, 10.0),
/// Fill::color(Color::Srgba(palettes::css::ORANGE_RED)),
/// Stroke::new(Color::Srgba(palettes::css::ORANGE_RED), 10.0),
/// ));
/// }
/// # bevy::ecs::system::assert_is_system(my_system);
Expand All @@ -107,6 +108,7 @@ impl GeometryBuilder {
/// ```
/// # use bevy::prelude::*;
/// # use bevy_prototype_lyon::prelude::*;
/// # use bevy::color::palettes;
/// #
/// fn my_system(mut commands: Commands) {
/// let line = shapes::Line(Vec2::ZERO, Vec2::new(10.0, 0.0));
Expand All @@ -115,7 +117,7 @@ impl GeometryBuilder {
/// path: GeometryBuilder::build_as(&line),
/// ..default()
/// },
/// Fill::color(Color::ORANGE_RED),
/// Fill::color(Color::Srgba(palettes::css::ORANGE_RED)),
/// ));
/// }
/// # bevy::ecs::system::assert_is_system(my_system);
Expand Down
19 changes: 11 additions & 8 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! `ShapeBundle`.

use bevy::{
color::palettes,
prelude::*,
render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology},
sprite::Mesh2dHandle,
Expand Down Expand Up @@ -43,13 +44,15 @@ impl Plugin for ShapePlugin {
)
.add_systems(PostUpdate, mesh_shapes_system.in_set(BuildShapes));

app.world.resource_mut::<Assets<ColorMaterial>>().insert(
COLOR_MATERIAL_HANDLE,
ColorMaterial {
color: Color::WHITE,
..default()
},
);
app.world_mut()
.resource_mut::<Assets<ColorMaterial>>()
.insert(
&COLOR_MATERIAL_HANDLE,
ColorMaterial {
color: Color::WHITE,
..default()
},
);
}
}

Expand Down Expand Up @@ -85,7 +88,7 @@ fn mesh_shapes_system(
fill(
&mut fill_tess,
&path.0,
&Fill::color(Color::FUCHSIA),
&Fill::color(Color::Srgba(palettes::css::FUCHSIA)),
&mut buffers,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ impl Geometry for Line {
/// 1) Go to File>Document Properties>General>Display Units and set it to px
///
/// 2) In File>Document Properties>Custom Size>Units set it to px, also, this
/// size would be used for `svg_doc_size_in_px`
/// size would be used for `svg_doc_size_in_px`
///
/// 3) In File>Document Properties>Scale>Scale x make sure it is set to 1 User
/// unit per px
/// unit per px
///
///Example exists in the examples folder
pub struct SvgPathShape {
Expand Down
6 changes: 3 additions & 3 deletions src/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::render::color::Color;
use bevy::color::{Color, ColorToComponents};
use lyon_tessellation::{
self as tess, FillVertex, FillVertexConstructor, StrokeVertex, StrokeVertexConstructor,
};
Expand Down Expand Up @@ -27,7 +27,7 @@ impl FillVertexConstructor<Vertex> for VertexConstructor {
fn new_vertex(&mut self, vertex: FillVertex) -> Vertex {
Vertex {
position: [vertex.position().x, vertex.position().y],
color: self.color.as_linear_rgba_f32(),
color: self.color.to_linear().to_f32_array(),
}
}
}
Expand All @@ -37,7 +37,7 @@ impl StrokeVertexConstructor<Vertex> for VertexConstructor {
fn new_vertex(&mut self, vertex: StrokeVertex) -> Vertex {
Vertex {
position: [vertex.position().x, vertex.position().y],
color: self.color.as_linear_rgba_f32(),
color: self.color.to_linear().to_f32_array(),
}
}
}
Loading