Skip to content

Commit

Permalink
improve egui backend
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Oct 27, 2023
1 parent 4a6db69 commit 05d1612
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ entity, and works with mouse, touch, or even gamepads.
- ***Lightweight***: only compile what you need.
- ***Expressive***: event listener components `On::<Pointer<Click>>::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,
Expand Down Expand Up @@ -50,12 +51,14 @@ commands.spawn((
// Send an event when the pointer is pressed over this entity:
On::<Pointer<Down>>::send_event::<DoSomethingComplex>(),
));

```

If you don't need event bubbling or callbacks, you can respond to pointer events like you would any
other bevy event, using `EventReader<Pointer<Click>>`, `EventReader<Pointer<Move>>`, 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
Expand All @@ -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

Expand Down Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion backends/bevy_picking_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 9 additions & 3 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ fn main() {
.run();
}

fn ui_example(mut egui_contexts: EguiContexts) {
fn ui_example(mut egui_contexts: EguiContexts, mut number: Local<f32>) {
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| {
Expand Down

0 comments on commit 05d1612

Please sign in to comment.