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 0.15 #68

Merged
merged 5 commits into from
Dec 1, 2024
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ version = "0.15.0"
bevy_egui = ["dep:bevy_egui"]

[dependencies]
bevy = {version = "0.14", features = ["bevy_render"], default-features = false}
bevy_egui = {version = "0.30", optional = true, default-features = false}
bevy = { version = "0.15", features = ["bevy_window", "bevy_core_pipeline"], default-features = false }
bevy_egui = { version = "0.31", optional = true, default-features = false }

[dev-dependencies]
bevy = {version = "0.14", default-features = false, features = [
bevy = {version = "0.15", default-features = false, features = [
"bevy_render",
"bevy_asset",
"bevy_sprite",
"bevy_winit",
"bevy_core_pipeline",
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
]}
bevy-inspector-egui = { version = "0.27", default-features = false, features = ["bevy_render"]}
bevy_egui = {version = "0.30", default-features = false, features = ["default_fonts"]}
bevy-inspector-egui = { version = "0.28", default-features = false, features = ["bevy_render"] }
bevy_egui = { version = "0.31", default-features = false, features = ["default_fonts"] }
rand = "0.8"

[[example]]
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ App::new()
Add the component to an orthographic camera:

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

This is enough to get going with sensible defaults.

Alternatively, set the fields of the `PanCam` component to customize behavior:

```rust ignore
commands.spawn(Camera2dBundle::default())
.insert(PanCam {
commands.spawn((
Camera2d,
PanCam {
grab_buttons: vec![MouseButton::Left, MouseButton::Middle], // which buttons should drag the camera
move_keys: DirectionKeys { // the keyboard buttons used to move the camera
up: vec![KeyCode::KeyQ], // initalize the struct like this or use the provided methods for
Expand All @@ -52,8 +55,13 @@ commands.spawn(Camera2dBundle::default())
enabled: true, // when false, controls are disabled. See toggle example.
zoom_to_cursor: true, // whether to zoom towards the mouse or the center of the screen
min_scale: 1., // prevent the camera from zooming too far in
max_scale: Some(40.), // prevent the camera from zooming too far out
});
max_scale: 40., // prevent the camera from zooming too far out
min_x: f32::NEG_INFINITY, // minimum x position of the camera window
max_x: f32::INFINITY, // maximum x position of the camera window
min_y: f32::NEG_INFINITY, // minimum y position of the camera window
max_y: f32::INFINITY, // maximum y position of the camera window
},
));
```

See the [`simple`](./examples/simple.rs) and [`toggle`](./examples/toggle.rs) examples.
Expand Down
20 changes: 11 additions & 9 deletions examples/camera_scaling_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
let mut cam = Camera2dBundle::default();
cam.projection.scaling_mode = ScalingMode::FixedVertical(10.0);
let mut ortho = OrthographicProjection::default_2d();
ortho.scaling_mode = ScalingMode::FixedVertical {
viewport_height: 10.0,
};

commands.spawn((
cam,
Camera2d,
ortho,
PanCam {
min_x: -10.,
max_x: 10.,
Expand All @@ -33,15 +36,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/clamped_borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
commands.spawn((
Camera2dBundle::default(),
Camera2d,
PanCam {
// prevent the camera from zooming too far out
max_scale: 40.,
Expand Down Expand Up @@ -40,15 +40,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default(), EguiPlugin))
.add_plugins((DefaultPlugins, PanCamPlugin, EguiPlugin))
.add_systems(Update, egui_ui)
.add_systems(Startup, setup)
.run();
Expand All @@ -33,7 +33,7 @@ fn egui_ui(mut contexts: EguiContexts) {
}

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

let n = 20;
let spacing = 50.;
Expand All @@ -44,15 +44,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
17 changes: 6 additions & 11 deletions examples/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ use rand::random;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
PanCamPlugin::default(),
WorldInspectorPlugin::default(),
))
.add_plugins((DefaultPlugins, PanCamPlugin, WorldInspectorPlugin::new()))
.add_systems(Startup, setup)
.run();
}

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

let n = 20;
let spacing = 50.;
Expand All @@ -26,15 +22,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
commands.spawn((
Camera2dBundle::default(),
Camera2d,
PanCam {
// Set max scale in order to prevent the camera from zooming too far out
max_scale: 40.,
Expand All @@ -30,15 +30,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

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

let n = 20;
let spacing = 50.;
Expand All @@ -21,15 +21,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.add_systems(Update, toggle_key)
.run();
}

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

let n = 20;
let spacing = 50.;
Expand All @@ -22,15 +22,14 @@ 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(SpriteBundle {
sprite: Sprite {
commands.spawn((
Sprite {
color,
custom_size,
..default()
},
transform: Transform::from_xyz(x, y, 0.),
..default()
});
Transform::from_xyz(x, y, 0.),
));
}
}
}
Expand Down
Loading