2019-05-06 13:21:36 -04:00
|
|
|
package main
|
2019-05-07 14:48:06 -04:00
|
|
|
//go:generate nswrap
|
2019-05-06 13:21:36 -04:00
|
|
|
|
|
|
|
import (
|
2019-05-07 14:48:06 -04:00
|
|
|
"runtime"
|
2019-05-06 13:21:36 -04:00
|
|
|
"gitlab.wow.st/gmp/nswrap/examples/app/ns"
|
|
|
|
)
|
|
|
|
|
2019-05-09 13:33:28 -04:00
|
|
|
func app() {
|
2019-05-07 14:48:06 -04:00
|
|
|
//Lock OS thread because Cocoa uses thread-local storage
|
|
|
|
runtime.LockOSThread()
|
2019-05-06 13:21:36 -04:00
|
|
|
a := ns.NSApplicationSharedApplication()
|
|
|
|
a.SetActivationPolicy(ns.NSApplicationActivationPolicyRegular)
|
|
|
|
w := ns.NSWindowAlloc().InitWithContentRect(
|
|
|
|
ns.NSMakeRect(200,200,600,600),
|
|
|
|
ns.NSWindowStyleMaskTitled,
|
|
|
|
ns.NSBackingStoreBuffered,
|
|
|
|
0,
|
|
|
|
nil,
|
|
|
|
)
|
2019-05-09 08:52:35 -04:00
|
|
|
nst := ns.NSStringWithGoString
|
|
|
|
w.SetTitle(nst("Hi World"))
|
2019-05-06 13:21:36 -04:00
|
|
|
w.MakeKeyAndOrderFront(w)
|
2019-05-07 14:48:06 -04:00
|
|
|
w.SetAlphaValue(0.85)
|
2019-05-09 08:52:35 -04:00
|
|
|
m1 := ns.NSMenuAlloc().InitWithTitle(nst("Main"))
|
2019-05-07 14:48:06 -04:00
|
|
|
appItem := ns.NSMenuItemAlloc()
|
|
|
|
fileItem := ns.NSMenuItemAlloc()
|
|
|
|
m1.AddItem(appItem)
|
|
|
|
m1.AddItem(fileItem)
|
|
|
|
|
2019-05-09 08:52:35 -04:00
|
|
|
appMenu := ns.NSMenuAlloc().InitWithTitle(nst("App"))
|
|
|
|
fileMenu := ns.NSMenuAlloc().InitWithTitle(nst("File"))
|
2019-05-07 14:48:06 -04:00
|
|
|
m1.SetSubmenu(appMenu, appItem)
|
|
|
|
m1.SetSubmenu(fileMenu, fileItem)
|
|
|
|
|
|
|
|
s := ns.NSStringWithGoString("")
|
2019-05-09 08:52:35 -04:00
|
|
|
appMenu.AddItemWithTitle(nst("About"), nil, s)
|
|
|
|
appMenu.AddItemWithTitle(nst("Preferences"), nil, s)
|
|
|
|
appMenu.AddItemWithTitle(nst("Quit"),ns.Selector("terminate:"), nst("q"))
|
2019-05-07 14:48:06 -04:00
|
|
|
a.SetMainMenu(m1)
|
2019-05-09 08:52:35 -04:00
|
|
|
fileMenu.AddItemWithTitle(nst("Open"), nil, s)
|
|
|
|
fileMenu.AddItemWithTitle(nst("New"), nil, s)
|
2019-05-07 14:48:06 -04:00
|
|
|
|
|
|
|
a.SetMainMenu(m1)
|
2019-05-07 15:49:43 -04:00
|
|
|
|
2019-05-09 08:52:35 -04:00
|
|
|
b1 := ns.NSButtonWithTitle(nst("push"),s,nil)
|
|
|
|
b1.SetFrame(ns.NSMakeRect(0,550,100,50))
|
2019-05-07 15:49:43 -04:00
|
|
|
w.ContentView().AddSubview(&b1.NSView,ns.NSWindowAbove,nil)
|
2019-05-06 13:21:36 -04:00
|
|
|
a.Run()
|
|
|
|
}
|
|
|
|
|
2019-05-07 14:48:06 -04:00
|
|
|
func main() {
|
2019-05-09 13:33:28 -04:00
|
|
|
go ns.Autorelease(app)
|
2019-05-07 14:48:06 -04:00
|
|
|
select { }
|
|
|
|
}
|
|
|
|
|