Change Go types to plain structs instead of pointers to structs.
Add methods for protocols that Objective-C interfaces claim to implement. Separate class methods from instance methods in internal data structures. Add layout constraints with visual formats to examples/app. Fix typedefs for wrapped objective-c object types.
This commit is contained in:
+69
-41
@@ -7,57 +7,24 @@ import (
|
||||
"gitlab.wow.st/gmp/nswrap/examples/app/ns"
|
||||
)
|
||||
|
||||
//Shortcut for literal NSStrings
|
||||
var nst = ns.NSStringWithGoString
|
||||
|
||||
func didFinishLaunching(n *ns.NSNotification) {
|
||||
func didFinishLaunching(n ns.NSNotification) {
|
||||
fmt.Println("Go: did finish launching")
|
||||
}
|
||||
|
||||
func shouldTerminateAfterLastWindowClosed(s *ns.NSApplication) ns.BOOL {
|
||||
return 1
|
||||
}
|
||||
|
||||
func willTerminate(n *ns.NSNotification) {
|
||||
fmt.Println("Go: will terminate")
|
||||
}
|
||||
|
||||
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()
|
||||
a := ns.NSApplicationSharedApplication()
|
||||
a.SetActivationPolicy(ns.NSApplicationActivationPolicyRegular)
|
||||
|
||||
//Set up an AppDelegate
|
||||
del := ns.AppDelegateAlloc()
|
||||
del.ApplicationDidFinishLaunchingCallback(didFinishLaunching)
|
||||
del.ApplicationShouldTerminateAfterLastWindowClosedCallback(shouldTerminateAfterLastWindowClosed)
|
||||
del.ApplicationWillTerminateCallback(willTerminate)
|
||||
del.ApplicationDidBecomeActiveCallback(didBecomeActive)
|
||||
a.SetDelegate(del)
|
||||
|
||||
fmt.Printf("Notification: %s\n",n.Name().UTF8String())
|
||||
//Set up an NSWindow
|
||||
win = ns.NSWindowAlloc().InitWithContentRect(
|
||||
ns.NSMakeRect(200,200,600,600),
|
||||
ns.NSWindowStyleMaskTitled | ns.NSWindowStyleMaskClosable |
|
||||
ns.NSWindowStyleMaskResizable,
|
||||
ns.NSWindowStyleMaskResizable,
|
||||
ns.NSBackingStoreBuffered,
|
||||
0,
|
||||
nil,
|
||||
ns.NSScreen{},
|
||||
)
|
||||
// retain win since we called Alloc and did not add it to a collection
|
||||
win.Retain()
|
||||
|
||||
win.SetTitle(nst("Hi World"))
|
||||
win.MakeKeyAndOrderFront(win)
|
||||
win.SetAlphaValue(0.85)
|
||||
@@ -83,6 +50,67 @@ func app() {
|
||||
|
||||
a.SetMainMenu(m1)
|
||||
|
||||
//add some buttons and do some layout
|
||||
|
||||
//don't do this:
|
||||
//b := ns.NSButtonAlloc().InitWithFrame(ns.NSMakeRect(100,100,100,50))
|
||||
|
||||
b1 := ns.NSButtonWithTitle(nst("PUSH"),ns.Id{},ns.Selector(""))
|
||||
b2 := ns.NSButtonWithTitle(nst("QUIT"),ns.Id{},ns.Selector("terminate:"))
|
||||
b1.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
||||
b2.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
||||
|
||||
cv := win.ContentView()
|
||||
|
||||
cv.AddSubview(b1.NSView,ns.NSWindowAbove,ns.NSView{})
|
||||
cv.AddSubview(b2.NSView,ns.NSWindowAbove,ns.NSView{})
|
||||
|
||||
viewmap := ns.NSDictionaryWithObjects(
|
||||
ns.NSArrayWithObjects(b1,b2),
|
||||
ns.NSArrayWithObjects(nst("b1"),nst("b2")))
|
||||
|
||||
cv.AddConstraints(ns.NSLayoutConstraintsWithVisualFormat(
|
||||
nst("V:|-[b1]"),0, ns.NSDictionary{}, viewmap))
|
||||
cv.AddConstraints(ns.NSLayoutConstraintsWithVisualFormat(
|
||||
nst("H:|-[b1]"),0, ns.NSDictionary{}, viewmap))
|
||||
cv.AddConstraints(ns.NSLayoutConstraintsWithVisualFormat(
|
||||
nst("H:[b1]-[b2]"),ns.NSLayoutFormatAlignAllBaseline,
|
||||
ns.NSDictionary{}, viewmap))
|
||||
}
|
||||
|
||||
func shouldTerminateAfterLastWindowClosed(s ns.NSApplication) ns.BOOL {
|
||||
return 1
|
||||
}
|
||||
|
||||
func willTerminate(n ns.NSNotification) {
|
||||
fmt.Println("Go: will terminate")
|
||||
}
|
||||
|
||||
func didBecomeActive(n ns.NSNotification) {
|
||||
fmt.Println("Go: did become active")
|
||||
fmt.Printf("Notification: %s\n",n.Name().UTF8String())
|
||||
}
|
||||
|
||||
var (
|
||||
a ns.NSApplication
|
||||
win ns.NSWindow
|
||||
)
|
||||
|
||||
func app() {
|
||||
//Lock OS thread because Cocoa uses thread-local storage
|
||||
runtime.LockOSThread()
|
||||
a = ns.NSApplicationSharedApplication()
|
||||
a.SetActivationPolicy(ns.NSApplicationActivationPolicyRegular)
|
||||
|
||||
//Set up an AppDelegate
|
||||
del := ns.AppDelegateAlloc()
|
||||
del.ApplicationDidFinishLaunchingCallback(didFinishLaunching)
|
||||
del.ApplicationShouldTerminateAfterLastWindowClosedCallback(shouldTerminateAfterLastWindowClosed)
|
||||
del.ApplicationWillTerminateCallback(willTerminate)
|
||||
del.ApplicationDidBecomeActiveCallback(didBecomeActive)
|
||||
|
||||
a.SetDelegate(del)
|
||||
|
||||
//Run the app
|
||||
a.Run()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# nswrap.yaml
|
||||
inputfiles:
|
||||
- /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
|
||||
- /System/Library/Frameworks/AppKit.framework/Headers/AppKit.h
|
||||
@@ -17,17 +18,17 @@ classes:
|
||||
- NSLayoutConstraint
|
||||
- NSDictionary
|
||||
- NSArray
|
||||
- NSColor
|
||||
- NSObject
|
||||
|
||||
functions: [NSMake.*]
|
||||
|
||||
enums:
|
||||
- CF.*
|
||||
- NSApplication.*
|
||||
- NSBackingStore.*
|
||||
- NSWindowStyleMask.*
|
||||
- NSWindowButton
|
||||
- NSWindowOrderingMode
|
||||
- NSLayout.*
|
||||
|
||||
delegates:
|
||||
AppDelegate:
|
||||
@@ -36,15 +37,7 @@ delegates:
|
||||
- applicationDidFinishLaunching
|
||||
- applicationShouldTerminateAfterLastWindowClosed
|
||||
- applicationDidBecomeActive
|
||||
subclasses:
|
||||
ViewController:
|
||||
NSViewController:
|
||||
- viewDidLoad
|
||||
- viewDidDisappear
|
||||
- loadView
|
||||
|
||||
frameworks: [ Foundation, AppKit, CoreGraphics ]
|
||||
frameworks: [ Foundation, AppKit ]
|
||||
pragma: [ clang diagnostic ignored "-Wformat-security" ]
|
||||
vaargs: 32
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user