vulkano_test/src/core/window/state.rs
Florian RICHER a295093c97
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 25m2s
Use bevy_app instead
2025-04-24 13:05:38 +02:00

45 lines
1.1 KiB
Rust

use std::sync::Arc;
use bevy_app::App;
use bevy_ecs::world::World;
use winit::{
application::ApplicationHandler, event::WindowEvent, event_loop::ActiveEventLoop,
window::WindowId,
};
use super::{config::WindowConfig, raw_handle::WindowWrapper};
pub struct WindowState {
app: App,
}
impl WindowState {
pub fn new(app: App) -> Self {
Self { app }
}
fn world(&self) -> &World {
self.app.world()
}
}
impl ApplicationHandler for WindowState {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let window_config = self.world().get_resource::<WindowConfig>().unwrap();
let window = event_loop.create_window(window_config.into()).unwrap();
self.app
.world_mut()
.insert_resource(WindowWrapper(Arc::new(window)));
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
log::debug!("The close button was pressed; stopping");
event_loop.exit();
}
_ => {}
}
}
}