From b5915db2cbc873067f97b5e61dc0be2b9dfb59ef Mon Sep 17 00:00:00 2001 From: Huon Imberger Date: Wed, 27 Dec 2023 09:22:43 +1100 Subject: [PATCH] Stop tracking previous frame's 'wants focus' value for egui This is no longer needed - presumably the issue was fixed upstream. --- src/egui.rs | 22 ++++------------------ src/lib.rs | 5 +---- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/egui.rs b/src/egui.rs index 8dffe8c..425b2e8 100644 --- a/src/egui.rs +++ b/src/egui.rs @@ -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, @@ -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); } diff --git a/src/lib.rs b/src/lib.rs index cd1f6ff..bc5e426 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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))), ); } }