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
@ -64,6 +64,7 @@ pub struct Window {
|
|||||||
cursor_visible: bool,
|
cursor_visible: bool,
|
||||||
cursor_locked: bool,
|
cursor_locked: bool,
|
||||||
cursor_position: Option<Vec2>,
|
cursor_position: Option<Vec2>,
|
||||||
|
focused: bool,
|
||||||
mode: WindowMode,
|
mode: WindowMode,
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub canvas: Option<String>,
|
pub canvas: Option<String>,
|
||||||
@ -152,6 +153,7 @@ impl Window {
|
|||||||
cursor_visible: window_descriptor.cursor_visible,
|
cursor_visible: window_descriptor.cursor_visible,
|
||||||
cursor_locked: window_descriptor.cursor_locked,
|
cursor_locked: window_descriptor.cursor_locked,
|
||||||
cursor_position: None,
|
cursor_position: None,
|
||||||
|
focused: true,
|
||||||
mode: window_descriptor.mode,
|
mode: window_descriptor.mode,
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
canvas: window_descriptor.canvas.clone(),
|
canvas: window_descriptor.canvas.clone(),
|
||||||
@ -395,6 +397,12 @@ impl Window {
|
|||||||
.push(WindowCommand::SetCursorPosition { position });
|
.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)]
|
#[allow(missing_docs)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_cursor_position_from_backend(&mut self, cursor_position: Option<Vec2>) {
|
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> + '_ {
|
pub fn drain_commands(&mut self) -> impl Iterator<Item = WindowCommand> + '_ {
|
||||||
self.command_queue.drain(..)
|
self.command_queue.drain(..)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_focused(&self) -> bool {
|
||||||
|
self.focused
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -407,6 +407,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
WindowEvent::Focused(focused) => {
|
WindowEvent::Focused(focused) => {
|
||||||
|
window.update_focused_status_from_backend(focused);
|
||||||
let mut focused_events =
|
let mut focused_events =
|
||||||
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
||||||
focused_events.send(WindowFocused {
|
focused_events.send(WindowFocused {
|
||||||
|
Loading…
Reference in New Issue
Block a user