Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into mweb_wasm_keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivy committed Jul 8, 2024
2 parents dd5904d + 6705757 commit 55bad5b
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 78 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.28.0] - 6-Jul-2024

### Changed

- Update Bevy to 0.14 ([#284](https://github.com/mvlabat/bevy_egui/pull/284) by @Friz64).
- Update Egui to 0.28 ([#290](https://github.com/mvlabat/bevy_egui/pull/290) by @Swoorup).
- Update webbrowser to 1.0.1

## [0.27.1] - 2-Jun-2024

### Changed

- Request Redraw only if really needed ([#278](https://github.com/mvlabat/bevy_egui/pull/278) by @Maximetinu).
- Fix light in the `render_to_image_wideget` example ([#282](https://github.com/mvlabat/bevy_egui/pull/282) by @rlidwka).

## [0.27.0] - 18-Apr-2024

### Added
Expand Down
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_egui"
version = "0.27.0"
version = "0.28.0"
authors = ["mvlabat <mvlabat@gmail.com>"]
description = "A plugin for Egui integration into Bevy"
license = "MIT"
Expand Down Expand Up @@ -39,17 +39,20 @@ name = "ui"
required-features = ["render"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] }
egui = { version = "0.27", default-features = false, features = ["bytemuck"] }
webbrowser = { version = "0.8.2", optional = true }
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_asset",
] }
egui = { version = "0.28", default-features = false, features = ["bytemuck"] }
bytemuck = "1"
webbrowser = { version = "1.0.1", optional = true }

[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies]
arboard = { version = "3.2.0", optional = true }
thread_local = { version = "1.1.0", optional = true }

[dev-dependencies]
version-sync = "0.9.4"
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.14.0", default-features = false, features = [
"x11",
"png",
"bevy_pbr",
Expand All @@ -59,7 +62,7 @@ bevy = { version = "0.13", default-features = false, features = [
] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
winit = "0.29"
winit = "0.30"
web-sys = { version = "0.3.63", features = [
"Clipboard",
"ClipboardEvent",
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ An example WASM project is live at [mvlabat.github.io/bevy_egui_web_showcase](ht

**Features:**
- Desktop and web platforms support
- Clipboard (web support is limited to the same window, see [rust-windowing/winit#1829](https://github.com/rust-windowing/winit/issues/1829))
- Clipboard
- Opening URLs
- Multiple windows support (see [./examples/two_windows.rs](https://github.com/mvlabat/bevy_egui/blob/v0.20.1/examples/two_windows.rs))

`bevy_egui` can be compiled with using only `bevy` and `egui` as dependencies: `manage_clipboard` and `open_url` features,
`bevy_egui` can be compiled with using only `bevy`, `egui` and `bytemuck` as dependencies: `manage_clipboard` and `open_url` features,
that require additional crates, can be disabled.

![bevy_egui](bevy_egui.png)
Expand All @@ -43,8 +43,8 @@ Here's a minimal usage example:
```toml
# Cargo.toml
[dependencies]
bevy = "0.13"
bevy_egui = "0.27"
bevy = "0.14"
bevy_egui = "0.28"
```

```rust
Expand Down Expand Up @@ -85,6 +85,7 @@ cargo run --example ui

| bevy | bevy_egui |
|------|-----------|
| 0.14 | 0.28 |
| 0.13 | 0.25-0.27 |
| 0.12 | 0.23-0.24 |
| 0.11 | 0.21-0.22 |
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo::rustc-check-cfg=cfg(web_sys_unstable_apis)");
}
28 changes: 16 additions & 12 deletions examples/render_to_image_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn setup(

let cube_handle = meshes.add(Cuboid::new(4.0, 4.0, 4.0));
let default_material = StandardMaterial {
base_color: Color::rgb(0.8, 0.7, 0.6),
base_color: Color::srgb(0.8, 0.7, 0.6),
reflectance: 0.02,
unlit: false,
..default()
Expand All @@ -89,22 +89,24 @@ fn setup(
..default()
})
.insert(PreviewPassCube)
.insert(preview_pass_layer);
.insert(preview_pass_layer.clone());

// Light
// NOTE: Currently lights are shared between passes - see https://github.com/bevyengine/bevy/issues/3462
commands.spawn(PointLightBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)),
..default()
});
// The same light is reused for both passes,
// you can specify different lights for preview and main pass by setting appropriate RenderLayers.
commands
.spawn(PointLightBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)),
..default()
})
.insert(RenderLayers::default().with(1));

commands
.spawn(Camera3dBundle {
camera: Camera {
// render before the "main pass" camera
order: -1,
target: RenderTarget::Image(image_handle),
clear_color: ClearColorConfig::Custom(Color::rgba(1.0, 1.0, 1.0, 0.0)),
clear_color: ClearColorConfig::Custom(Color::srgba(1.0, 1.0, 1.0, 0.0)),
..default()
},
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
Expand Down Expand Up @@ -164,7 +166,9 @@ fn render_to_image_example_system(
ui.end_row();

ui.label("Emissive:");
color_picker_widget(ui, &mut preview_material.emissive);
let mut emissive_color = Color::from(preview_material.emissive);
color_picker_widget(ui, &mut emissive_color);
preview_material.emissive = emissive_color.into();
ui.end_row();

ui.label("Perceptual roughness:");
Expand Down Expand Up @@ -192,7 +196,7 @@ fn render_to_image_example_system(
}

fn color_picker_widget(ui: &mut egui::Ui, color: &mut Color) -> egui::Response {
let [r, g, b, a] = color.as_rgba_f32();
let [r, g, b, a] = Srgba::from(*color).to_f32_array();
let mut egui_color: egui::Rgba = egui::Rgba::from_srgba_unmultiplied(
(r * 255.0) as u8,
(g * 255.0) as u8,
Expand All @@ -205,7 +209,7 @@ fn color_picker_widget(ui: &mut egui::Ui, color: &mut Color) -> egui::Response {
egui::color_picker::Alpha::Opaque,
);
let [r, g, b, a] = egui_color.to_srgba_unmultiplied();
*color = Color::rgba(
*color = Color::srgba(
r as f32 / 255.0,
g as f32 / 255.0,
b as f32 / 255.0,
Expand Down
4 changes: 2 additions & 2 deletions examples/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ fn setup_system(
) {
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..Default::default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});
Expand Down
4 changes: 2 additions & 2 deletions examples/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl FromWorld for Images {
/// - configuring egui contexts during the startup.
fn main() {
App::new()
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.insert_resource(ClearColor(Color::BLACK))
.insert_resource(Msaa::Sample4)
.init_resource::<UiState>()
.add_plugins(DefaultPlugins.set(WindowPlugin {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Default for Painting {
impl Painting {
pub fn ui_control(&mut self, ui: &mut egui::Ui) -> egui::Response {
ui.horizontal(|ui| {
egui::stroke_ui(ui, &mut self.stroke, "Stroke");
ui.add(&mut self.stroke);
ui.separator();
if ui.button("Clear Painting").clicked() {
self.lines.clear();
Expand Down
2 changes: 1 addition & 1 deletion run-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cargo-run-wasm = "0.2.0"
cargo-run-wasm = "0.4.0"
2 changes: 1 addition & 1 deletion run-wasm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
cargo_run_wasm::run_wasm_cli_with_css("body { margin: 0px; }");
}
2 changes: 1 addition & 1 deletion src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
EguiRenderOutput, EguiSettings, WindowSize,
};
use bevy::{
core::cast_slice,
ecs::world::{FromWorld, World},
prelude::{Entity, Handle, Resource},
render::{
Expand All @@ -26,6 +25,7 @@ use bevy::{
view::ExtractedWindows,
},
};
use bytemuck::cast_slice;
use egui::{TextureFilter, TextureOptions};

/// Egui shader.
Expand Down
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ pub struct EguiRenderOutput {
pub textures_delta: egui::TexturesDelta,
}

impl EguiRenderOutput {
/// Returns `true` if the output has no Egui shapes and no textures delta
pub fn is_empty(&self) -> bool {
self.paint_jobs.is_empty() && self.textures_delta.is_empty()
}
}

/// Is used for storing Egui output.
#[derive(Component, Clone, Default)]
pub struct EguiOutput {
Expand Down Expand Up @@ -630,7 +637,7 @@ impl Plugin for EguiPlugin {
fn build(&self, app: &mut App) {
app.register_type::<EguiSettings>();

let world = &mut app.world;
let world = app.world_mut();
world.init_resource::<EguiSettings>();
#[cfg(feature = "render")]
world.init_resource::<EguiManagedTextures>();
Expand Down Expand Up @@ -753,7 +760,7 @@ impl Plugin for EguiPlugin {

#[cfg(feature = "render")]
fn finish(&self, app: &mut App) {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<egui_node::EguiPipeline>()
.init_resource::<SpecializedRenderPipelines<EguiPipeline>>()
Expand Down Expand Up @@ -900,7 +907,7 @@ fn free_egui_textures_system(
if let egui::TextureId::Managed(texture_id) = texture_id {
let managed_texture = egui_managed_textures.remove(&(window_id, texture_id));
if let Some(managed_texture) = managed_texture {
image_assets.remove(managed_texture.handle);
image_assets.remove(&managed_texture.handle);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/render_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bevy::{
DynamicUniformBuffer, PipelineCache, ShaderType, SpecializedRenderPipelines,
},
renderer::{RenderDevice, RenderQueue},
texture::GpuImage,
view::ExtractedWindows,
Extract,
},
Expand Down Expand Up @@ -188,7 +189,7 @@ pub fn queue_bind_groups_system(
mut commands: Commands,
egui_textures: ExtractedEguiTextures,
render_device: Res<RenderDevice>,
gpu_images: Res<RenderAssets<Image>>,
gpu_images: Res<RenderAssets<GpuImage>>,
egui_pipeline: Res<EguiPipeline>,
) {
let bind_groups = egui_textures
Expand Down
Loading

0 comments on commit 55bad5b

Please sign in to comment.