-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathmain.go
77 lines (64 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
package main
import (
"fmt"
"github.com/progrium/darwinkit/helper/action"
"github.com/progrium/darwinkit/helper/layout"
"github.com/progrium/darwinkit/helper/widgets"
"github.com/progrium/darwinkit/macos"
"github.com/progrium/darwinkit/macos/appkit"
"github.com/progrium/darwinkit/macos/foundation"
"github.com/progrium/darwinkit/objc"
)
func main() {
macos.RunApp(launched)
}
func launched(app appkit.Application, delegate *appkit.ApplicationDelegate) {
app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
app.ActivateIgnoringOtherApps(true)
w := appkit.NewWindowWithSize(600, 400)
objc.Retain(&w)
w.SetTitle("Test Layout")
label := appkit.NewLabel("label")
mdButton := appkit.NewButtonWithTitle("modal dialog")
dButton := appkit.NewButtonWithTitle("dialog")
textView := appkit.TextViewClass.ScrollableTextView()
action.Set(mdButton, func(sender objc.Object) {
d := widgets.NewDialog(400, 300)
d.SetView(appkit.NewLabel("test modal dialog"))
// if d.RunModal() == appkit.ModalResponseOK {
// fmt.Println("ok!")
// }
})
action.Set(dButton, func(sender objc.Object) {
d := widgets.NewDialog(400, 300)
d.SetView(appkit.NewLabel("test dialog"))
d.Center()
d.Show(func() {
fmt.Println("ok!")
})
})
gridView := appkit.NewGridView()
for i := 0; i < 3; i++ {
var views []appkit.IView
for j := 0; j < 4; j++ {
label := appkit.NewLabel(fmt.Sprintf("label-%v-%v", i, j))
views = append(views, label)
}
gridView.AddRowWithViews(views)
}
gridView.SetContentHuggingPriorityForOrientation(appkit.LayoutPriorityDefaultHigh, appkit.LayoutConstraintOrientationHorizontal)
gridView.ColumnAtIndex(0).SetXPlacement(appkit.GridCellPlacementTrailing)
gridView.SetRowAlignment(appkit.GridRowAlignmentLastBaseline)
stackView := appkit.StackView_StackViewWithViews([]appkit.IView{label, mdButton, dButton, textView, gridView})
stackView.SetOrientation(appkit.UserInterfaceLayoutOrientationVertical)
stackView.SetDistribution(appkit.StackViewDistributionFillEqually)
stackView.SetAlignment(appkit.LayoutAttributeCenterX)
stackView.SetSpacing(10)
w.ContentView().AddSubview(stackView)
layout.PinEdgesToSuperView(stackView, foundation.EdgeInsets{Top: 10, Bottom: 10, Left: 20, Right: 20})
w.MakeKeyAndOrderFront(nil)
w.Center()
delegate.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool {
return true
})
}