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

egui 0.29 support #313

Merged
merged 5 commits into from
Oct 4, 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
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ 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).

## Unreleased

### Changed

- Update Egui to 0.29 ([#313](https://github.com/mvlabat/bevy_egui/pull/313) by @PPakalns).

### Additional notes on breaking changes

- `EguiSettings` is now a component.
- `EguiSet::BeginFrame` has been renamed to `EguiSet::BeginPass`.

## [0.29.0] - 18-Aug-2024

### Added

- Initial worldspace UI support ([#304](https://github.com/mvlabat/bevy_egui/pull/304) by @TheButlah, @Schmarni-Dev)
- Paint callback support ([#303](https://github.com/mvlabat/bevy_egui/pull/303) by @PPakalns)
- Initial worldspace UI support ([#304](https://github.com/mvlabat/bevy_egui/pull/304) by @TheButlah, @Schmarni-Dev).
- Paint callback support ([#303](https://github.com/mvlabat/bevy_egui/pull/303) by @PPakalns).

### Changed

Expand Down Expand Up @@ -75,7 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Update Bevy to 0.13 ([#236](https://github.com/mvlabat/bevy_egui/pull/236) by @eri).
- Update Egui to 0.26
- Update Egui to 0.26.

### Fixed

Expand Down
37 changes: 20 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ required-features = ["render"]
name = "simple"
required-features = ["render"]
[[example]]
name = "simple_multipass"
required-features = ["render"]
[[example]]
name = "two_windows"
required-features = ["render"]
[[example]]
Expand All @@ -46,10 +49,10 @@ required-features = ["render"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_asset",
"bevy_winit",
"bevy_asset",
"bevy_winit",
] }
egui = { version = "0.28", default-features = false, features = ["bytemuck"] }
egui = { version = "0.29", default-features = false, features = ["bytemuck"] }
bytemuck = "1"
webbrowser = { version = "1.0.1", optional = true }
wgpu-types = "0.20"
Expand All @@ -61,25 +64,25 @@ thread_local = { version = "1.1.0", optional = true }
[dev-dependencies]
version-sync = "0.9.4"
bevy = { version = "0.14.0", default-features = false, features = [
"x11",
"png",
"bevy_pbr",
"bevy_core_pipeline",
"tonemapping_luts",
"webgl2",
"x11",
"png",
"bevy_pbr",
"bevy_core_pipeline",
"tonemapping_luts",
"webgl2",
] }
egui = { version = "0.28", default-features = false, features = ["bytemuck"] }
egui = { version = "0.29", default-features = false, features = ["bytemuck"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
winit = "0.30"
web-sys = { version = "0.3.63", features = [
"Clipboard",
"ClipboardEvent",
"DataTransfer",
'Document',
'EventTarget',
"Window",
"Navigator",
"Clipboard",
"ClipboardEvent",
"DataTransfer",
'Document',
'EventTarget',
"Window",
"Navigator",
] }
js-sys = "0.3.63"
wasm-bindgen = "0.2.84"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
// Systems that create Egui widgets should be run during the `CoreSet::Update` set,
// or after the `EguiSet::BeginFrame` system (which belongs to the `CoreSet::PreUpdate` set).
// or after the `EguiSet::BeginPass` system (which belongs to the `CoreSet::PreUpdate` set).
.add_systems(Update, ui_example_system)
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
// Systems that create Egui widgets should be run during the `CoreSet::Update` set,
// or after the `EguiSet::BeginFrame` system (which belongs to the `CoreSet::PreUpdate` set).
// or after the `EguiSet::BeginPass` system (which belongs to the `CoreSet::PreUpdate` set).
.add_systems(Update, ui_example_system)
.run();
}
Expand Down
42 changes: 42 additions & 0 deletions examples/simple_multipass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::num::NonZero;

use bevy::prelude::*;
use bevy_egui::{EguiContext, EguiFullOutput, EguiInput, EguiPlugin, EguiSettings, EguiStartupSet};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_systems(
PreStartup,
configure_context.after(EguiStartupSet::InitContexts),
)
.add_systems(Update, ui_example_system)
.run();
}

fn configure_context(mut egui_settings: Query<&mut EguiSettings>) {
egui_settings.single_mut().run_manually = true;
}

fn ui_example_system(mut contexts: Query<(&mut EguiContext, &mut EguiInput, &mut EguiFullOutput)>) {
let (mut ctx, mut egui_input, mut egui_full_output) = contexts.single_mut();

let ui = |ctx: &egui::Context| {
egui::Window::new("Hello").show(ctx, |ui| {
let passes = ui
.ctx()
.viewport(|viewport| viewport.output.num_completed_passes)
+ 1;
ui.label(format!("Passes: {}", passes));
ui.ctx().request_discard("Trying to reach max limit");
});
};

let ctx = ctx.get_mut();
ctx.memory_mut(|memory| {
memory.options.max_passes = NonZero::new(5).unwrap();
});

**egui_full_output = Some(ctx.run(egui_input.take(), ui));
}
7 changes: 3 additions & 4 deletions examples/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy::prelude::*;
use bevy_egui::{EguiContexts, EguiPlugin, EguiSettings};

struct Images {
Expand Down Expand Up @@ -63,13 +63,12 @@ fn configure_ui_state_system(mut ui_state: ResMut<UiState>) {
fn update_ui_scale_factor_system(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut toggle_scale_factor: Local<Option<bool>>,
mut egui_settings: ResMut<EguiSettings>,
windows: Query<&Window, With<PrimaryWindow>>,
mut contexts: Query<(&mut EguiSettings, &Window)>,
) {
if keyboard_input.just_pressed(KeyCode::Slash) || toggle_scale_factor.is_none() {
*toggle_scale_factor = Some(!toggle_scale_factor.unwrap_or(true));

if let Ok(window) = windows.get_single() {
if let Ok((mut egui_settings, window)) = contexts.get_single_mut() {
let scale_factor = if toggle_scale_factor.unwrap() {
1.0
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,17 @@ impl Node for EguiNode {
return;
};

let mut render_target_size = world.query::<(&RenderTargetSize, &mut EguiRenderOutput)>();
let mut render_target_query =
world.query::<(&EguiSettings, &RenderTargetSize, &mut EguiRenderOutput)>();

let Ok((window_size, mut render_output)) =
render_target_size.get_mut(world, self.window_entity)
let Ok((egui_settings, window_size, mut render_output)) =
render_target_query.get_mut(world, self.window_entity)
else {
return;
};
let window_size = *window_size;
let paint_jobs = std::mem::take(&mut render_output.paint_jobs);

let egui_settings = &world.get_resource::<EguiSettings>().unwrap();

let render_device = world.get_resource::<RenderDevice>().unwrap();

self.pixels_per_point = window_size.scale_factor * egui_settings.scale_factor;
if window_size.physical_width == 0.0 || window_size.physical_height == 0.0 {
return;
Expand All @@ -258,6 +255,8 @@ impl Node for EguiNode {
self.index_data.clear();
self.postponed_updates.clear();

let render_device = world.get_resource::<RenderDevice>().unwrap();

for egui::epaint::ClippedPrimitive {
clip_rect,
primitive,
Expand Down
12 changes: 5 additions & 7 deletions src/egui_render_to_texture_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,23 @@ impl Node for EguiRenderToTextureNode {
return;
};

let mut render_target_sizes = world.query::<(&RenderTargetSize, &mut EguiRenderOutput)>();
let Ok((render_target_size, mut render_output)) =
render_target_sizes.get_mut(world, self.render_to_texture_target)
let mut render_target_query =
world.query::<(&EguiSettings, &RenderTargetSize, &mut EguiRenderOutput)>();
let Ok((egui_settings, render_target_size, mut render_output)) =
render_target_query.get_mut(world, self.render_to_texture_target)
else {
return;
};

let render_target_size = *render_target_size;
let paint_jobs = std::mem::take(&mut render_output.paint_jobs);

let egui_settings = &world.get_resource::<EguiSettings>().unwrap();

let render_device = world.get_resource::<RenderDevice>().unwrap();

self.pixels_per_point = render_target_size.scale_factor * egui_settings.scale_factor;
if render_target_size.physical_width == 0.0 || render_target_size.physical_height == 0.0 {
return;
}

let render_device = world.get_resource::<RenderDevice>().unwrap();
let mut index_offset = 0;

self.draw_commands.clear();
Expand Down
Loading
Loading