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