pebble/rendering/
window_plugin.rs1use crate::prelude::{Plugin, WindowConfig, WindowResource, WindowRunner};
2
3pub struct WindowPlugin<W: WindowRunner> {
10 pub config: WindowConfig,
11 _marker: std::marker::PhantomData<W>,
12}
13
14impl<W> WindowPlugin<W>
15where
16 W: WindowRunner,
17{
18 pub fn new(config: WindowConfig) -> Self {
19 Self {
20 config,
21 _marker: std::marker::PhantomData,
22 }
23 }
24}
25
26impl<W> Plugin for WindowPlugin<W>
27where
28 W: WindowRunner,
29 W::Handle: 'static + Send + Sync + Clone,
30{
31 fn build(&self, app: &mut crate::prelude::App) {
32 let window_source = W::create(&self.config);
33 let window_handle = window_source.handle().clone();
34 let window_exposed = window_source.exposed().clone();
35
36 app.add_resource(WindowResource::<W> {
37 handle: window_handle,
38 exposed: window_exposed,
39 });
40 app.set_runner(move |mut app| {
41 window_source.run(move || app.update());
42 });
43 }
44}