mod events; mod keystroke; #[cfg(target_os = "macos")] mod mac; #[cfg(any(test, feature = "test"))] mod test; use crate::{ AnyWindowHandle, Bounds, FontFeatures, FontId, FontMetrics, FontStyle, FontWeight, GlyphId, LineLayout, Pixels, Point, RunStyle, SharedString, Size, }; use async_task::Runnable; use futures::channel::oneshot; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use std::{any::Any, fmt::Debug, ops::Range, rc::Rc, sync::Arc}; use uuid::Uuid; pub use events::*; pub use keystroke::*; #[cfg(target_os = "macos")] pub use mac::*; #[cfg(any(test, feature = "test"))] pub use test::*; pub trait Platform { fn dispatcher(&self) -> Arc; fn font_system(&self) -> Arc; fn open_window( &self, handle: AnyWindowHandle, options: WindowOptions, ) -> Box; } pub trait PlatformScreen: Debug { fn as_any(&self) -> &dyn Any; fn bounds(&self) -> Bounds; fn content_bounds(&self) -> Bounds; fn display_uuid(&self) -> Option; } pub trait PlatformWindow: HasRawWindowHandle + HasRawDisplayHandle { fn bounds(&self) -> WindowBounds; fn content_size(&self) -> Size; fn scale_factor(&self) -> f32; fn titlebar_height(&self) -> Pixels; fn appearance(&self) -> WindowAppearance; fn screen(&self) -> Rc; fn mouse_position(&self) -> Point; fn as_any_mut(&mut self) -> &mut dyn Any; fn set_input_handler(&mut self, input_handler: Box); fn prompt( &self, level: WindowPromptLevel, msg: &str, answers: &[&str], ) -> oneshot::Receiver; fn activate(&self); fn set_title(&mut self, title: &str); fn set_edited(&mut self, edited: bool); fn show_character_palette(&self); fn minimize(&self); fn zoom(&self); fn toggle_full_screen(&self); fn on_event(&mut self, callback: Box bool>); fn on_active_status_change(&mut self, callback: Box); fn on_resize(&mut self, callback: Box); fn on_fullscreen(&mut self, callback: Box); fn on_moved(&mut self, callback: Box); fn on_should_close(&mut self, callback: Box bool>); fn on_close(&mut self, callback: Box); fn on_appearance_changed(&mut self, callback: Box); fn is_topmost_for_position(&self, position: Point) -> bool; } pub trait PlatformDispatcher: Send + Sync { fn is_main_thread(&self) -> bool; fn run_on_main_thread(&self, task: Runnable); } pub trait PlatformTextSystem: Send + Sync { fn add_fonts(&self, fonts: &[Arc>]) -> anyhow::Result<()>; fn all_families(&self) -> Vec; fn load_family(&self, name: &str, features: &FontFeatures) -> anyhow::Result>; fn select_font( &self, font_ids: &[FontId], weight: FontWeight, style: FontStyle, ) -> anyhow::Result; fn font_metrics(&self, font_id: FontId) -> FontMetrics; fn typographic_bounds( &self, font_id: FontId, glyph_id: GlyphId, ) -> anyhow::Result>; fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> anyhow::Result>; fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option; fn rasterize_glyph( &self, font_id: FontId, font_size: f32, glyph_id: GlyphId, subpixel_shift: Point, scale_factor: f32, options: RasterizationOptions, ) -> Option<(Bounds, Vec)>; fn layout_line(&self, text: &str, font_size: Pixels, runs: &[(usize, RunStyle)]) -> LineLayout; fn wrap_line( &self, text: &str, font_id: FontId, font_size: Pixels, width: Pixels, ) -> Vec; } pub trait InputHandler { fn selected_text_range(&self) -> Option>; fn marked_text_range(&self) -> Option>; fn text_for_range(&self, range_utf16: Range) -> Option; fn replace_text_in_range(&mut self, replacement_range: Option>, text: &str); fn replace_and_mark_text_in_range( &mut self, range_utf16: Option>, new_text: &str, new_selected_range: Option>, ); fn unmark_text(&mut self); fn bounds_for_range(&self, range_utf16: Range) -> Option>; } #[derive(Copy, Clone, Debug)] pub enum RasterizationOptions { Alpha, Bgra, } #[derive(Debug)] pub struct WindowOptions { pub bounds: WindowBounds, pub titlebar: Option, pub center: bool, pub focus: bool, pub show: bool, pub kind: WindowKind, pub is_movable: bool, pub screen: Option>, } impl Default for WindowOptions { fn default() -> Self { Self { bounds: WindowBounds::default(), titlebar: Some(TitlebarOptions { title: Default::default(), appears_transparent: Default::default(), traffic_light_position: Default::default(), }), center: false, focus: true, show: true, kind: WindowKind::Normal, is_movable: true, screen: None, } } } #[derive(Debug, Default)] pub struct TitlebarOptions { pub title: Option, pub appears_transparent: bool, pub traffic_light_position: Option>, } #[derive(Copy, Clone, Debug)] pub enum Appearance { Light, VibrantLight, Dark, VibrantDark, } impl Default for Appearance { fn default() -> Self { Self::Light } } #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum WindowKind { Normal, PopUp, } #[derive(Copy, Clone, Debug, PartialEq, Default)] pub enum WindowBounds { Fullscreen, #[default] Maximized, Fixed(Bounds), } #[derive(Copy, Clone, Debug)] pub enum WindowAppearance { Light, VibrantLight, Dark, VibrantDark, } impl Default for WindowAppearance { fn default() -> Self { Self::Light } } #[derive(Copy, Clone, Debug, PartialEq, Default)] pub enum WindowPromptLevel { #[default] Info, Warning, Critical, }