Skip to content

Commit

Permalink
Re-export EguiWantsFocus resource (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plonq authored Nov 25, 2023
1 parent 5eb7414 commit ebb232a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/egui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use bevy::prelude::{DetectChangesMut, Query, ResMut, Resource};

/// A resource that tracks whether egui wants focus on the current and previous frames.
///
/// 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 true.
#[derive(Resource, PartialEq, Eq, Default)]
pub struct EguiWantsFocus {
// Must track previous value too, because when you click inside an egui window,
// Context::wants_pointer_input() returns false once before returning true again, which
// is undesirable.
/// Whether egui wanted focus on the previous frame
pub prev: bool,
/// Whether egui wants focus on the current frame
pub curr: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy::window::{PrimaryWindow, WindowRef};
#[cfg(feature = "bevy_egui")]
use bevy_egui::EguiSet;
#[cfg(feature = "bevy_egui")]
use egui::EguiWantsFocus;
pub use egui::EguiWantsFocus;
use std::f32::consts::{PI, TAU};

#[cfg(feature = "bevy_egui")]
Expand Down

0 comments on commit ebb232a

Please sign in to comment.