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

Update for Bevy 0.9 #26

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ license = "MIT OR Apache-2.0"
name = "bevy_pancam"
readme = "readme.md"
repository = "https://github.com/johanhelsing/bevy_pancam"
version = "0.6.1"
version = "0.7.0"

[features]
bevy_egui = ["dep:bevy_egui"]
bevy-inspector-egui = ["dep:bevy-inspector-egui"]

[dependencies]
bevy = {version = "0.8", features = ["render"], default-features = false}
bevy_egui = {version = "0.16", optional = true, default-features = false}
bevy-inspector-egui = { version = "0.13", optional = true, default-features = false }
bevy = {version = "0.9", features = ["render"], default-features = false}
bevy_egui = {version = "0.17", optional = true, default-features = false}
bevy-inspector-egui = { version = "0.14", optional = true, default-features = false }

[dev-dependencies]
bevy = {version = "0.8", default-features = false, features = [
bevy = {version = "0.9", default-features = false, features = [
"render",
"bevy_asset",
"bevy_winit",
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
]}
rand = "0.8"
bevy_egui = {version = "0.16", default-features = false, features = ["default_fonts"]}
bevy-inspector-egui = {version = "0.13", default-features = false}
bevy_egui = {version = "0.17", default-features = false, features = ["default_fonts"]}
bevy-inspector-egui = {version = "0.14", default-features = false}

[[example]]
name = "egui"
Expand Down
19 changes: 11 additions & 8 deletions examples/camera_scaling_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ fn setup(mut commands: Commands) {
let mut cam = Camera2dBundle::default();
cam.projection.scaling_mode = ScalingMode::FixedVertical(10.0);

commands.spawn_bundle(cam).insert(PanCam {
min_x: Some(-10.),
max_x: Some(10.),
min_y: Some(-10.),
max_y: Some(10.0),
..default()
});
commands.spawn((
cam,
PanCam {
min_x: Some(-10.),
max_x: Some(10.),
min_y: Some(-10.),
max_y: Some(10.0),
..default()
},
));

let n = 20;
let spacing = 1.;
Expand All @@ -31,7 +34,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing + offset;
let y = y as f32 * spacing + offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
11 changes: 6 additions & 5 deletions examples/clamped_borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam {
commands.spawn((
Camera2dBundle::default(),
PanCam {
// prevent the camera from zooming too far out
max_scale: Some(40.),
// prevent the camera from zooming too far in
Expand All @@ -29,7 +29,8 @@ fn setup(mut commands: Commands) {
// prevent the camera from panning or zooming past y 1750. value chosen for same reason as above
max_y: Some(1750.),
..default()
});
},
));

let n = 20;
let spacing = 50.;
Expand All @@ -40,7 +41,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
6 changes: 2 additions & 4 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ fn egui_setup(mut egui_context: ResMut<EguiContext>) {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -48,7 +46,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
6 changes: 2 additions & 4 deletions examples/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -26,7 +24,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
11 changes: 6 additions & 5 deletions examples/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam {
commands.spawn((
Camera2dBundle::default(),
PanCam {
// Set max scale in order to prevent the camera from zooming too far out
max_scale: Some(40.),
// Set min scale in order to prevent the camera from zooming too far in
min_scale: 1.,
..default()
});
},
));

let n = 20;
let spacing = 50.;
Expand All @@ -30,7 +31,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
6 changes: 2 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -24,7 +22,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
6 changes: 2 additions & 4 deletions examples/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands
.spawn_bundle(Camera2dBundle::default())
.insert(PanCam::default());
commands.spawn((Camera2dBundle::default(), PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -25,7 +23,7 @@ fn setup(mut commands: Commands) {
let x = x as f32 * spacing - offset;
let y = y as f32 * spacing - offset;
let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
sprite: Sprite {
color,
custom_size,
Expand Down
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ App::new()
Add the component to an orthographic camera:

```rust ignore
commands.spawn_bundle(Camera2dBundle::default())
commands.spawn(Camera2dBundle::default())
.insert(PanCam::default());
```

Expand All @@ -39,7 +39,7 @@ This is enough to get going with sensible defaults.
Alternatively, set the fields of the `PanCam` component to customize behavior:

```rust ignore
commands.spawn_bundle(Camera2dBundle::default())
commands.spawn(Camera2dBundle::default())
.insert(PanCam {
grab_buttons: vec![MouseButton::Left, MouseButton::Middle], // which buttons should drag the camera
enabled: true, // when false, controls are disabled. See toggle example.
Expand All @@ -64,7 +64,8 @@ I intend to support the `main` branch of Bevy in the `bevy-main` branch.

|bevy|bevy_pancam|
|---|---|
|0.8|0.5, 0.6, main|
|0.9|0.7, main|
|0.8|0.5, 0.6|
|0.7|0.3, 0.4|
|0.6|0.2|
|0.5|0.1|
Expand Down