1use pathfinder_geometry::vector::Vector2F;
2use std::rc::Rc;
3use std::sync::Arc;
4
5struct Platform {
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 Platform {
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::Platform for Platform {
32 fn on_menu_command(&self, _: Box<dyn FnMut(&str)>) {}
33
34 fn on_become_active(&self, _: Box<dyn FnMut()>) {}
35
36 fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
37
38 fn on_event(&self, _: Box<dyn FnMut(crate::Event) -> bool>) {}
39
40 fn on_open_files(&self, _: Box<dyn FnMut(Vec<std::path::PathBuf>)>) {}
41
42 fn run(&self, _on_finish_launching: Box<dyn FnOnce() -> ()>) {
43 unimplemented!()
44 }
45
46 fn dispatcher(&self) -> Arc<dyn super::Dispatcher> {
47 self.dispatcher.clone()
48 }
49
50 fn fonts(&self) -> std::sync::Arc<dyn super::FontSystem> {
51 self.fonts.clone()
52 }
53
54 fn activate(&self, _ignoring_other_apps: bool) {}
55
56 fn open_window(
57 &self,
58 options: super::WindowOptions,
59 _executor: Rc<super::executor::Foreground>,
60 ) -> anyhow::Result<Box<dyn super::Window>> {
61 Ok(Box::new(Window::new(options.bounds.size())))
62 }
63
64 fn set_menus(&self, _menus: &[crate::Menu]) {}
65
66 fn quit(&self) {}
67
68 fn prompt_for_paths(&self, _: super::PathPromptOptions) -> Option<Vec<std::path::PathBuf>> {
69 None
70 }
71
72 fn copy(&self, _: &str) {}
73}
74
75impl Window {
76 fn new(size: Vector2F) -> Self {
77 Self {
78 size,
79 event_handlers: Vec::new(),
80 resize_handlers: Vec::new(),
81 scale_factor: 1.0,
82 current_scene: None,
83 }
84 }
85}
86
87impl super::Dispatcher for Dispatcher {
88 fn is_main_thread(&self) -> bool {
89 true
90 }
91
92 fn run_on_main_thread(&self, task: async_task::Runnable) {
93 task.run();
94 }
95}
96
97impl super::WindowContext for Window {
98 fn size(&self) -> Vector2F {
99 self.size
100 }
101
102 fn scale_factor(&self) -> f32 {
103 self.scale_factor
104 }
105
106 fn present_scene(&mut self, scene: crate::Scene) {
107 self.current_scene = Some(scene);
108 }
109}
110
111impl super::Window for Window {
112 fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
113 self.event_handlers.push(callback);
114 }
115
116 fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn super::WindowContext)>) {
117 self.resize_handlers.push(callback);
118 }
119}
120
121pub fn platform() -> impl super::Platform {
122 Platform::new()
123}