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-07 14:48:06 -04:00
|
|
|
func nsmgr() {
|
|
|
|
//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,
|
|
|
|
)
|
|
|
|
w.SetTitle(ns.NSStringWithGoString("Hi World"))
|
|
|
|
w.MakeKeyAndOrderFront(w)
|
2019-05-07 14:48:06 -04:00
|
|
|
w.SetAlphaValue(0.85)
|
|
|
|
m1 := ns.NSMenuAlloc().InitWithTitle(ns.NSStringWithGoString("Main"))
|
|
|
|
appItem := ns.NSMenuItemAlloc()
|
|
|
|
fileItem := ns.NSMenuItemAlloc()
|
|
|
|
m1.AddItem(appItem)
|
|
|
|
m1.AddItem(fileItem)
|
|
|
|
|
|
|
|
appMenu := ns.NSMenuAlloc().InitWithTitle(ns.NSStringWithGoString("App"))
|
|
|
|
fileMenu := ns.NSMenuAlloc().InitWithTitle(ns.NSStringWithGoString("File"))
|
|
|
|
m1.SetSubmenu(appMenu, appItem)
|
|
|
|
m1.SetSubmenu(fileMenu, fileItem)
|
|
|
|
|
|
|
|
s := ns.NSStringWithGoString("")
|
|
|
|
appMenu.AddItemWithTitle(ns.NSStringWithGoString("About"), nil, s)
|
|
|
|
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Preferences"), nil, s)
|
2019-05-07 15:17:23 -04:00
|
|
|
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Quit"),ns.Selector("terminate:"), ns.NSStringWithGoString("q"))
|
2019-05-07 14:48:06 -04:00
|
|
|
a.SetMainMenu(m1)
|
|
|
|
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("Open"), nil, s)
|
|
|
|
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("New"), nil, s)
|
|
|
|
|
|
|
|
a.SetMainMenu(m1)
|
2019-05-07 15:49:43 -04:00
|
|
|
|
|
|
|
b1 := ns.NSButtonWithTitle(ns.NSStringWithGoString("push"),s,nil)
|
|
|
|
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() {
|
|
|
|
go nsmgr()
|
|
|
|
select { }
|
|
|
|
}
|
|
|
|
|