forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton_darwin.go
47 lines (38 loc) · 837 Bytes
/
button_darwin.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
// 16 july 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type button struct {
*controlSingleObject
clicked *event
}
func newButton(text string) *button {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
b := &button{
controlSingleObject: newControlSingleObject(C.newButton()),
clicked: newEvent(),
}
C.buttonSetText(b.id, ctext)
C.buttonSetDelegate(b.id, unsafe.Pointer(b))
return b
}
func (b *button) OnClicked(e func()) {
b.clicked.set(e)
}
func (b *button) Text() string {
return C.GoString(C.buttonText(b.id))
}
func (b *button) SetText(text string) {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
C.buttonSetText(b.id, ctext)
}
//export buttonClicked
func buttonClicked(xb unsafe.Pointer) {
b := (*button)(unsafe.Pointer(xb))
b.clicked.fire()
}