2014-08-02 21:35:58 -05:00
|
|
|
// 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
|
2014-10-02 09:05:53 -05:00
|
|
|
clicked *event
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func newButton(text string) *button {
|
2014-08-02 21:35:58 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
b := &button{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleObject: newControlSingleObject(C.newButton()),
|
2014-10-02 09:05:53 -05:00
|
|
|
clicked: newEvent(),
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
C.buttonSetText(b.id, ctext)
|
|
|
|
C.buttonSetDelegate(b.id, unsafe.Pointer(b))
|
2014-08-02 21:35:58 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *button) OnClicked(e func()) {
|
|
|
|
b.clicked.set(e)
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func (b *button) Text() string {
|
2014-10-18 16:03:07 -05:00
|
|
|
return C.GoString(C.buttonText(b.id))
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
//export buttonClicked
|
|
|
|
func buttonClicked(xb unsafe.Pointer) {
|
|
|
|
b := (*button)(unsafe.Pointer(xb))
|
|
|
|
b.clicked.fire()
|
|
|
|
}
|