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    FontCache, 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        font_cache: Arc<FontCache>,
36    ) -> Result<Box<dyn Window>>;
37}
38
39pub trait Dispatcher: Send + Sync {
40    fn is_main_thread(&self) -> bool;
41    fn run_on_main_thread(&self, task: Runnable);
42}
43
44pub trait Window: WindowContext {
45    fn on_event(&mut self, callback: Box<dyn FnMut(Event)>);
46    fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn WindowContext)>);
47}
48
49pub trait WindowContext {
50    fn size(&self) -> Vector2F;
51    fn scale_factor(&self) -> f32;
52    fn present_scene(&mut self, scene: Scene);
53}
54
55pub struct WindowOptions<'a> {
56    pub bounds: RectF,
57    pub title: Option<&'a str>,
58}