Update
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Has been cancelled

This commit is contained in:
Florian RICHER 2025-04-13 16:35:21 +02:00
parent b361965033
commit f4694157ab
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
8 changed files with 143 additions and 3 deletions

24
src/core/window/mod.rs Normal file
View file

@ -0,0 +1,24 @@
pub mod window_handler;
use super::app::{App, plugin::Plugin};
use window_handler::WindowHandler;
use winit::event_loop::EventLoop;
use winit::window::WindowAttributes;
pub struct WindowPlugin {
window_attributes: WindowAttributes,
event_loop: EventLoop<()>,
}
impl Plugin for WindowPlugin {
fn build(&self, app: &mut App) {
let world = app.world_mut();
world.insert_resource(WindowHandler::new(self.window_attributes.clone()));
let window_handler = world.get_resource_mut::<WindowHandler>().unwrap();
// app.set_runner(Box::new(move || {
// self.event_loop.run_app(&mut window_handler);
// }));
}
}

View file

@ -0,0 +1,40 @@
use bevy_ecs::system::Resource;
use winit::{
application::ApplicationHandler,
event::WindowEvent,
event_loop::ActiveEventLoop,
window::{Window, WindowAttributes, WindowId},
};
#[derive(Resource)]
pub struct WindowHandler {
window_attributes: WindowAttributes,
window: Option<Box<Window>>,
}
impl WindowHandler {
pub fn new(window_attributes: WindowAttributes) -> Self {
Self {
window_attributes,
window: None,
}
}
}
impl ApplicationHandler for WindowHandler {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let window = event_loop
.create_window(self.window_attributes.clone())
.unwrap();
self.window = Some(Box::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();
}
_ => {}
}
}
}