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.15 #309

Merged
merged 19 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ name = "render_egui_to_texture"
required-features = ["render"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0-dev", default-features = false, features = [
"bevy_asset",
"bevy_winit",
] }
egui = { version = "0.28", default-features = false, features = ["bytemuck"] }
bytemuck = "1"
webbrowser = { version = "1.0.1", optional = true }
wgpu-types = "0.20"
wgpu-types = "22"

[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.14.0", default-features = false, features = [
bevy = { version = "0.15.0-dev", default-features = false, features = [
"x11",
"png",
"bevy_pbr",
Expand Down Expand Up @@ -90,3 +90,6 @@ crossbeam-channel = "0.5.8"

[workspace]
members = ["run-wasm"]

[patch.crates-io]
bevy = { path = "../bevy" }
14 changes: 12 additions & 2 deletions examples/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy::{
prelude::*,
render::view::cursor::CursorIcon,
window::{PrimaryWindow, SystemCursorIcon},
};
use bevy_egui::{EguiContexts, EguiPlugin, EguiSettings};

struct Images {
Expand All @@ -23,7 +27,6 @@ impl FromWorld for Images {
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.insert_resource(Msaa::Sample4)
.init_resource::<UiState>()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
Expand All @@ -33,6 +36,7 @@ fn main() {
..default()
}))
.add_plugins(EguiPlugin)
.add_systems(Startup, configure_cursor)
.add_systems(Startup, configure_visuals_system)
.add_systems(Startup, configure_ui_state_system)
.add_systems(Update, update_ui_scale_factor_system)
Expand All @@ -49,6 +53,12 @@ struct UiState {
is_window_open: bool,
}

fn configure_cursor(mut commands: Commands, windows: Query<Entity, With<PrimaryWindow>>) {
commands
.entity(windows.single())
.insert(CursorIcon::System(SystemCursorIcon::Default));
}

fn configure_visuals_system(mut contexts: EguiContexts) {
contexts.ctx_mut().set_visuals(egui::Visuals {
window_rounding: 0.0.into(),
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ use bevy::{
SystemSet, With, Without,
},
reflect::Reflect,
render::view::cursor::CursorIcon,
window::{PrimaryWindow, Window},
};
#[cfg(all(
Expand Down Expand Up @@ -797,6 +798,8 @@ pub struct EguiContextQuery {
pub render_target_size: &'static mut RenderTargetSize,
/// [`Window`] component, when rendering to a window.
pub window: Option<&'static mut Window>,
/// Cursor for the
Copy link
Contributor

@Friz64 Friz64 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfinished comment

Copy link
Contributor Author

@Vrixyz Vrixyz Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out!

It's part of an actually a non trivial change: The handling of the cursor is changed in bevy 0.15 ; in this PR I moved the initialization of the cursor to the user through configure_cursor :
https://github.com/mvlabat/bevy_egui/blob/3be113b82f8b7122b33f92467d20d2560e0d7722/examples/ui.rs#L56-L60

But I think this code snippet should live with bevy_egui (or bevy_something 🤔 ; but in the meantime we should be able to add it if not present.)

pub cursor: Option<&'static mut CursorIcon>,
/// [`EguiRenderToTextureHandle`] component, when rendering to a texture.
#[cfg(feature = "render")]
pub render_to_texture: Option<&'static mut EguiRenderToTextureHandle>,
Expand Down
80 changes: 42 additions & 38 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,12 @@ pub fn process_output_system(
egui_clipboard.set_contents(&platform_output.copied_text);
}

if let Some(mut window) = context.window {
if let Some(mut cursor) = context.cursor {
let mut set_icon = || {
window.cursor.icon = egui_to_winit_cursor_icon(platform_output.cursor_icon)
.unwrap_or(bevy::window::CursorIcon::Default);
*cursor = bevy::render::view::cursor::CursorIcon::System(
egui_to_winit_cursor_icon(platform_output.cursor_icon)
.unwrap_or(bevy::window::SystemCursorIcon::Default),
);
};

#[cfg(windows)]
Expand Down Expand Up @@ -598,42 +600,44 @@ pub fn process_output_system(
}
}

fn egui_to_winit_cursor_icon(cursor_icon: egui::CursorIcon) -> Option<bevy::window::CursorIcon> {
fn egui_to_winit_cursor_icon(
cursor_icon: egui::CursorIcon,
) -> Option<bevy::window::SystemCursorIcon> {
match cursor_icon {
egui::CursorIcon::Default => Some(bevy::window::CursorIcon::Default),
egui::CursorIcon::PointingHand => Some(bevy::window::CursorIcon::Pointer),
egui::CursorIcon::ResizeHorizontal => Some(bevy::window::CursorIcon::EwResize),
egui::CursorIcon::ResizeNeSw => Some(bevy::window::CursorIcon::NeswResize),
egui::CursorIcon::ResizeNwSe => Some(bevy::window::CursorIcon::NwseResize),
egui::CursorIcon::ResizeVertical => Some(bevy::window::CursorIcon::NsResize),
egui::CursorIcon::Text => Some(bevy::window::CursorIcon::Text),
egui::CursorIcon::Grab => Some(bevy::window::CursorIcon::Grab),
egui::CursorIcon::Grabbing => Some(bevy::window::CursorIcon::Grabbing),
egui::CursorIcon::ContextMenu => Some(bevy::window::CursorIcon::ContextMenu),
egui::CursorIcon::Help => Some(bevy::window::CursorIcon::Help),
egui::CursorIcon::Progress => Some(bevy::window::CursorIcon::Progress),
egui::CursorIcon::Wait => Some(bevy::window::CursorIcon::Wait),
egui::CursorIcon::Cell => Some(bevy::window::CursorIcon::Cell),
egui::CursorIcon::Crosshair => Some(bevy::window::CursorIcon::Crosshair),
egui::CursorIcon::VerticalText => Some(bevy::window::CursorIcon::VerticalText),
egui::CursorIcon::Alias => Some(bevy::window::CursorIcon::Alias),
egui::CursorIcon::Copy => Some(bevy::window::CursorIcon::Copy),
egui::CursorIcon::Move => Some(bevy::window::CursorIcon::Move),
egui::CursorIcon::NoDrop => Some(bevy::window::CursorIcon::NoDrop),
egui::CursorIcon::NotAllowed => Some(bevy::window::CursorIcon::NotAllowed),
egui::CursorIcon::AllScroll => Some(bevy::window::CursorIcon::AllScroll),
egui::CursorIcon::ZoomIn => Some(bevy::window::CursorIcon::ZoomIn),
egui::CursorIcon::ZoomOut => Some(bevy::window::CursorIcon::ZoomOut),
egui::CursorIcon::ResizeEast => Some(bevy::window::CursorIcon::EResize),
egui::CursorIcon::ResizeSouthEast => Some(bevy::window::CursorIcon::SeResize),
egui::CursorIcon::ResizeSouth => Some(bevy::window::CursorIcon::SResize),
egui::CursorIcon::ResizeSouthWest => Some(bevy::window::CursorIcon::SwResize),
egui::CursorIcon::ResizeWest => Some(bevy::window::CursorIcon::WResize),
egui::CursorIcon::ResizeNorthWest => Some(bevy::window::CursorIcon::NwResize),
egui::CursorIcon::ResizeNorth => Some(bevy::window::CursorIcon::NResize),
egui::CursorIcon::ResizeNorthEast => Some(bevy::window::CursorIcon::NeResize),
egui::CursorIcon::ResizeColumn => Some(bevy::window::CursorIcon::ColResize),
egui::CursorIcon::ResizeRow => Some(bevy::window::CursorIcon::RowResize),
egui::CursorIcon::Default => Some(bevy::window::SystemCursorIcon::Default),
egui::CursorIcon::PointingHand => Some(bevy::window::SystemCursorIcon::Pointer),
egui::CursorIcon::ResizeHorizontal => Some(bevy::window::SystemCursorIcon::EwResize),
egui::CursorIcon::ResizeNeSw => Some(bevy::window::SystemCursorIcon::NeswResize),
egui::CursorIcon::ResizeNwSe => Some(bevy::window::SystemCursorIcon::NwseResize),
egui::CursorIcon::ResizeVertical => Some(bevy::window::SystemCursorIcon::NsResize),
egui::CursorIcon::Text => Some(bevy::window::SystemCursorIcon::Text),
egui::CursorIcon::Grab => Some(bevy::window::SystemCursorIcon::Grab),
egui::CursorIcon::Grabbing => Some(bevy::window::SystemCursorIcon::Grabbing),
egui::CursorIcon::ContextMenu => Some(bevy::window::SystemCursorIcon::ContextMenu),
egui::CursorIcon::Help => Some(bevy::window::SystemCursorIcon::Help),
egui::CursorIcon::Progress => Some(bevy::window::SystemCursorIcon::Progress),
egui::CursorIcon::Wait => Some(bevy::window::SystemCursorIcon::Wait),
egui::CursorIcon::Cell => Some(bevy::window::SystemCursorIcon::Cell),
egui::CursorIcon::Crosshair => Some(bevy::window::SystemCursorIcon::Crosshair),
egui::CursorIcon::VerticalText => Some(bevy::window::SystemCursorIcon::VerticalText),
egui::CursorIcon::Alias => Some(bevy::window::SystemCursorIcon::Alias),
egui::CursorIcon::Copy => Some(bevy::window::SystemCursorIcon::Copy),
egui::CursorIcon::Move => Some(bevy::window::SystemCursorIcon::Move),
egui::CursorIcon::NoDrop => Some(bevy::window::SystemCursorIcon::NoDrop),
egui::CursorIcon::NotAllowed => Some(bevy::window::SystemCursorIcon::NotAllowed),
egui::CursorIcon::AllScroll => Some(bevy::window::SystemCursorIcon::AllScroll),
egui::CursorIcon::ZoomIn => Some(bevy::window::SystemCursorIcon::ZoomIn),
egui::CursorIcon::ZoomOut => Some(bevy::window::SystemCursorIcon::ZoomOut),
egui::CursorIcon::ResizeEast => Some(bevy::window::SystemCursorIcon::EResize),
egui::CursorIcon::ResizeSouthEast => Some(bevy::window::SystemCursorIcon::SeResize),
egui::CursorIcon::ResizeSouth => Some(bevy::window::SystemCursorIcon::SResize),
egui::CursorIcon::ResizeSouthWest => Some(bevy::window::SystemCursorIcon::SwResize),
egui::CursorIcon::ResizeWest => Some(bevy::window::SystemCursorIcon::WResize),
egui::CursorIcon::ResizeNorthWest => Some(bevy::window::SystemCursorIcon::NwResize),
egui::CursorIcon::ResizeNorth => Some(bevy::window::SystemCursorIcon::NResize),
egui::CursorIcon::ResizeNorthEast => Some(bevy::window::SystemCursorIcon::NeResize),
egui::CursorIcon::ResizeColumn => Some(bevy::window::SystemCursorIcon::ColResize),
egui::CursorIcon::ResizeRow => Some(bevy::window::SystemCursorIcon::RowResize),
egui::CursorIcon::None => None,
}
}
Expand Down
Loading