test.rs

  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
 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)>) {}
 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        options: super::WindowOptions,
 57        _executor: Rc<super::executor::Foreground>,
 58    ) -> anyhow::Result<Box<dyn super::Window>> {
 59        Ok(Box::new(Window::new(options.bounds.size())))
 60    }
 61
 62    fn set_menus(&self, _menus: &[crate::Menu]) {}
 63
 64    fn quit(&self) {}
 65
 66    fn prompt_for_paths(&self, _: super::PathPromptOptions) -> Option<Vec<std::path::PathBuf>> {
 67        None
 68    }
 69
 70    fn copy(&self, _: &str) {}
 71}
 72
 73impl Window {
 74    fn new(size: Vector2F) -> Self {
 75        Self {
 76            size,
 77            event_handlers: Vec::new(),
 78            resize_handlers: Vec::new(),
 79            scale_factor: 1.0,
 80            current_scene: None,
 81        }
 82    }
 83}
 84
 85impl super::Dispatcher for Dispatcher {
 86    fn is_main_thread(&self) -> bool {
 87        true
 88    }
 89
 90    fn run_on_main_thread(&self, task: async_task::Runnable) {
 91        task.run();
 92    }
 93}
 94
 95impl super::WindowContext for Window {
 96    fn size(&self) -> Vector2F {
 97        self.size
 98    }
 99
100    fn scale_factor(&self) -> f32 {
101        self.scale_factor
102    }
103
104    fn present_scene(&mut self, scene: crate::Scene) {
105        self.current_scene = Some(scene);
106    }
107}
108
109impl super::Window for Window {
110    fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
111        self.event_handlers.push(callback);
112    }
113
114    fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn super::WindowContext)>) {
115        self.resize_handlers.push(callback);
116    }
117}
118
119pub fn platform() -> impl super::Platform {
120    Platform::new()
121}