First draft that handles subclasses and improvements to delegate
implementation.
This commit is contained in:
+22
-22
@@ -7,15 +7,12 @@ import (
|
||||
"gitlab.wow.st/gmp/nswrap/examples/app/ns"
|
||||
)
|
||||
|
||||
var nst = ns.NSStringWithGoString
|
||||
|
||||
func didFinishLaunching(n *ns.NSNotification) {
|
||||
fmt.Println("Go: did finish launching")
|
||||
}
|
||||
|
||||
func shouldTerminate(s *ns.NSApplication) ns.NSApplicationTerminateReply {
|
||||
fmt.Println("Go: should terminate")
|
||||
return ns.NSTerminateNow
|
||||
}
|
||||
|
||||
func shouldTerminateAfterLastWindowClosed(s *ns.NSApplication) ns.BOOL {
|
||||
return 1
|
||||
}
|
||||
@@ -26,8 +23,18 @@ func willTerminate(n *ns.NSNotification) {
|
||||
|
||||
func didBecomeActive(n *ns.NSNotification) {
|
||||
fmt.Println("Go: did become active")
|
||||
vc := win.ContentViewController()
|
||||
if vc == nil {
|
||||
fmt.Println("vc == nil")
|
||||
} else {
|
||||
fmt.Println("vc is not nil")
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
win *ns.NSWindow
|
||||
)
|
||||
|
||||
func app() {
|
||||
//Lock OS thread because Cocoa uses thread-local storage
|
||||
runtime.LockOSThread()
|
||||
@@ -37,24 +44,23 @@ func app() {
|
||||
//Set up an AppDelegate
|
||||
del := ns.AppDelegateAlloc()
|
||||
del.ApplicationDidFinishLaunchingCallback(didFinishLaunching)
|
||||
del.ApplicationShouldTerminateCallback(shouldTerminate)
|
||||
del.ApplicationShouldTerminateAfterLastWindowClosedCallback(shouldTerminateAfterLastWindowClosed)
|
||||
del.ApplicationWillTerminateCallback(willTerminate)
|
||||
del.ApplicationDidBecomeActiveCallback(didBecomeActive)
|
||||
a.SetDelegate(del)
|
||||
|
||||
//Set up an NSWindow
|
||||
w := ns.NSWindowAlloc().InitWithContentRect(
|
||||
win = ns.NSWindowAlloc().InitWithContentRect(
|
||||
ns.NSMakeRect(200,200,600,600),
|
||||
ns.NSWindowStyleMaskTitled | ns.NSWindowStyleMaskClosable,
|
||||
ns.NSWindowStyleMaskTitled | ns.NSWindowStyleMaskClosable |
|
||||
ns.NSWindowStyleMaskResizable,
|
||||
ns.NSBackingStoreBuffered,
|
||||
0,
|
||||
nil,
|
||||
)
|
||||
nst := ns.NSStringWithGoString
|
||||
w.SetTitle(nst("Hi World"))
|
||||
w.MakeKeyAndOrderFront(w)
|
||||
w.SetAlphaValue(0.85)
|
||||
win.SetTitle(nst("Hi World"))
|
||||
win.MakeKeyAndOrderFront(win)
|
||||
win.SetAlphaValue(0.85)
|
||||
|
||||
//Build a basic menu
|
||||
m1 := ns.NSMenuAlloc().InitWithTitle(nst("Main"))
|
||||
@@ -68,21 +74,15 @@ func app() {
|
||||
m1.SetSubmenu(appMenu, appItem)
|
||||
m1.SetSubmenu(fileMenu, fileItem)
|
||||
|
||||
s := ns.NSStringWithGoString("")
|
||||
appMenu.AddItemWithTitle(nst("About"), nil, s)
|
||||
appMenu.AddItemWithTitle(nst("Preferences"), nil, s)
|
||||
appMenu.AddItemWithTitle(nst("About"), nil, nst(""))
|
||||
appMenu.AddItemWithTitle(nst("Preferences"), nil, nst(""))
|
||||
appMenu.AddItemWithTitle(nst("Quit"),ns.Selector("terminate:"), nst("q"))
|
||||
a.SetMainMenu(m1)
|
||||
fileMenu.AddItemWithTitle(nst("Open"), nil, s)
|
||||
fileMenu.AddItemWithTitle(nst("New"), nil, s)
|
||||
fileMenu.AddItemWithTitle(nst("Open"), nil, nst(""))
|
||||
fileMenu.AddItemWithTitle(nst("New"), nil, nst(""))
|
||||
|
||||
a.SetMainMenu(m1)
|
||||
|
||||
//Add a random button that does nothing
|
||||
b1 := ns.NSButtonWithTitle(nst("push"),s,nil)
|
||||
b1.Id.NSView().SetFrame(ns.NSMakeRect(0,550,100,50))
|
||||
w.ContentView().AddSubview(&b1.NSView,ns.NSWindowAbove,nil)
|
||||
|
||||
//Run the app
|
||||
a.Run()
|
||||
}
|
||||
|
||||
+20
-20
@@ -4,31 +4,20 @@ inputfiles:
|
||||
|
||||
classes:
|
||||
- NSAutoreleasePool
|
||||
- NSArray
|
||||
- NSMutableArray
|
||||
- NSDictionary
|
||||
- NSEnumerator
|
||||
- NSSet
|
||||
- NSDate
|
||||
- NSTimeZone
|
||||
- NSCalendar
|
||||
- NSLocale
|
||||
- NSCharacterSet
|
||||
- NSString
|
||||
- NSScanner
|
||||
- NSFileManager
|
||||
- NSApplication
|
||||
- NSBundle
|
||||
- NSApp
|
||||
- NSMenu
|
||||
- NSMenuItem
|
||||
- NSWindow
|
||||
- NSView
|
||||
- NSScreen
|
||||
- NSMenu
|
||||
- NSMenuItem
|
||||
- NSButton
|
||||
- NSEvent
|
||||
- NSResponder
|
||||
- NSRunLoop
|
||||
- NSNotification
|
||||
- NSStackView
|
||||
- NSLayoutConstraint
|
||||
- NSDictionary
|
||||
- NSArray
|
||||
- NSColor
|
||||
|
||||
functions: [NSMake.*]
|
||||
|
||||
@@ -41,7 +30,18 @@ enums:
|
||||
- NSWindowOrderingMode
|
||||
|
||||
delegates:
|
||||
AppDelegate: [NSApplicationDelegate]
|
||||
AppDelegate:
|
||||
NSApplicationDelegate:
|
||||
- applicationWillTerminate
|
||||
- applicationDidFinishLaunching
|
||||
- applicationShouldTerminateAfterLastWindowClosed
|
||||
- applicationDidBecomeActive
|
||||
subclasses:
|
||||
ViewController:
|
||||
NSViewController:
|
||||
- viewDidLoad
|
||||
- viewDidDisappear
|
||||
- loadView
|
||||
|
||||
frameworks: [ Foundation, AppKit, CoreGraphics ]
|
||||
pragma: [ clang diagnostic ignored "-Wformat-security" ]
|
||||
|
||||
Reference in New Issue
Block a user