Skip to content

Commit

Permalink
revert removal of is_init bugfix and rename handle_event to handle_wi…
Browse files Browse the repository at this point in the history
…ndow_event
  • Loading branch information
msparkles committed Jun 29, 2024
1 parent 02bf8cb commit 939f78c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
14 changes: 12 additions & 2 deletions crates/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Instant;

use winit::{
application::ApplicationHandler,
event::WindowEvent,
event::{StartCause, WindowEvent},
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
};

Expand Down Expand Up @@ -97,6 +97,16 @@ impl<T: ExampleBody> ApplicationHandler for App<T> {
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,
Expand All @@ -107,7 +117,7 @@ impl<T: ExampleBody> ApplicationHandler for App<T> {
.app
.as_mut()
.unwrap()
.handle_event(&mut self.yak, &event, event_loop)
.handle_window_event(&mut self.yak, &event, event_loop)
{
return;
}
Expand Down
12 changes: 10 additions & 2 deletions crates/demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winit::{
event::{Event, WindowEvent},
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::Window,
};
Expand Down Expand Up @@ -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 { .. },
..
Expand All @@ -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;
}
}
Expand Down
14 changes: 6 additions & 8 deletions crates/yakui-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -106,7 +104,7 @@ impl Graphics {

renderer,
window,
/*is_init: true,*/
is_init: true,
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion crates/yakui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 939f78c

Please sign in to comment.