Fix macOS sample for Mojave with dark theme.

This commit is contained in:
Nikolay Igotti
2018-09-28 10:01:08 +03:00
parent 127cd3d2d5
commit b9e4697893
+21 -10
View File
@@ -2,8 +2,6 @@ import kotlin.native.concurrent.*
import kotlinx.cinterop.* import kotlinx.cinterop.*
import platform.AppKit.* import platform.AppKit.*
import platform.Foundation.* import platform.Foundation.*
import platform.objc.*
import platform.osx.*
import platform.darwin.* import platform.darwin.*
import platform.posix.* import platform.posix.*
@@ -34,12 +32,17 @@ private class Controller : NSObject() {
dispatch_async_f(asyncQueue, DetachedObjectGraph { dispatch_async_f(asyncQueue, DetachedObjectGraph {
Data(clock_gettime_nsec_np(CLOCK_REALTIME)) Data(clock_gettime_nsec_np(CLOCK_REALTIME))
}.asCPointer(), staticCFunction { }.asCPointer(), staticCFunction {
it -> it ->
initRuntimeIfNeeded() initRuntimeIfNeeded()
val data = DetachedObjectGraph<Data>(it).attach() val data = DetachedObjectGraph<Data>(it).attach()
println("in async: $data") println("in async: $data")
}) })
} }
@ObjCAction
fun onQuit() {
NSApplication.sharedApplication().stop(this)
}
} }
private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol { private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol {
@@ -51,10 +54,10 @@ private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol {
val mainDisplayRect = NSScreen.mainScreen()!!.frame val mainDisplayRect = NSScreen.mainScreen()!!.frame
val windowRect = mainDisplayRect.useContents { val windowRect = mainDisplayRect.useContents {
NSMakeRect( NSMakeRect(
origin.x + size.width * 0.25, origin.x + size.width * 0.25,
origin.y + size.height * 0.25, origin.y + size.height * 0.25,
size.width * 0.5, size.width * 0.5,
size.height * 0.5 size.height * 0.5
) )
} }
@@ -68,7 +71,7 @@ private class MyAppDelegate() : NSObject(), NSApplicationDelegateProtocol {
hasShadow = true hasShadow = true
preferredBackingLocation = NSWindowBackingLocationVideoMemory preferredBackingLocation = NSWindowBackingLocationVideoMemory
hidesOnDeactivate = false hidesOnDeactivate = false
backgroundColor = NSColor.whiteColor() backgroundColor = NSColor.grayColor()
releasedWhenClosed = false releasedWhenClosed = false
delegate = object : NSObject(), NSWindowDelegateProtocol { 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" title = "Press me"
target = controller target = controller
action = NSSelectorFromString("onClick") 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) { override fun applicationWillFinishLaunching(notification: NSNotification) {
window.makeKeyAndOrderFront(this) window.makeKeyAndOrderFront(this)
} }
} }