exit event loop properly
This commit is contained in:
parent
53f0070f7d
commit
b7da32fe1c
2 changed files with 23 additions and 17 deletions
|
@ -1,6 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ctx::WgpuCtx;
|
||||
|
@ -43,15 +41,16 @@ impl ApplicationHandler for App<'_> {
|
|||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
if let Some(window) = self.windows.remove(&window_id) {
|
||||
let mut window = Arc::into_inner(window);
|
||||
|
||||
let mut window = Arc::into_inner(window);
|
||||
window = None;
|
||||
// _ = window;
|
||||
drop(window);
|
||||
|
||||
event_loop.exit();
|
||||
println!("Window: {:?} closed, exiting", window_id);
|
||||
}
|
||||
if self.windows.is_empty() {
|
||||
event_loop.exit();
|
||||
}
|
||||
// if self.windows.is_empty() {
|
||||
// event_loop.exit();
|
||||
// }
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
device_id,
|
||||
|
@ -76,7 +75,7 @@ impl ApplicationHandler for App<'_> {
|
|||
winit::keyboard::KeyCode::Escape => {
|
||||
debug!("Escape key pressed, spawning new window");
|
||||
let win_attr =
|
||||
Window::default_attributes().with_title("Zenyx - New Window");
|
||||
Window::default_attributes().with_title(format!("Zenyx - New Window {}",self.windows.len()));
|
||||
let new_window = Arc::new(
|
||||
event_loop
|
||||
.create_window(win_attr)
|
||||
|
@ -93,12 +92,19 @@ impl ApplicationHandler for App<'_> {
|
|||
_ => {}
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
for window in self.windows.values() {
|
||||
if let Some(ctx) = &mut self.ctx {
|
||||
ctx.draw();
|
||||
if let Some(ctx) = &mut self.ctx {
|
||||
ctx.draw();
|
||||
}
|
||||
match self.windows.get(&window_id) {
|
||||
Some(window) => {
|
||||
if let Some(ctx) = &mut self.ctx {
|
||||
ctx.draw();
|
||||
}
|
||||
window.request_redraw();
|
||||
}
|
||||
window.request_redraw();
|
||||
None => ()
|
||||
}
|
||||
|
||||
}
|
||||
WindowEvent::Resized(size) => {
|
||||
if let Some(window) = self.windows.get(&window_id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue