pebble/rendering/
window_plugin.rs1use 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 let window_exposed = window_source.exposed().clone();
29
30 app.add_resource(WindowResource::<W> {
31 handle: window_handle,
32 exposed: window_exposed,
33 });
34 app.set_runner(move |mut app| {
35 window_source.run(move || app.update());
36 });
37 }
38}