Skip to content

Commit

Permalink
Stop tracking previous frame's 'wants focus' value for egui
Browse files Browse the repository at this point in the history
This is no longer needed - presumably the issue was fixed upstream.
  • Loading branch information
Plonq committed Dec 26, 2023
1 parent 37f77ec commit b5915db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
22 changes: 4 additions & 18 deletions src/egui.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
use bevy::prelude::*;

/// A resource that tracks whether egui wants focus on the current and previous frames.
/// A resource that tracks whether egui wants focus, i.e. user is interacting with egui.
///
/// The reason the previous frame's value is saved is because when you click inside an
/// egui window, Context::wants_pointer_input() still returns false once before returning
/// true. If the camera stops taking input only when it returns false, there's one frame
/// where both egui and the camera are using the input events, which is not desirable.
///
/// This is re-exported in case it's useful. I recommend only using input events if both
/// `prev` and `curr` are false.
/// This is re-exported in case it's useful.
#[derive(Resource, PartialEq, Eq, Default)]
pub struct EguiWantsFocus {
/// Whether egui wanted focus on the previous frame
pub prev: bool,
/// Whether egui wants focus on the current frame
pub curr: bool,
}
pub struct EguiWantsFocus(pub bool);

pub fn check_egui_wants_focus(
mut contexts: bevy_egui::EguiContexts,
Expand All @@ -30,9 +19,6 @@ pub fn check_egui_wants_focus(
let ctx = contexts.ctx_for_window_mut(window);
ctx.wants_pointer_input() || ctx.wants_keyboard_input()
});
let new_res = EguiWantsFocus {
prev: wants_focus.curr,
curr: new_wants_focus,
};
let new_res = EguiWantsFocus(new_wants_focus);
wants_focus.set_if_neq(new_res);
}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ impl Plugin for PanOrbitCameraPlugin {
)
.configure_sets(
Update,
PanOrbitCameraSystemSet.run_if(resource_equals(EguiWantsFocus {
prev: false,
curr: false,
})),
PanOrbitCameraSystemSet.run_if(resource_equals(EguiWantsFocus(false))),
);
}
}
Expand Down

0 comments on commit b5915db

Please sign in to comment.