2022-09-14 09:47:43 +00:00
|
|
|
mod appearance;
|
2021-03-30 04:46:26 +00:00
|
|
|
mod atlas;
|
2022-08-30 17:05:33 +00:00
|
|
|
mod dispatcher;
|
2021-02-20 17:02:34 +00:00
|
|
|
mod event;
|
2021-03-24 15:51:28 +00:00
|
|
|
mod fonts;
|
2021-02-20 23:05:36 +00:00
|
|
|
mod geometry;
|
2021-09-14 16:11:59 +00:00
|
|
|
mod image_cache;
|
2021-04-09 19:03:26 +00:00
|
|
|
mod platform;
|
2021-03-20 15:38:36 +00:00
|
|
|
mod renderer;
|
2022-10-26 10:04:45 +00:00
|
|
|
mod screen;
|
2021-03-23 14:15:41 +00:00
|
|
|
mod sprite_cache;
|
2022-09-08 17:07:11 +00:00
|
|
|
mod status_item;
|
2021-02-20 23:05:36 +00:00
|
|
|
mod window;
|
|
|
|
|
2023-01-26 01:05:57 +00:00
|
|
|
use cocoa::{
|
|
|
|
base::{id, nil, BOOL, NO, YES},
|
|
|
|
foundation::{NSAutoreleasePool, NSNotFound, NSString, NSUInteger},
|
|
|
|
};
|
2021-02-20 23:05:36 +00:00
|
|
|
pub use dispatcher::Dispatcher;
|
2021-03-24 15:51:28 +00:00
|
|
|
pub use fonts::FontSystem;
|
2021-06-07 23:42:49 +00:00
|
|
|
use platform::{MacForegroundPlatform, MacPlatform};
|
2022-08-30 16:17:54 +00:00
|
|
|
pub use renderer::Surface;
|
2023-01-26 01:05:57 +00:00
|
|
|
use std::{ops::Range, rc::Rc, sync::Arc};
|
2023-08-08 23:21:06 +00:00
|
|
|
use window::MacWindow;
|
2021-02-20 23:05:36 +00:00
|
|
|
|
2023-02-24 17:39:52 +00:00
|
|
|
use crate::executor;
|
|
|
|
|
2021-06-07 23:35:27 +00:00
|
|
|
pub(crate) fn platform() -> Arc<dyn super::Platform> {
|
|
|
|
Arc::new(MacPlatform::new())
|
2021-02-20 23:05:36 +00:00
|
|
|
}
|
2021-04-02 21:26:53 +00:00
|
|
|
|
2023-02-24 17:39:52 +00:00
|
|
|
pub(crate) fn foreground_platform(
|
|
|
|
foreground: Rc<executor::Foreground>,
|
|
|
|
) -> Rc<dyn super::ForegroundPlatform> {
|
|
|
|
Rc::new(MacForegroundPlatform::new(foreground))
|
2021-06-07 23:42:49 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 23:05:36 +00:00
|
|
|
trait BoolExt {
|
|
|
|
fn to_objc(self) -> BOOL;
|
|
|
|
}
|
2021-02-20 17:02:34 +00:00
|
|
|
|
2021-02-20 23:05:36 +00:00
|
|
|
impl BoolExt for bool {
|
|
|
|
fn to_objc(self) -> BOOL {
|
|
|
|
if self {
|
|
|
|
YES
|
|
|
|
} else {
|
|
|
|
NO
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 17:02:34 +00:00
|
|
|
}
|
2023-01-26 01:05:57 +00:00
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
struct NSRange {
|
|
|
|
pub location: NSUInteger,
|
|
|
|
pub length: NSUInteger,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NSRange {
|
|
|
|
fn invalid() -> Self {
|
|
|
|
Self {
|
|
|
|
location: NSNotFound as NSUInteger,
|
|
|
|
length: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_valid(&self) -> bool {
|
|
|
|
self.location != NSNotFound as NSUInteger
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_range(self) -> Option<Range<usize>> {
|
|
|
|
if self.is_valid() {
|
|
|
|
let start = self.location as usize;
|
|
|
|
let end = start + self.length as usize;
|
|
|
|
Some(start..end)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Range<usize>> for NSRange {
|
|
|
|
fn from(range: Range<usize>) -> Self {
|
|
|
|
NSRange {
|
|
|
|
location: range.start as NSUInteger,
|
|
|
|
length: range.len() as NSUInteger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl objc::Encode for NSRange {
|
|
|
|
fn encode() -> objc::Encoding {
|
|
|
|
let encoding = format!(
|
|
|
|
"{{NSRange={}{}}}",
|
|
|
|
NSUInteger::encode().as_str(),
|
|
|
|
NSUInteger::encode().as_str()
|
|
|
|
);
|
|
|
|
unsafe { objc::Encoding::from_str(&encoding) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn ns_string(string: &str) -> id {
|
|
|
|
NSString::alloc(nil).init_str(string).autorelease()
|
|
|
|
}
|