Created
October 19, 2022 20:03
-
-
Save kotleni/3c61bcc7a797f539d3bd02cbf4b919ce to your computer and use it in GitHub Desktop.
Kotlin AppKit usage example (MacOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform.AppKit.* | |
import platform.Foundation.NSMakeRect | |
import platform.Foundation.NSNotification | |
import platform.Foundation.NSRect | |
import platform.darwin.NSObject | |
fun main() { | |
val app = NSApplication.sharedApplication() | |
app.delegate = MyAppDelegate() | |
app.setActivationPolicy(NSApplicationActivationPolicy.NSApplicationActivationPolicyRegular) | |
app.activateIgnoringOtherApps(true) | |
app.run() | |
} | |
class MyAppDelegate(): NSObject(), NSApplicationDelegateProtocol { | |
private val window: NSWindow | |
init { | |
val rect = NSMakeRect(0.0, 0.0, 600.0, 400.0) | |
window = NSWindow( | |
contentRect = rect, | |
styleMask = NSWindowStyleMaskClosable, | |
backing = NSBackingStoreBuffered, | |
defer = false | |
) | |
window.title = "Window" | |
window.movableByWindowBackground = true | |
} | |
override fun applicationWillFinishLaunching(notification: NSNotification) { | |
window.makeKeyAndOrderFront(null) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment