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 to bevy 0.5 #12

Merged
merged 28 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3172593
Use EventReader directly, which was made possible by Bevy PR #1244
Weasy666 Jan 19, 2021
0e3a9d2
Track Bevy master branch
Weasy666 Jan 19, 2021
37145b2
add BufferMapMode to map_buffer (#5)
jakobhellermann Jan 25, 2021
1591437
update bevy to new wgpu api
jakobhellermann Feb 8, 2021
bf3347b
don't use exclusive systems in ui example
jakobhellermann Feb 17, 2021
7420b31
add bevy to dev-dependencies to fix wasm-bindgen resolution error
jakobhellermann Feb 17, 2021
fd9af83
make sure bevy UI is rendered before egui
jakobhellermann Feb 17, 2021
6044dea
update bevy stage labels
jakobhellermann Feb 18, 2021
909eca6
fmt
jakobhellermann Feb 20, 2021
4ac85f0
wip: port to ecs v2
jakobhellermann Feb 26, 2021
531076c
update to ecs v2
jakobhellermann Feb 27, 2021
caa7eac
only connect UI_PASS node if it exists
jakobhellermann Mar 6, 2021
fb800be
undo dev-dependencies change as that breaks wasm dependencies
jakobhellermann Mar 6, 2021
5726c83
use the bevy_winit feature instead of the crate
jakobhellermann Mar 7, 2021
92943b7
update bevy, use system dependencies instead of stages
jakobhellermann Mar 12, 2021
6411ba3
specify bevy main branch
jakobhellermann Mar 12, 2021
0ed4e17
make EguiSystem public
jakobhellermann Mar 12, 2021
0e8335a
fix doc links
jakobhellermann Mar 12, 2021
92b11f7
Merge branch 'main' into bevy-0.5
jakobhellermann Mar 20, 2021
606989d
use v2 resolver and specify bevy as dev-dependency
jakobhellermann Mar 26, 2021
9f18bb6
use bevy 0.5
jakobhellermann Apr 7, 2021
5cea17b
Apply suggestions from code review
jakobhellermann Apr 7, 2021
177ac26
explicit prelude imports
jakobhellermann Apr 7, 2021
7a1e240
simplify ci features
jakobhellermann Apr 7, 2021
a84623c
update bevy_webgl2 version
jakobhellermann Apr 9, 2021
2e822b7
update egui to 0.11
jakobhellermann Apr 9, 2021
79459cb
only set cursor icon if not none
jakobhellermann Apr 10, 2021
880deeb
work around egui layouting bug
jakobhellermann Apr 10, 2021
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
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
features: [
'bevy/x11,bevy/png,bevy/bevy_wgpu',
'bevy/x11,bevy/png,bevy/bevy_wgpu,manage_clipboard',
'bevy/x11,bevy/png,bevy/bevy_wgpu,open_url',
'bevy/x11,bevy/png,bevy/bevy_wgpu,manage_clipboard,open_url',
'',
'manage_clipboard',
'open_url',
'manage_clipboard,open_url',
]
steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT"
edition = "2018"
repository = "https://github.com/mvlabat/bevy_egui"
exclude = ["assets/**/*", ".github/**/*"]
resolver = "2"

[package.metadata.docs.rs]
no-default-features = true # clipboard crate fails the build currently https://github.com/rust-lang/docs.rs/issues/695
Expand All @@ -19,9 +20,8 @@ manage_clipboard = ["clipboard", "thread_local"]
open_url = ["webbrowser"]

[dependencies]
bevy = { version = "0.4", default-features = false, features = ["render"] }
bevy_winit = "0.4.0"
egui = "0.10.0"
bevy = { version = "0.5", default-features = false, features = ["render", "bevy_winit"] }
egui = "0.11.0"
webbrowser = { version = "0.5.5", optional = true }
winit = { version = "0.24.0", features = ["x11"], default-features = false }

Expand All @@ -32,7 +32,5 @@ thread_local = { version = "1.1.0", optional = true }
[dev-dependencies]
version-sync = "0.9.2"

[[example]]
name = "ui"
path = "examples/ui.rs"
required-features = ["bevy/x11", "bevy/png", "bevy/bevy_wgpu"]
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
bevy = { version = "0.5", default-features = false, features = ["bevy_wgpu", "x11", "png"] }
mvlabat marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ that require additional crates, can be disabled.

An example WASM project is live at [mvlabat.github.io/bevy_egui_web_showcase](https://mvlabat.github.io/bevy_egui_web_showcase/index.html) [[source](https://github.com/mvlabat/bevy_egui_web_showcase)].

**Note** that in order to use `bevy_egui`in WASM you need [bevy_webgl2](https://github.com/mrk-its/bevy_webgl2) of at least `0.4.1` version.
**Note** that in order to use `bevy_egui`in WASM you need [bevy_webgl2](https://github.com/mrk-its/bevy_webgl2) of at least `0.5.0` version.

## Usage

Here's a minimal usage example:
```toml
# Cargo.toml
[dependencies]
bevy = "0.4"
bevy = "0.5"
bevy_egui = "0.3"
```

Expand All @@ -57,10 +57,17 @@ fn ui_example(mut egui_context: ResMut<EguiContext>) {
For a more advanced example, see [examples/ui.rs](examples/ui.rs).

```bash
cargo run --example ui --features="bevy/x11 bevy/png bevy/bevy_wgpu"
cargo run --example ui
```

## See also

- [`jakobhellermann/bevy-inspector-egui`](https://github.com/jakobhellermann/bevy-inspector-egui)
- [`mvlabat/bevy_megaui`](https://github.com/mvlabat/bevy_megaui)

## Bevy support table

|bevy|bevy_egui|
|---|---|
|0.5|0.4|
|0.4|0.1-0.3|
29 changes: 13 additions & 16 deletions examples/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const BEVY_TEXTURE_ID: u64 = 0;

fn main() {
App::build()
.add_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.insert_resource(Msaa { samples: 4 })
.init_resource::<UiState>()
.add_plugins(DefaultPlugins)
.add_plugin(EguiPlugin)
.add_startup_system(load_assets.system())
Expand All @@ -23,11 +24,8 @@ struct UiState {
inverted: bool,
}

fn load_assets(_world: &mut World, resources: &mut Resources) {
let mut egui_context = resources.get_mut::<EguiContext>().unwrap();
let asset_server = resources.get::<AssetServer>().unwrap();

let texture_handle = asset_server.load("icon.png");
fn load_assets(mut egui_context: ResMut<EguiContext>, assets: Res<AssetServer>) {
let texture_handle = assets.load("icon.png");
egui_context.set_egui_texture(BEVY_TEXTURE_ID, texture_handle);
}

Expand All @@ -37,12 +35,12 @@ fn update_ui_scale_factor(mut egui_settings: ResMut<EguiSettings>, windows: Res<
}
}

fn ui_example(_world: &mut World, resources: &mut Resources) {
resources.get_or_insert_with(UiState::default);

let mut egui_ctx = resources.get_mut::<EguiContext>().unwrap();
fn ui_example(
mut egui_ctx: ResMut<EguiContext>,
mut ui_state: ResMut<UiState>,
assets: Res<AssetServer>,
) {
let ctx = &mut egui_ctx.ctx;
let mut ui_state = resources.get_mut::<UiState>().unwrap();

let mut load = false;
let mut remove = false;
Expand All @@ -56,7 +54,7 @@ fn ui_example(_world: &mut World, resources: &mut Resources) {
ui.text_edit_singleline(&mut ui_state.label);
});

ui.add(egui::Slider::f32(&mut ui_state.value, 0.0..=10.0).text("value"));
ui.add(egui::Slider::new(&mut ui_state.value, 0.0..=10.0).text("value"));
if ui.button("Increment").clicked() {
ui_state.value += 1.0;
}
Expand Down Expand Up @@ -121,11 +119,10 @@ fn ui_example(_world: &mut World, resources: &mut Resources) {
ui_state.inverted = !ui_state.inverted;
}
if load || invert {
let asset_server = resources.get::<AssetServer>().unwrap();
let texture_handle = if ui_state.inverted {
asset_server.load("icon_inverted.png")
assets.load("icon_inverted.png")
} else {
asset_server.load("icon.png")
assets.load("icon.png")
};
egui_ctx.set_egui_texture(BEVY_TEXTURE_ID, texture_handle);
}
Expand Down
Loading