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