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
78impl Window {
79 fn new(size: Vector2F) -> Self {
80 Self {
81 size,
82 event_handlers: Vec::new(),
83 resize_handlers: Vec::new(),
84 scale_factor: 1.0,
85 current_scene: None,
86 }
87 }
88}
89
90impl super::Dispatcher for Dispatcher {
91 fn is_main_thread(&self) -> bool {
92 true
93 }
94
95 fn run_on_main_thread(&self, task: async_task::Runnable) {
96 task.run();
97 }
98}
99
100impl super::WindowContext for Window {
101 fn size(&self) -> Vector2F {
102 self.size
103 }
104
105 fn scale_factor(&self) -> f32 {
106 self.scale_factor
107 }
108
109 fn present_scene(&mut self, scene: crate::Scene) {
110 self.current_scene = Some(scene);
111 }
112}
113
114impl super::Window for Window {
115 fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
116 self.event_handlers.push(callback);
117 }
118
119 fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn super::WindowContext)>) {
120 self.resize_handlers.push(callback);
121 }
122}
123
124pub fn platform() -> impl super::Platform {
125 Platform::new()
126}