From b9e46978934e0b73be331b5ab78e5c46ad92e7f5 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 28 Sep 2018 10:01:08 +0300 Subject: [PATCH] Fix macOS sample for Mojave with dark theme. --- samples/objc/src/main/kotlin/Window.kt | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/samples/objc/src/main/kotlin/Window.kt b/samples/objc/src/main/kotlin/Window.kt index 29293bc998a..98b7c5379b3 100644 --- a/samples/objc/src/main/kotlin/Window.kt +++ b/samples/objc/src/main/kotlin/Window.kt @@ -2,8 +2,6 @@ import kotlin.native.concurrent.* import kotlinx.cinterop.* import platform.AppKit.* import platform.Foundation.* -import platform.objc.* -import platform.osx.* import platform.darwin.* import platform.posix.* @@ -34,12 +32,17 @@ private class Controller : NSObject() { dispatch_async_f(asyncQueue, DetachedObjectGraph { Data(clock_gettime_nsec_np(CLOCK_REALTIME)) }.asCPointer(), staticCFunction { - it -> + it -> initRuntimeIfNeeded() val data = DetachedObjectGraph(it).attach() println("in async: $data") }) } + + @ObjCAction + fun onQuit() { + NSApplication.sharedApplication().stop(this) + } } private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol { @@ -51,10 +54,10 @@ private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol { val mainDisplayRect = NSScreen.mainScreen()!!.frame val windowRect = mainDisplayRect.useContents { NSMakeRect( - origin.x + size.width * 0.25, - origin.y + size.height * 0.25, - size.width * 0.5, - size.height * 0.5 + origin.x + size.width * 0.25, + origin.y + size.height * 0.25, + size.width * 0.5, + size.height * 0.5 ) } @@ -68,7 +71,7 @@ private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol { hasShadow = true preferredBackingLocation = NSWindowBackingLocationVideoMemory hidesOnDeactivate = false - backgroundColor = NSColor.whiteColor() + backgroundColor = NSColor.grayColor() releasedWhenClosed = false delegate = object : NSObject(), NSWindowDelegateProtocol { @@ -79,15 +82,23 @@ private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol { } } - val button = NSButton(NSMakeRect(10.0, 10.0, 100.0, 40.0)).apply { + val buttonPress = NSButton(NSMakeRect(10.0, 10.0, 100.0, 40.0)).apply { title = "Press me" target = controller action = NSSelectorFromString("onClick") } - window.contentView!!.addSubview(button) + window.contentView!!.addSubview(buttonPress) + val buttonQuit = NSButton(NSMakeRect(120.0, 10.0, 100.0, 40.0)).apply { + title = "Quit" + target = controller + action = NSSelectorFromString("onQuit") + } + window.contentView!!.addSubview(buttonQuit) + } override fun applicationWillFinishLaunching(notification: NSNotification) { window.makeKeyAndOrderFront(this) } } +