2014-08-02 21:35:58 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type checkbox struct {
|
2014-10-18 16:03:07 -05:00
|
|
|
*controlSingleObject
|
2014-10-02 09:05:53 -05:00
|
|
|
toggled *event
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newCheckbox(text string) *checkbox {
|
2014-08-03 19:08:25 -05:00
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
|
|
|
c := &checkbox{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleObject: newControlSingleObject(C.newCheckbox()),
|
2014-10-02 09:05:53 -05:00
|
|
|
toggled: newEvent(),
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
C.buttonSetText(c.id, ctext)
|
|
|
|
C.checkboxSetDelegate(c.id, unsafe.Pointer(c))
|
2014-08-03 19:08:25 -05:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *checkbox) OnToggled(e func()) {
|
|
|
|
c.toggled.set(e)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
func (c *checkbox) Text() string {
|
2014-10-18 16:03:07 -05:00
|
|
|
return C.GoString(C.buttonText(c.id))
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *checkbox) SetText(text string) {
|
|
|
|
ctext := C.CString(text)
|
|
|
|
defer C.free(unsafe.Pointer(ctext))
|
2014-10-18 16:03:07 -05:00
|
|
|
C.buttonSetText(c.id, ctext)
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
2014-08-02 21:35:58 -05:00
|
|
|
|
|
|
|
func (c *checkbox) Checked() bool {
|
2014-10-18 16:03:07 -05:00
|
|
|
return fromBOOL(C.checkboxChecked(c.id))
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *checkbox) SetChecked(checked bool) {
|
2014-10-18 16:03:07 -05:00
|
|
|
C.checkboxSetChecked(c.id, toBOOL(checked))
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export checkboxToggled
|
|
|
|
func checkboxToggled(xc unsafe.Pointer) {
|
|
|
|
c := (*checkbox)(unsafe.Pointer(xc))
|
|
|
|
c.toggled.fire()
|
|
|
|
}
|