-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathmain.go
96 lines (74 loc) · 2.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"log"
"github.com/progrium/darwinkit/macos/appkit"
"github.com/progrium/darwinkit/macos/foundation"
"github.com/progrium/darwinkit/objc"
)
type CustomView struct {
appkit.View `objc:"NSView"`
}
func (v CustomView) AcceptsFirstResponder() bool {
return true
}
func (v CustomView) KeyDown(event appkit.Event) {
log.Println("Keydown:", v.Class().Name(), event.Class().Name())
}
type CustomSplitView struct {
appkit.SplitView `objc:"NSSplitView"`
}
func (v CustomSplitView) DividerThickness() float64 {
return 10.0
}
func (v CustomSplitView) DividerColor() appkit.Color {
return appkit.Color_BlackColor()
}
func main() {
log.Println("Program started.")
CustomViewClass := objc.NewClass[CustomView](
objc.Sel("acceptsFirstResponder"),
objc.Sel("keyDown:"),
)
objc.RegisterClass(CustomViewClass)
CustomSplitViewClass := objc.NewClass[CustomSplitView](
objc.Sel("dividerThickness"),
objc.Sel("dividerColor"),
)
objc.RegisterClass(CustomSplitViewClass)
app := appkit.Application_SharedApplication()
ad := &appkit.ApplicationDelegate{}
ad.SetApplicationDidFinishLaunching(func(foundation.Notification) {
frame := rectOf(400, 400, 300, 200)
win := appkit.NewWindowWithContentRectStyleMaskBackingDefer(
frame,
appkit.WindowStyleMaskTitled|appkit.WindowStyleMaskClosable,
appkit.BackingStoreBuffered,
false,
)
objc.Retain(&win)
win.SetTitle("Hello world")
win.SetLevel(appkit.MainMenuWindowLevel + 2)
view := CustomSplitViewClass.New().InitWithFrame(frame)
view.SetVertical(true)
neatView := CustomViewClass.New().InitWithFrame(rectOf(0, 0, 150, 99))
coolView := CustomViewClass.New().InitWithFrame(rectOf(10, 0, 150, 99))
neatView.AddSubview(appkit.NewLabel("NEAT"))
coolView.AddSubview(appkit.NewLabel("COOL"))
// Add subviews
view.AddArrangedSubview(neatView)
view.AddArrangedSubview(coolView)
win.SetContentView(view)
win.MakeKeyAndOrderFront(nil)
log.Println("App started.")
})
ad.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool {
return true
})
app.SetDelegate(ad)
app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
app.ActivateIgnoringOtherApps(true)
app.Run()
}
func rectOf(x, y, width, height float64) foundation.Rect {
return foundation.Rect{Origin: foundation.Point{X: x, Y: y}, Size: foundation.Size{Width: width, Height: height}}
}