-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_darwin.v
57 lines (49 loc) · 1.31 KB
/
ui_darwin.v
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
// Copyright (c) 2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license
// that can be found in the LICENSE file.
module ui
pub fn message_box(s string) {
unsafe {
ns_string := nsstring(s)
# NSAlert *alert = [[NSAlert alloc] init] ;
# [alert setMessageText:ns_string];
# [alert runModal];
}
}
fn nsstring(s string) voidptr {
unsafe {
# return [ [ NSString alloc ] initWithBytesNoCopy:s.str length:s.len
# encoding:NSUTF8StringEncoding freeWhenDone: false];
}
return 0
}
pub fn notify(title, msg string) {
unsafe {
ns_msg := nsstring(msg)
ns_title := nsstring(title)
# NSUserNotification *notification = [[[NSUserNotification alloc] init] retain];
# notification.title = ns_title;
# notification.informativeText = ns_msg;
# NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
# [center deliverNotification:notification];
}
}
/*
pub fn text_width(s string) int {
return 0
}
*/
pub fn bundle_path() string {
s := ''
# s = tos2( [[[NSBundle mainBundle] bundlePath] UTF8String]);
return s
}
pub fn wait_events() {
unsafe {
# NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny
# untilDate:[NSDate distantFuture]
# inMode:NSDefaultRunLoopMode
# dequeue:YES];
# [NSApp sendEvent:event];
}
}