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