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
51impl Window {
52 fn new(size: Vector2F) -> Self {
53 Self {
54 size,
55 event_handlers: Vec::new(),
56 resize_handlers: Vec::new(),
57 scale_factor: 1.0,
58 current_scene: None,
59 }
60 }
61}
62
63impl super::Dispatcher for Dispatcher {
64 fn is_main_thread(&self) -> bool {
65 true
66 }
67
68 fn run_on_main_thread(&self, task: async_task::Runnable) {
69 task.run();
70 }
71}
72
73impl super::WindowContext for Window {
74 fn size(&self) -> Vector2F {
75 self.size
76 }
77
78 fn scale_factor(&self) -> f32 {
79 self.scale_factor
80 }
81
82 fn present_scene(&mut self, scene: crate::Scene) {
83 self.current_scene = Some(scene);
84 }
85}
86
87impl super::Window for Window {
88 fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
89 self.event_handlers.push(callback);
90 }
91
92 fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn super::WindowContext)>) {
93 self.resize_handlers.push(callback);
94 }
95}
96
97pub fn app() -> impl super::App {
98 App::new()
99}