mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
Simple Implementation to address #1327 by adding a focused field to the window and related system (#1386)
* Simple Implementation to address #1327 by adding a focused field to the window and related system * Changing Window update function from bevy_window to bevy_winit. * Removing unused imports.
This commit is contained in:
parent
b39df9a8d2
commit
f8292ccf7e
2 changed files with 14 additions and 0 deletions
|
@ -64,6 +64,7 @@ pub struct Window {
|
|||
cursor_visible: bool,
|
||||
cursor_locked: bool,
|
||||
cursor_position: Option<Vec2>,
|
||||
focused: bool,
|
||||
mode: WindowMode,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub canvas: Option<String>,
|
||||
|
@ -152,6 +153,7 @@ impl Window {
|
|||
cursor_visible: window_descriptor.cursor_visible,
|
||||
cursor_locked: window_descriptor.cursor_locked,
|
||||
cursor_position: None,
|
||||
focused: true,
|
||||
mode: window_descriptor.mode,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
canvas: window_descriptor.canvas.clone(),
|
||||
|
@ -395,6 +397,12 @@ impl Window {
|
|||
.push(WindowCommand::SetCursorPosition { position });
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[inline]
|
||||
pub fn update_focused_status_from_backend(&mut self, focused: bool) {
|
||||
self.focused = focused;
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[inline]
|
||||
pub fn update_cursor_position_from_backend(&mut self, cursor_position: Option<Vec2>) {
|
||||
|
@ -418,6 +426,11 @@ impl Window {
|
|||
pub fn drain_commands(&mut self) -> impl Iterator<Item = WindowCommand> + '_ {
|
||||
self.command_queue.drain(..)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_focused(&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -407,6 +407,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
|
|||
);
|
||||
}
|
||||
WindowEvent::Focused(focused) => {
|
||||
window.update_focused_status_from_backend(focused);
|
||||
let mut focused_events =
|
||||
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
||||
focused_events.send(WindowFocused {
|
||||
|
|
Loading…
Reference in a new issue