1use pathfinder_geometry::vector::Vector2F;
2use std::rc::Rc;
3use std::sync::Arc;
4
5struct App {
6 dispatcher: Arc<dyn super::Dispatcher>,
7 fonts: Arc<dyn super::FontSystem>,
8}
9
10struct Dispatcher;
11
12pub struct Window {
13 size: Vector2F,
14 scale_factor: f32,
15 current_scene: Option<crate::Scene>,
16 event_handlers: Vec<Box<dyn FnMut(super::Event)>>,
17 resize_handlers: Vec<Box<dyn FnMut(&mut dyn super::WindowContext)>>,
18}
19
20pub struct WindowContext {}
21
22impl App {
23 fn new() -> Self {
24 Self {
25 dispatcher: Arc::new(Dispatcher),
26 fonts: Arc::new(super::current::FontSystem::new()),
27 }
28 }
29}
30
31impl super::App for App {
32 fn dispatcher(&self) -> Arc<dyn super::Dispatcher> {
33 self.dispatcher.clone()
34 }
35
36 fn activate(&self, _ignoring_other_apps: bool) {}
37
38 fn open_window(
39 &self,
40 options: super::WindowOptions,
41 _executor: Rc<super::executor::Foreground>,
42 ) -> anyhow::Result<Box<dyn super::Window>> {
43 Ok(Box::new(Window::new(options.bounds.size())))
44 }
45
46 fn fonts(&self) -> std::sync::Arc<dyn super::FontSystem> {
47 self.fonts.clone()
48 }
49
50 fn quit(&self) {}
51}
52
53impl Window {
54 fn new(size: Vector2F) -> Self {
55 Self {
56 size,
57 event_handlers: Vec::new(),
58 resize_handlers: Vec::new(),
59 scale_factor: 1.0,
60 current_scene: None,
61 }
62 }
63}
64
65impl super::Dispatcher for Dispatcher {
66 fn is_main_thread(&self) -> bool {
67 true
68 }
69
70 fn run_on_main_thread(&self, task: async_task::Runnable) {
71 task.run();
72 }
73}
74
75impl super::WindowContext for Window {
76 fn size(&self) -> Vector2F {
77 self.size
78 }
79
80 fn scale_factor(&self) -> f32 {
81 self.scale_factor
82 }
83
84 fn present_scene(&mut self, scene: crate::Scene) {
85 self.current_scene = Some(scene);
86 }
87}
88
89impl super::Window for Window {
90 fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
91 self.event_handlers.push(callback);
92 }
93
94 fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn super::WindowContext)>) {
95 self.resize_handlers.push(callback);
96 }
97}
98
99pub fn app() -> impl super::App {
100 App::new()
101}