-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod.rs
More file actions
97 lines (76 loc) · 1.98 KB
/
mod.rs
File metadata and controls
97 lines (76 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
mod canvas;
pub use canvas::*;
mod window;
pub use window::*;
mod monitor;
pub use monitor::*;
mod msgbox;
pub use msgbox::*;
mod filebox;
pub use filebox::*;
mod button;
pub use button::*;
mod edit;
pub use edit::*;
mod text_box;
pub use text_box::*;
mod label;
pub use label::*;
mod progress;
pub use progress::*;
mod combo_box;
pub use combo_box::*;
/// [`NSWindow`].
pub type RawWindow = Retained<NSWindow>;
use objc2::rc::{Retained, autoreleasepool};
use objc2_app_kit::NSWindow;
use objc2_foundation::{NSPoint, NSRect, NSSize, NSString, NSUserDefaults, ns_string};
use crate::{ColorTheme, Point, Rect, Size};
pub fn color_theme() -> ColorTheme {
unsafe {
let osx_mode =
NSUserDefaults::standardUserDefaults().stringForKey(ns_string!("AppleInterfaceStyle"));
let is_dark = osx_mode
.map(|mode| mode.isEqualToString(ns_string!("Dark")))
.unwrap_or_default();
if is_dark {
ColorTheme::Dark
} else {
ColorTheme::Light
}
}
}
#[inline]
pub(crate) fn from_cgsize(size: NSSize) -> Size {
Size::new(size.width, size.height)
}
#[inline]
pub(crate) fn to_cgsize(size: Size) -> NSSize {
NSSize::new(size.width, size.height)
}
#[inline]
pub(crate) fn transform_rect(s: Size, rect: Rect) -> NSRect {
NSRect::new(
NSPoint::new(rect.origin.x, s.height - rect.size.height - rect.origin.y),
to_cgsize(rect.size),
)
}
#[inline]
pub(crate) fn transform_cgrect(s: Size, rect: NSRect) -> Rect {
Rect::new(
Point::new(rect.origin.x, s.height - rect.size.height - rect.origin.y),
from_cgsize(rect.size),
)
}
#[inline]
pub(crate) fn transform_point(s: Size, p: Point) -> NSPoint {
NSPoint::new(p.x, s.height - p.y)
}
#[inline]
pub(crate) fn transform_cgpoint(s: Size, p: NSPoint) -> Point {
Point::new(p.x, s.height - p.y)
}
#[inline]
pub(crate) fn from_nsstring(s: &NSString) -> String {
autoreleasepool(|pool| unsafe { s.to_str(pool) }.to_string())
}