Skip to main content

pebble/rendering/
window_plugin.rs

1use crate::prelude::{Plugin, WindowConfig, WindowResource, WindowRunner};
2
3pub struct WindowPlugin<W: WindowRunner> {
4    pub config: WindowConfig,
5    _marker: std::marker::PhantomData<W>,
6}
7
8impl<W> WindowPlugin<W>
9where
10    W: WindowRunner,
11{
12    pub fn new(config: WindowConfig) -> Self {
13        Self {
14            config,
15            _marker: std::marker::PhantomData,
16        }
17    }
18}
19
20impl<W> Plugin for WindowPlugin<W>
21where
22    W: WindowRunner,
23    W::Handle: 'static + Send + Sync + Clone,
24{
25    fn build(&self, app: &mut crate::prelude::App) {
26        let window_source = W::create(&self.config);
27        let window_handle = window_source.handle().clone();
28
29        app.add_resource(WindowResource::<W> {
30            handle: window_handle,
31        });
32        app.set_runner(move |mut app| {
33            window_source.run(move || app.update());
34        });
35    }
36}