use winit::{
event::{WindowEvent},
event_loop::EventLoop,
window::Window
};
use winit::application::ApplicationHandler;
use winit::event_loop::{ActiveEventLoop, ControlFlow};
use winit::window::WindowId;
#[derive(Debug)]
pub struct Application {
title: Option<Box<str>>,
application_id: Option<Box<str>>,
window: Option<Box<dyn Window>>
}
pub fn application() -> Application {
Application {
title: None,
application_id: None,
window: None,
}
}
impl Application {
pub fn title(mut self, title: Box<str>) -> Self {
self.title = Some(title);
self
}
pub fn application_id(mut self, id: Box<str>) -> Self {
self.application_id = Some(id);
self
}
pub fn run(self) -> Result<(), winit::error::EventLoopError> {
let event_loop = EventLoop::new()?;
event_loop.set_control_flow(ControlFlow::Wait);
event_loop.run_app(self)
}
}
impl ApplicationHandler for Application {
fn resumed(&mut self, event_loop: &dyn ActiveEventLoop) {
todo!()
}
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
todo!()
}
fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, window_id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
println!("The close button was pressed; stopping");
event_loop.exit();
},
WindowEvent::RedrawRequested => {
self.window.as_ref().unwrap().request_redraw();
}
_ => (),
}
}
}