Add a lot of thing
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-15 13:59:19 +01:00
parent 09e109d6ef
commit fb4ac29c07
6 changed files with 255 additions and 43 deletions

View file

@ -1,9 +1,9 @@
use crate::display::window::Window;
use crate::vulkan::VkRenderContext;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop;
use winit::window::{WindowId};
use crate::display::window::Window;
use crate::vulkan::VkRenderContext;
use winit::window::WindowId;
pub struct App {
window: Window,
@ -34,7 +34,29 @@ impl ApplicationHandler for App {
log::debug!("The close button was pressed; stopping");
event_loop.exit();
}
_ => self.window.window_event(event_loop, id, event),
WindowEvent::Resized(size) => {
match self.render_context.as_mut() {
Some(render_context) => {
if let Err(error) = render_context.update_resolution(size.width, size.height) {
log::error!("Failed to update resolution of render context : {}", error);
}
}
None => log::warn!("Window resized but no render context found")
};
}
WindowEvent::RedrawRequested => {
match self.render_context.as_mut() {
Some(render_context) => {
if let Err(error) = render_context.render() {
log::error!("Failed to render with render context : {}", error);
}
}
None => log::warn!("Window resized but no render context found")
};
self.window.request_redraw();
}
_ => {}
}
}
}

View file

@ -6,7 +6,7 @@ use winit::window::WindowId;
pub struct Window {
handle: Option<winit::window::Window>,
window_attributes: winit::window::WindowAttributes
window_attributes: winit::window::WindowAttributes,
}
impl Window {
@ -49,20 +49,15 @@ impl Window {
pub fn handle(&self) -> Option<&winit::window::Window> {
self.handle.as_ref()
}
pub fn size(&self) -> Option<winit::dpi::Size> {
self.window_attributes.inner_size
}
pub fn window_event(&mut self, _event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
match event {
WindowEvent::RedrawRequested => {
match self.handle.as_ref() {
Some(window) => window.request_redraw(),
None => log::warn!("Redraw requested but no window found")
}
}
_ => (),
pub fn request_redraw(&self) {
match self.handle.as_ref() {
Some(window) => window.request_redraw(),
None => log::warn!("Redraw requested but no window found")
}
}
}