1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::marker::PhantomData;
use crate::internal_prelude::*;
use crate::config::ScreenMetrics;
use crate::node::Buildable;
use crate::window::Window;
pub struct Builder<R: Buildable> {
pub(crate) sandbox: Weak<Sandbox>,
_phantom: PhantomData<R>,
}
#[derive(Clone)]
pub struct Sandbox {
screen_metrics: ScreenMetrics,
window: Arc<Window>,
}
impl Sandbox {
pub fn new(screen_metrics: ScreenMetrics) -> Arc<Sandbox> {
Arc::new_cyclic(|sandbox_weak| -> Sandbox {
let win = Window::new(sandbox_weak.clone());
Sandbox {
screen_metrics,
window: win,
}
})
}
pub fn window(&self) -> Arc<Window> {
self.window.clone()
}
pub fn builder<T: Buildable>(self: &Arc<Self>) -> Builder<T> {
Builder {
sandbox: Arc::downgrade(self),
_phantom: PhantomData,
}
}
}