Add event handler methods to the engine structure

This commit is contained in:
reo 2025-09-18 00:32:12 +03:00
parent c32a452f17
commit 9905ffd26b
5 changed files with 29 additions and 25 deletions

View file

@ -18,27 +18,16 @@ const MAIN_SCENE_ID: &str = "main_scene";
#[derive(Default)]
struct UpdateAspectRatioSystem;
impl System for UpdateAspectRatioSystem {
fn initialize(&mut self) {}
fn load_world(&mut self, _ctx: &mut SystemContext) {}
fn update(&mut self, ctx: &mut SystemContext) {
// FIXME: Need an event handler rework for systems.
match &ctx.platform_context.current_event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(sz) => {
let _ = ctx
.scene
.world
.query_mut::<&mut Camera>()
.into_iter()
.map(|(_, cam)| {
cam.aspect = sz.width as f32 / sz.height as f32;
});
}
_ => {}
},
_ => {}
fn handle_event(&mut self, ctx: &mut SystemContext) {
if let Event::WindowEvent { event: WindowEvent::Resized(sz), .. } =
&ctx.platform_context.current_event
{
ctx.scene.world
.query_mut::<&mut Camera>()
.into_iter()
.for_each(|(_, cam)| {
cam.aspect = sz.width as f32 / sz.height as f32;
});
}
}
}
@ -73,9 +62,6 @@ impl System for RenderingTestSystem {
}
fn update(&mut self, ctx: &mut SystemContext) {
// if let Some(mut debug_ui) = ctx.platform_context.imgui_ui.as_ref().map(|ui| ui.borrow_mut()) {
// debug_ui.text("Hello World!");
// }
ctx.debug_ui_buffer.borrow_mut().text("Hello World!".to_owned());
}
}