-
Notifications
You must be signed in to change notification settings - Fork 248
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
Drop events on focus #50
base: main
Are you sure you want to change the base?
Conversation
Add a system param input_events_mut, that contains the Events resources directly for event iteration. This allows them to be cleared. Gated behind the drop_events_on_focus feature
The actual only relevant commit is |
This shows an small example app that shows suppression of events, copy this into example/simple.rs, run with:
use bevy::prelude::*;
use bevy_egui::{egui, EguiContext, EguiPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(EguiPlugin)
.add_system(ui_example.system())
.add_system(input_events.system())
.run();
}
fn ui_example(egui_context: Res<EguiContext>) {
egui::Window::new("Hello").show(egui_context.ctx(), |ui| {
ui.label("world");
});
egui::Window::new("Hello2").show(egui_context.ctx(), |ui| {
ui.label("world");
});
}
fn input_events(mut ev_cursor: EventReader<CursorMoved>) {
for event in ev_cursor.iter() {
println!("Mouse move: {:?}", event);
}
} |
Fixes #47 |
One thing I only just thought of, is to leave most of the event consumption code the same in process_input system. And clear the input events in a system just after process_inputs. If you think this PR has merit, I can rework this, so that most of process_input remains unchanged (except for the Input::clone()) |
f454510
to
022ebd1
Compare
Any updates on this? |
879a24b
to
8956b27
Compare
This is a POC of dropping/suppressing of keyboard & mouse events, when the pointer is over any egui windows. Im not really that happy with it, but there is nothing wrong with it per-se, with the current state of bevy.
This is based off of jakobhellerman/bevy_egui#bevy-main, as it also depends on a slightly patched version of bevy:https://github.com/rezural/bevy/tree/input-derive-clone
I have gated it behind the drop_events_on_focus feature (feel free to rename this to something better), as while it is probably handy for bevy_egui consumers to opt into, it makes decisions about when to drop events, which are fairly arbitrary.
In reality, the application itself will probably want to decide which input state it is in (i.e. if there is a mouse pointer, or not), and a host of other concerns that will have to be fleshed out properly in bevy & the larger UI effort. I imagine this will come as a result of the bevy ui effort.