2021-02-20 17:02:34 +00:00
|
|
|
mod event;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
pub mod mac;
|
2021-03-31 23:59:03 +00:00
|
|
|
pub mod test;
|
2021-02-20 17:02:34 +00:00
|
|
|
pub mod current {
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
pub use super::mac::*;
|
|
|
|
}
|
|
|
|
|
2021-03-19 03:33:16 +00:00
|
|
|
use crate::{
|
|
|
|
executor,
|
2021-03-25 09:58:33 +00:00
|
|
|
fonts::{FontId, GlyphId, Metrics as FontMetrics, Properties as FontProperties},
|
2021-03-24 15:51:28 +00:00
|
|
|
geometry::{
|
|
|
|
rect::{RectF, RectI},
|
|
|
|
vector::Vector2F,
|
|
|
|
},
|
|
|
|
text_layout::Line,
|
2021-04-08 22:56:21 +00:00
|
|
|
Menu, Scene,
|
2021-03-19 03:33:16 +00:00
|
|
|
};
|
2021-02-20 23:05:36 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use async_task::Runnable;
|
2021-03-10 04:00:51 +00:00
|
|
|
pub use event::Event;
|
2021-03-24 15:51:28 +00:00
|
|
|
use std::{ops::Range, path::PathBuf, rc::Rc, sync::Arc};
|
2021-02-20 17:02:34 +00:00
|
|
|
|
2021-04-09 19:03:26 +00:00
|
|
|
pub trait Platform {
|
|
|
|
fn on_menu_command(&self, callback: Box<dyn FnMut(&str)>);
|
|
|
|
fn on_become_active(&self, callback: Box<dyn FnMut()>);
|
|
|
|
fn on_resign_active(&self, callback: Box<dyn FnMut()>);
|
|
|
|
fn on_event(&self, callback: Box<dyn FnMut(Event) -> bool>);
|
|
|
|
fn on_open_files(&self, callback: Box<dyn FnMut(Vec<PathBuf>)>);
|
2021-04-10 03:33:17 +00:00
|
|
|
fn run(&self, on_finish_launching: Box<dyn FnOnce() -> ()>);
|
2021-04-09 19:03:26 +00:00
|
|
|
|
2021-02-20 23:05:36 +00:00
|
|
|
fn dispatcher(&self) -> Arc<dyn Dispatcher>;
|
2021-04-09 19:03:26 +00:00
|
|
|
fn fonts(&self) -> Arc<dyn FontSystem>;
|
|
|
|
|
2021-02-20 23:05:36 +00:00
|
|
|
fn activate(&self, ignoring_other_apps: bool);
|
|
|
|
fn open_window(
|
|
|
|
&self,
|
|
|
|
options: WindowOptions,
|
|
|
|
executor: Rc<executor::Foreground>,
|
2021-03-21 04:15:04 +00:00
|
|
|
) -> Result<Box<dyn Window>>;
|
2021-04-09 05:25:54 +00:00
|
|
|
fn prompt_for_paths(&self, options: PathPromptOptions) -> Option<Vec<PathBuf>>;
|
2021-04-08 22:56:21 +00:00
|
|
|
fn quit(&self);
|
2021-04-08 03:54:05 +00:00
|
|
|
fn copy(&self, text: &str);
|
2021-04-09 19:03:26 +00:00
|
|
|
fn set_menus(&self, menus: &[Menu]);
|
2021-02-20 23:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Dispatcher: Send + Sync {
|
|
|
|
fn is_main_thread(&self) -> bool;
|
|
|
|
fn run_on_main_thread(&self, task: Runnable);
|
|
|
|
}
|
|
|
|
|
2021-03-21 04:15:04 +00:00
|
|
|
pub trait Window: WindowContext {
|
2021-03-21 17:38:23 +00:00
|
|
|
fn on_event(&mut self, callback: Box<dyn FnMut(Event)>);
|
2021-03-21 04:15:04 +00:00
|
|
|
fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn WindowContext)>);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait WindowContext {
|
2021-03-19 03:33:16 +00:00
|
|
|
fn size(&self) -> Vector2F;
|
|
|
|
fn scale_factor(&self) -> f32;
|
2021-03-21 04:15:04 +00:00
|
|
|
fn present_scene(&mut self, scene: Scene);
|
2021-03-19 03:33:16 +00:00
|
|
|
}
|
2021-02-20 23:05:36 +00:00
|
|
|
|
|
|
|
pub struct WindowOptions<'a> {
|
|
|
|
pub bounds: RectF,
|
|
|
|
pub title: Option<&'a str>,
|
|
|
|
}
|
2021-03-24 15:51:28 +00:00
|
|
|
|
2021-04-09 05:25:54 +00:00
|
|
|
pub struct PathPromptOptions {
|
|
|
|
pub files: bool,
|
|
|
|
pub directories: bool,
|
|
|
|
pub multiple: bool,
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:51:28 +00:00
|
|
|
pub trait FontSystem: Send + Sync {
|
|
|
|
fn load_family(&self, name: &str) -> anyhow::Result<Vec<FontId>>;
|
|
|
|
fn select_font(
|
|
|
|
&self,
|
|
|
|
font_ids: &[FontId],
|
|
|
|
properties: &FontProperties,
|
|
|
|
) -> anyhow::Result<FontId>;
|
|
|
|
fn font_metrics(&self, font_id: FontId) -> FontMetrics;
|
|
|
|
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> anyhow::Result<RectF>;
|
|
|
|
fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>;
|
|
|
|
fn rasterize_glyph(
|
|
|
|
&self,
|
|
|
|
font_id: FontId,
|
|
|
|
font_size: f32,
|
|
|
|
glyph_id: GlyphId,
|
2021-03-24 17:35:48 +00:00
|
|
|
subpixel_shift: Vector2F,
|
2021-03-24 15:51:28 +00:00
|
|
|
scale_factor: f32,
|
|
|
|
) -> Option<(RectI, Vec<u8>)>;
|
|
|
|
fn layout_str(&self, text: &str, font_size: f32, runs: &[(Range<usize>, FontId)]) -> Line;
|
|
|
|
}
|