Created
October 7, 2024 20:58
-
-
Save pcwalton/dfbcca5894f512614746f32bee1bdc5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Cargo.toml b/Cargo.toml | |
index 7729047..393959d 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -39,7 +39,7 @@ name = "ui" | |
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", | |
] } | |
egui = { version = "0.28", default-features = false, features = ["bytemuck"] } | |
@@ -52,7 +52,7 @@ 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", | |
diff --git a/src/egui_node.rs b/src/egui_node.rs | |
index 399ee85..b099a81 100644 | |
--- a/src/egui_node.rs | |
+++ b/src/egui_node.rs | |
@@ -23,6 +23,8 @@ use bevy::{ | |
renderer::{RenderContext, RenderDevice, RenderQueue}, | |
texture::{Image, ImageAddressMode, ImageFilterMode, ImageSampler, ImageSamplerDescriptor}, | |
view::ExtractedWindows, | |
+ world_sync::MainEntity, | |
+ MainWorld, | |
}, | |
}; | |
use bytemuck::cast_slice; | |
@@ -187,9 +189,11 @@ impl EguiNode { | |
impl Node for EguiNode { | |
fn update(&mut self, world: &mut World) { | |
- let mut window_sizes = world.query::<(&WindowSize, &mut EguiRenderOutput)>(); | |
+ let mut window_sizes = world.query::<(&WindowSize, &mut EguiRenderOutput, &MainEntity)>(); | |
- let Ok((window_size, mut render_output)) = window_sizes.get_mut(world, self.window_entity) | |
+ let Some((window_size, mut render_output, _)) = window_sizes | |
+ .iter_mut(world) | |
+ .find(|(_, _, entity)| self.window_entity == entity.id()) | |
else { | |
return; | |
}; | |
@@ -367,7 +371,15 @@ impl Node for EguiNode { | |
IndexFormat::Uint32, | |
); | |
- let transform_buffer_offset = egui_transforms.offsets[&self.window_entity]; | |
+ let Some(&render_world_window_id) = egui_transforms.offsets.keys().find(|&render_entity| { | |
+ world | |
+ .get::<MainEntity>(*render_entity) | |
+ .is_some_and(|main_entity| main_entity.id() == self.window_entity) | |
+ }) else { | |
+ return Ok(()); | |
+ }; | |
+ | |
+ let transform_buffer_offset = egui_transforms.offsets[&render_world_window_id]; | |
let transform_buffer_bind_group = &egui_transforms.bind_group.as_ref().unwrap().1; | |
render_pass.set_bind_group(0, transform_buffer_bind_group, &[transform_buffer_offset]); | |
diff --git a/src/systems.rs b/src/systems.rs | |
index 8f0827d..e79b383 100644 | |
--- a/src/systems.rs | |
+++ b/src/systems.rs | |
@@ -14,7 +14,7 @@ use bevy::{ | |
ButtonState, | |
}, | |
log, | |
- prelude::{Entity, EventReader, Query, Resource, Time}, | |
+ prelude::{Commands, Entity, EventReader, Query, Resource, Time, Window, With}, | |
time::Real, | |
window::{CursorMoved, RequestRedraw}, | |
}; | |
@@ -84,7 +84,7 @@ impl<'w, 's> ContextSystemParams<'w, 's> { | |
} | |
Err( | |
err @ QueryEntityError::NoSuchEntity(_) | |
- | err @ QueryEntityError::QueryDoesNotMatch(_), | |
+ | err @ QueryEntityError::QueryDoesNotMatch(..), | |
) => { | |
log::error!("Failed to get an Egui context for a window ({window:?}): {err:?}",); | |
None | |
@@ -474,6 +474,8 @@ pub fn process_output_system( | |
mut egui_clipboard: bevy::ecs::system::ResMut<crate::EguiClipboard>, | |
mut event: EventWriter<RequestRedraw>, | |
#[cfg(windows)] mut last_cursor_icon: Local<bevy::utils::HashMap<Entity, egui::CursorIcon>>, | |
+ windows: Query<Entity, With<Window>>, | |
+ mut commands: Commands, | |
) { | |
let mut should_request_redraw = false; | |
@@ -504,8 +506,14 @@ pub fn process_output_system( | |
} | |
let mut set_icon = || { | |
- context.window.cursor.icon = egui_to_winit_cursor_icon(platform_output.cursor_icon) | |
- .unwrap_or(bevy::window::CursorIcon::Default); | |
+ for window in windows.iter() { | |
+ commands | |
+ .entity(window) | |
+ .insert(bevy::render::view::cursor::CursorIcon::from( | |
+ egui_to_winit_cursor_icon(platform_output.cursor_icon) | |
+ .unwrap_or(bevy::window::SystemCursorIcon::Default), | |
+ )); | |
+ } | |
}; | |
#[cfg(windows)] | |
@@ -547,42 +555,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, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment