mod.rs

 1mod event;
 2#[cfg(target_os = "macos")]
 3pub mod mac;
 4pub mod current {
 5    #[cfg(target_os = "macos")]
 6    pub use super::mac::*;
 7}
 8
 9use crate::{
10    executor,
11    geometry::{rect::RectF, vector::Vector2F},
12    Scene,
13};
14use anyhow::Result;
15use async_task::Runnable;
16pub use event::Event;
17use std::{path::PathBuf, rc::Rc, sync::Arc};
18
19pub trait Runner {
20    fn on_finish_launching<F: 'static + FnOnce()>(self, callback: F) -> Self where;
21    fn on_become_active<F: 'static + FnMut()>(self, callback: F) -> Self;
22    fn on_resign_active<F: 'static + FnMut()>(self, callback: F) -> Self;
23    fn on_event<F: 'static + FnMut(Event) -> bool>(self, callback: F) -> Self;
24    fn on_open_files<F: 'static + FnMut(Vec<PathBuf>)>(self, callback: F) -> Self;
25    fn run(self);
26}
27
28pub trait App {
29    fn dispatcher(&self) -> Arc<dyn Dispatcher>;
30    fn activate(&self, ignoring_other_apps: bool);
31    fn open_window(
32        &self,
33        options: WindowOptions,
34        executor: Rc<executor::Foreground>,
35    ) -> Result<Box<dyn Window>>;
36}
37
38pub trait Dispatcher: Send + Sync {
39    fn is_main_thread(&self) -> bool;
40    fn run_on_main_thread(&self, task: Runnable);
41}
42
43pub trait Window: WindowContext {
44    fn on_event(&mut self, callback: Box<dyn FnMut(Event)>);
45    fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn WindowContext)>);
46}
47
48pub trait WindowContext {
49    fn size(&self) -> Vector2F;
50    fn scale_factor(&self) -> f32;
51    fn present_scene(&mut self, scene: Scene);
52}
53
54pub struct WindowOptions<'a> {
55    pub bounds: RectF,
56    pub title: Option<&'a str>,
57}