diff --git a/crates/bootstrap/src/lib.rs b/crates/bootstrap/src/lib.rs index b417824..3e2fc61 100644 --- a/crates/bootstrap/src/lib.rs +++ b/crates/bootstrap/src/lib.rs @@ -5,7 +5,7 @@ use std::time::Instant; use winit::{ application::ApplicationHandler, - event::WindowEvent, + event::{StartCause, WindowEvent}, event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, }; @@ -97,6 +97,16 @@ impl ApplicationHandler for App { self.window = Some(window); } + fn new_events(&mut self, _event_loop: &ActiveEventLoop, cause: winit::event::StartCause) { + if let Some(app) = self.app.as_mut() { + if cause == StartCause::Init { + app.is_init = true; + } else { + app.is_init = false; + } + } + } + fn window_event( &mut self, event_loop: &ActiveEventLoop, @@ -107,7 +117,7 @@ impl ApplicationHandler for App { .app .as_mut() .unwrap() - .handle_event(&mut self.yak, &event, event_loop) + .handle_window_event(&mut self.yak, &event, event_loop) { return; } diff --git a/crates/demo/src/main.rs b/crates/demo/src/main.rs index 03a7c32..b1e3125 100644 --- a/crates/demo/src/main.rs +++ b/crates/demo/src/main.rs @@ -1,5 +1,5 @@ use winit::{ - event::{Event, WindowEvent}, + event::{Event, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::Window, }; @@ -30,6 +30,14 @@ async fn run(event_loop: EventLoop<()>, window: Window) { window.request_redraw(); } + Event::NewEvents(cause) => { + if cause == StartCause::Init { + graphics.is_init = true; + } else { + graphics.is_init = false; + } + } + Event::WindowEvent { event: WindowEvent::RedrawRequested { .. }, .. @@ -42,7 +50,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { } Event::WindowEvent { event, .. } => { - if graphics.handle_event(&mut yak, &event, event_loop) { + if graphics.handle_window_event(&mut yak, &event, event_loop) { return; } } diff --git a/crates/yakui-app/src/lib.rs b/crates/yakui-app/src/lib.rs index fdf9313..2ff7ee7 100644 --- a/crates/yakui-app/src/lib.rs +++ b/crates/yakui-app/src/lib.rs @@ -18,10 +18,8 @@ pub struct Graphics { window: yakui_winit::YakuiWinit, pub renderer: yakui_wgpu::YakuiWgpu, - /* /// Tracks whether winit is still initializing - is_init: bool, - */ + pub is_init: bool, } impl Graphics { @@ -106,7 +104,7 @@ impl Graphics { renderer, window, - /*is_init: true,*/ + is_init: true, } } @@ -179,7 +177,7 @@ impl Graphics { output.present(); } - pub fn handle_event( + pub fn handle_window_event( &mut self, yak: &mut yakui::Yakui, event: &WindowEvent, @@ -188,7 +186,7 @@ impl Graphics { // yakui_winit will return whether it handled an event. This means that // yakui believes it should handle that event exclusively, like if a // button in the UI was clicked. - if self.window.handle_event(yak, event) { + if self.window.handle_window_event(yak, event) { return true; } @@ -203,9 +201,9 @@ impl Graphics { // and causing issues. // // https://github.com/rust-windowing/winit/issues/2094 - /*if self.is_init { + if self.is_init { return false; - }*/ + } self.resize(*size); } diff --git a/crates/yakui-winit/src/lib.rs b/crates/yakui-winit/src/lib.rs index f68c704..2a20193 100644 --- a/crates/yakui-winit/src/lib.rs +++ b/crates/yakui-winit/src/lib.rs @@ -50,7 +50,11 @@ impl YakuiWinit { self.auto_viewport = enabled; } - pub fn handle_event(&mut self, state: &mut yakui_core::Yakui, event: &WindowEvent) -> bool { + pub fn handle_window_event( + &mut self, + state: &mut yakui_core::Yakui, + event: &WindowEvent, + ) -> bool { if let Some(init) = self.init.take() { let size = Vec2::new(init.size.width as f32, init.size.height as f32); state.set_surface_size(size);