andlabs-ui/button_darwin.go

48 lines
837 B
Go
Raw Normal View History

// 16 july 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type button struct {
2014-10-18 16:03:07 -05:00
*controlSingleObject
clicked *event
}
func newButton(text string) *button {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
b := &button{
2014-10-18 16:03:07 -05:00
controlSingleObject: newControlSingleObject(C.newButton()),
clicked: newEvent(),
}
2014-10-18 16:03:07 -05:00
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 {
2014-10-18 16:03:07 -05:00
return C.GoString(C.buttonText(b.id))
}
func (b *button) SetText(text string) {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
2014-10-18 16:03:07 -05:00
C.buttonSetText(b.id, ctext)
}
//export buttonClicked
func buttonClicked(xb unsafe.Pointer) {
b := (*button)(unsafe.Pointer(xb))
b.clicked.fire()
}