@@ -8,44 +8,44 @@ import (
88 "github.com/progrium/macdriver/objc"
99)
1010
11- type TestView struct {
12- objc. Object
11+ type CustomView struct {
12+ appkit. View `objc:"NSView"`
1313}
1414
15- func (v TestView ) acceptsFirstResponder () bool {
15+ func (v CustomView ) AcceptsFirstResponder () bool {
1616 return true
1717}
1818
19- func (v TestView ) keyDown (event appkit.Event ) {
19+ func (v CustomView ) KeyDown (event appkit.Event ) {
2020 log .Println ("Keydown:" , v .Class ().Name (), event .Class ().Name ())
2121}
2222
23- func (v TestView ) dividerThickness () float64 {
23+ type CustomSplitView struct {
24+ appkit.SplitView `objc:"NSSplitView"`
25+ }
26+
27+ func (v CustomSplitView ) DividerThickness () float64 {
2428 return 10.0
2529}
2630
27- func (v TestView ) dividerColor () appkit.Color {
31+ func (v CustomSplitView ) DividerColor () appkit.Color {
2832 return appkit .Color_BlackColor ()
2933}
3034
3135func main () {
3236 log .Println ("Program started." )
3337
34- // Create a SplitView subclass using AllocateClass
35- SplitViewClass := objc .AllocateClass (objc .GetClass ("NSSplitView" ), "TestSplitView" , 0 )
36- objc .AddMethod (SplitViewClass , objc .Sel ("acceptsFirstResponder" ), (TestView ).acceptsFirstResponder )
37- objc .AddMethod (SplitViewClass , objc .Sel ("keyDown:" ), (TestView ).keyDown )
38-
39- // Implement these methods for the dividerThickness and dividerColor properties on the subclass
40- objc .AddMethod (SplitViewClass , objc .Sel ("dividerThickness" ), (TestView ).dividerThickness )
41- objc .AddMethod (SplitViewClass , objc .Sel ("dividerColor" ), (TestView ).dividerColor )
42-
43- objc .RegisterClass (SplitViewClass )
38+ CustomViewClass := objc .NewClass [CustomView ](
39+ objc .Sel ("acceptsFirstResponder" ),
40+ objc .Sel ("keyDown:" ),
41+ )
42+ objc .RegisterClass (CustomViewClass )
4443
45- ViewClass := objc .AllocateClass (objc .GetClass ("NSView" ), "TestView" , 0 )
46- objc .AddMethod (ViewClass , objc .Sel ("acceptsFirstResponder" ), (TestView ).acceptsFirstResponder )
47- objc .AddMethod (ViewClass , objc .Sel ("keyDown:" ), (TestView ).keyDown )
48- objc .RegisterClass (ViewClass )
44+ CustomSplitViewClass := objc .NewClass [CustomSplitView ](
45+ objc .Sel ("dividerThickness" ),
46+ objc .Sel ("dividerColor" ),
47+ )
48+ objc .RegisterClass (CustomSplitViewClass )
4949
5050 app := appkit .Application_SharedApplication ()
5151
@@ -64,11 +64,11 @@ func main() {
6464 win .SetTitle ("Hello world" )
6565 win .SetLevel (appkit .MainMenuWindowLevel + 2 )
6666
67- view := appkit . SplitViewFrom ( SplitViewClass . CreateInstance ( 0 ). Ptr () ).InitWithFrame (frame )
67+ view := CustomSplitViewClass . New ( ).InitWithFrame (frame )
6868 view .SetVertical (true )
6969
70- neatView := appkit . ViewFrom ( ViewClass . CreateInstance ( 0 ). Ptr () ).InitWithFrame (rectOf (0 , 0 , 150 , 99 ))
71- coolView := appkit . ViewFrom ( ViewClass . CreateInstance ( 0 ). Ptr () ).InitWithFrame (rectOf (10 , 0 , 150 , 99 ))
70+ neatView := CustomViewClass . New ( ).InitWithFrame (rectOf (0 , 0 , 150 , 99 ))
71+ coolView := CustomViewClass . New ( ).InitWithFrame (rectOf (10 , 0 , 150 , 99 ))
7272 neatView .AddSubview (appkit .NewLabel ("NEAT" ))
7373 coolView .AddSubview (appkit .NewLabel ("COOL" ))
7474
0 commit comments