From 05d161259b5606d893e94e1ce4ece5a2a5856ffe Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Fri, 27 Oct 2023 11:44:39 -0700 Subject: [PATCH] improve egui backend --- CHANGELOG.md | 2 ++ README.md | 16 +++++++++------- backends/bevy_picking_egui/src/lib.rs | 2 +- examples/egui.rs | 12 +++++++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd0fb89..369bac18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ `PostUpdate`, which means egui hit tests will be one frame out of date. This is required because users tend to build their `egui` UI in `Update`, and egui rebuilds the entire UI from scratch every frame, so the picking backend must be run after users have built their UI. +- Fixed: backend not returning hits when egui is using the pointer to resize windows or drag widgets + like sliders or windows. ## Miscellaneous diff --git a/README.md b/README.md index 33ab7a2d..cc240c5e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ entity, and works with mouse, touch, or even gamepads. - ***Lightweight***: only compile what you need. - ***Expressive***: event listener components `On::>::run(my_system)`. - ***Input Agnostic***: control pointers with mouse, pen, touch, or custom bevy systems. -- ***Modular Backends***: mix and match backends like `rapier`, `egui`, `bevy_ui`, or write your own. +- ***Modular Backends***: mix and match backends like `rapier`, `egui`, `bevy_ui`, or write your own. + ## Lightweight Only compile what you use. All non-critical plugins can be disabled, including highlighting, @@ -50,12 +51,14 @@ commands.spawn(( // Send an event when the pointer is pressed over this entity: On::>::send_event::(), )); - ``` +If you don't need event bubbling or callbacks, you can respond to pointer events like you would any +other bevy event, using `EventReader>`, `EventReader>`, etc. + ## Input Agnostic -Pointers can be controlled with anything, whether its the included mouse or touch inputs, or a +Pointers can be controlled with anything, whether it's the included mouse or touch inputs, or a custom gamepad input system you write yourself. ## Modular Backends @@ -70,8 +73,8 @@ this plugin will handle sorting hits and generating events. ## Robust -In addition to these features, this plugin also correctly handles multitouch, multiple windows, and -multiple layered render passes. +In addition to these features, this plugin also correctly handles multitouch, multiple windows, +render layers, viewports, and camera order. # Getting Started @@ -100,10 +103,9 @@ To learn more, [read the docs](https://docs.rs/bevy_mod_picking/latest/bevy_mod_ I intend to track the `main` branch of Bevy. PRs supporting this are welcome! - | bevy | bevy_mod_picking | | ---- | ---------------- | -| 0.11 | 0.15 | +| 0.11 | 0.15, 0.16 | | 0.10 | 0.12, 0.13, 0.14 | | 0.9 | 0.10, 0.11 | | 0.8 | 0.8, 0.9 | diff --git a/backends/bevy_picking_egui/src/lib.rs b/backends/bevy_picking_egui/src/lib.rs index 5be4be53..1824927a 100644 --- a/backends/bevy_picking_egui/src/lib.rs +++ b/backends/bevy_picking_egui/src/lib.rs @@ -80,7 +80,7 @@ pub fn egui_picking( { if let NormalizedRenderTarget::Window(id) = location.target { if let Ok((entity, mut ctx)) = egui_context.get_mut(id.entity()) { - if ctx.get_mut().is_pointer_over_area() { + if ctx.get_mut().wants_pointer_input() { let entry = (entity, HitData::new(entity, 0.0, None, None)); let order = 1_000_000f32; // Assume egui should be on top of everything else. output.send(PointerHits::new(*pointer, Vec::from([entry]), order)) diff --git a/examples/egui.rs b/examples/egui.rs index ee5f98cc..443149d3 100644 --- a/examples/egui.rs +++ b/examples/egui.rs @@ -23,10 +23,16 @@ fn main() { .run(); } -fn ui_example(mut egui_contexts: EguiContexts) { +fn ui_example(mut egui_contexts: EguiContexts, mut number: Local) { egui::SidePanel::left("Left").show(egui_contexts.ctx_mut(), |ui| { - ui.heading("Note that you can select a 3d object then click on this side panel without that object being deselected!"); - ui.allocate_rect(ui.available_rect_before_wrap(), egui::Sense::hover()); + ScrollArea::vertical() + .auto_shrink([false; 2]) + .show(ui, |ui| { + ui.heading("Note that while a slider is being dragged, the panel is being resized, or the scrollbar is being moved, items in the 3d scene cannot be picked even if the mouse is over them."); + for _ in 0..100 { + ui.add(egui::Slider::new(&mut *number, 0.0..=100.0)); + } + }) }); egui::Window::new("Demo").show(egui_contexts.ctx_mut(), |ui| { ScrollArea::both().auto_shrink([false; 2]).show(ui, |ui| {