kludgine_app/
application.rs1use std::marker::PhantomData;
2
3use crate::runtime::Runtime;
4use crate::window::{RuntimeWindow, Window, WindowCreator};
5
6pub trait Application: Sized + Send + Sync {
8 fn initialize(&mut self) {}
10
11 fn should_exit(&mut self) -> bool {
14 Self::open_window_count() == 0
15 }
16
17 #[must_use]
19 fn open_window_count() -> usize {
20 RuntimeWindow::count()
21 }
22}
23
24pub struct SingleWindowApplication<T> {
30 phantom: PhantomData<T>,
31}
32
33impl<T> Application for SingleWindowApplication<T> where T: Window + WindowCreator + 'static {}
34
35impl<T> SingleWindowApplication<T>
36where
37 T: Window + WindowCreator + 'static,
38{
39 pub fn run(window: T) -> ! {
41 let app = Self {
42 phantom: PhantomData::default(),
43 };
44 Runtime::new(app).run(window.get_window_builder(), window)
45 }
46}